00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00038 #ifndef SIMTHETIC_INTERFACES_HEADER
00039 #define SIMTHETIC_INTERFACES_HEADER
00040
00041 #include <iostream>
00042 #include <string>
00043 #include <algorithm>
00044 #include <typeinfo>
00045
00046 #include <simthetic/exceptions.h>
00047 #include <simthetic/misc.h>
00048 #include <simthetic/signals.h>
00049
00050
00051
00052 #ifndef DLLIMPORT
00053 # ifdef __declspec
00054 # if BUILDING_SIMTHETICBASE_DLL
00055 # define DLLIMPORT __declspec (dllexport)
00056 # else
00057 # define DLLIMPORT __declspec (dllimport)
00058 # endif
00059 # else
00060 # define DLLIMPORT
00061 # endif
00062 #endif
00063
00064
00065 namespace simth
00066 {
00067
00068
00069 class Device;
00070
00071
00082 class DLLIMPORT DataInterface
00083 {
00084 Device* const device_;
00085 int ID_;
00086 protected:
00087
00091 int ID() const {return ID_;}
00095 Device* const device() const {return device_;}
00096
00097 public:
00098
00103 DataInterface(Device* const device, int ID)
00104 : device_(device), ID_(ID) {};
00105
00106 virtual ~DataInterface() {};
00107
00110 virtual void reset() = 0;
00111
00116 static const size_t undefinedLength;
00117 };
00118
00119
00123 class DLLIMPORT InputInterface : public DataInterface
00124 {
00125 public:
00126
00131 InputInterface(Device* const dev, int ID);
00132
00133 virtual ~InputInterface();
00134
00138 virtual void reset() = 0;
00139
00147 virtual void acceptNewData(size_t newElements) = 0;
00148
00160 virtual size_t sequenceLength() const = 0;
00161
00164 virtual void setSequenceLength(size_t newLen) = 0;
00165
00170 virtual bool isFilled() const = 0;
00171
00173 bool isConnected() const {return isConnected_;}
00174
00178 virtual void acceptConnection();
00179
00189 virtual void flushProcessedSequence() = 0;
00190
00198 virtual void releaseProcessedSequence() = 0;
00199
00204 virtual void processFinished() = 0;
00205
00209
00210 private:
00211
00212 bool isConnected_;
00213
00214
00215
00216 };
00217
00218
00227 template<class T>
00228 class DLLIMPORT InputInterfaceT : public InputInterface
00229 {
00230
00231 public:
00234 InputInterfaceT(Device* const dev, int ID,
00235 size_t sequenceLength = undefinedLength,
00236 const typename T::value_type&
00237 default_val = typename T::value_type() );
00238
00241 InputInterfaceT(Device* const dev, int ID,
00242 const typename T::value_type& default_val);
00243
00246 virtual ~InputInterfaceT();
00247
00266 T* externSequence(size_t size, size_t capacity);
00267
00280 T* internSequence();
00281
00285 virtual void reset();
00286
00292 virtual void acceptNewData(size_t size);
00293
00307 virtual size_t sequenceLength() const;
00308
00311 virtual void setSequenceLength(size_t newLen);
00312
00317 virtual bool isFilled() const;
00318
00329 virtual void flushProcessedSequence();
00330
00338 virtual void releaseProcessedSequence();
00339
00344 virtual void processFinished();
00345
00346 protected:
00347 void addRefCount();
00348 void subRefCount();
00349
00350 size_t storedElements() const {return storedElements_;}
00351
00352
00353 private:
00356 typedef typename T::storage_type buffer_type;
00360 typedef typename T::access_type access_type;
00361
00362
00363
00364
00365
00366
00367
00368
00371 buffer_type* seqBuffer;
00372
00373
00374
00375
00376
00377
00378
00379
00383 access_type* inputSubSeq;
00384
00388 access_type* outputSubSeq;
00389
00394 size_t storedElements_;
00395
00406 size_t sequenceLength_;
00407
00410 size_t refCount;
00411
00412 bool waitingForProcess;
00413
00414 void invariante() const;
00415
00416 };
00417
00418
00419
00420
00439 class OutputInterface : public DataInterface
00440 {
00441
00442 public:
00443 OutputInterface(Device* const dev, int ID)
00444 : DataInterface(dev,ID) {};
00445
00446 virtual ~OutputInterface() {};
00447
00448 virtual void connect(InputInterface* interfacePtr) = 0;
00449
00450 virtual void reset() = 0;
00451
00455 virtual size_t sequenceCapacity() const = 0;
00456
00459 virtual size_t sequenceLength() const = 0;
00460
00464 virtual void setSequenceCapacity(size_t size) = 0;
00467 virtual void setSequenceLength(size_t size) = 0;
00468
00471 virtual bool isConnected() const = 0;
00472
00477 virtual void flushProcessedSequences() = 0;
00478
00482 virtual void processFinished() = 0;
00483
00484 protected:
00492 static std::string wrongConnectionMsg(const std::type_info& output_if,
00493 const std::type_info& input_if);
00494
00495 };
00496
00505 template<class T>
00506 class OutputInterfaceT : public OutputInterface
00507 {
00508 private:
00509
00510 size_t sequenceCapacity_;
00511 size_t sequenceLength_;
00512
00513 typedef InputInterfaceT<T> interf_type;
00514
00515 interf_type* connectedInterface;
00516 T* currentOutputSequence;
00517
00518 std::vector<interf_type*> multipleConnectedInterfaces;
00519
00520 bool isMultipleConnected_;
00521 protected:
00525 bool isMultipleConnected() const {return isMultipleConnected_;}
00526 public:
00527
00528 OutputInterfaceT(Device* const dev, int ID);
00529
00530 virtual size_t sequenceCapacity() const {return sequenceCapacity_;}
00531 virtual size_t sequenceLength() const {return sequenceLength_;}
00532
00533 virtual void setSequenceCapacity(size_t size);
00534 virtual void setSequenceLength(size_t size);
00535
00536 T* const internSequence();
00537
00538 virtual void connect(InputInterface* interfacePtr);
00539
00540 virtual void reset();
00541
00542
00543 virtual bool isConnected() const {return connectedInterface != NULL;}
00544
00545 virtual void flushProcessedSequences();
00546
00547 virtual void processFinished();
00548
00549 };
00550
00551 }
00552
00553
00554 #endif
00555
00556