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
00112 static const size_t undefinedLength;
00113 };
00114
00115
00119 class DLLIMPORT InputInterface : public DataInterface
00120 {
00121 public:
00122
00127 InputInterface(Device* const dev, int ID);
00128
00129 virtual ~InputInterface();
00130
00134 virtual void reset() = 0;
00135
00143 virtual void acceptNewData(size_t newElements) = 0;
00144
00156 virtual size_t sequenceLength() const = 0;
00157
00160 virtual void setSequenceLength(size_t newLen) = 0;
00161
00166 virtual bool isFilled() const = 0;
00167
00169 bool isConnected() const {return isConnected_;}
00170
00174 virtual void acceptConnection();
00175
00185 virtual void flushProcessedSequence() = 0;
00186
00194 virtual void releaseProcessedSequence() = 0;
00195
00200 virtual void processFinished() = 0;
00201
00205
00206 private:
00207
00208 bool isConnected_;
00209
00210
00211
00212 };
00213
00214
00223 template<class T>
00224 class DLLIMPORT InputInterfaceT : public InputInterface
00225 {
00226
00227 public:
00230 InputInterfaceT(Device* const dev, int ID,
00231 size_t sequenceLength = undefinedLength,
00232 const typename T::value_type&
00233 default_val = typename T::value_type() );
00234
00237 InputInterfaceT(Device* const dev, int ID,
00238 const typename T::value_type& default_val);
00239
00242 virtual ~InputInterfaceT();
00243
00262 T* externSequence(size_t size, size_t capacity);
00263
00276 T* internSequence();
00277
00281 virtual void reset();
00282
00288 virtual void acceptNewData(size_t size);
00289
00301 virtual size_t sequenceLength() const;
00302
00305 virtual void setSequenceLength(size_t newLen);
00306
00311 virtual bool isFilled() const;
00312
00323 virtual void flushProcessedSequence();
00324
00332 virtual void releaseProcessedSequence();
00333
00338 virtual void processFinished();
00339
00340 protected:
00341 void incrementRefCount();
00342 void decrementRefCount();
00343
00344 size_t storedElements() const {return storedElements_;}
00345
00346
00347 private:
00350 typedef typename T::storage_type buffer_type;
00354 typedef typename T::access_type access_type;
00355
00356
00357
00358
00359
00360
00361
00362
00365 buffer_type* seqBuffer;
00366
00367
00368
00369
00370
00371
00372
00373
00377 access_type* inputSubSeq;
00378
00382 access_type* outputSubSeq;
00383
00388 size_t storedElements_;
00389
00400 size_t sequenceLength_;
00401
00404 size_t refCount;
00405
00406 bool waitingForProcess;
00407
00408 void invariante() const;
00409
00410 };
00411
00412
00413
00414
00433 class OutputInterface : public DataInterface
00434 {
00435
00436 public:
00437 OutputInterface(Device* const dev, int ID)
00438 : DataInterface(dev,ID) {};
00439
00440 virtual ~OutputInterface() {};
00441
00442 virtual void connect(InputInterface* interfacePtr) = 0;
00443
00447 virtual void reset() = 0;
00448
00452 virtual size_t sequenceCapacity() const = 0;
00453
00456 virtual size_t sequenceLength() const = 0;
00457
00461 virtual void setSequenceCapacity(size_t size) = 0;
00464 virtual void setSequenceLength(size_t size) = 0;
00465
00468 virtual bool isConnected() const = 0;
00469
00474 virtual void flushProcessedSequences() = 0;
00475
00479 virtual void processFinished() = 0;
00480
00481 protected:
00489 static std::string wrongConnectionMsg(const std::type_info& output_if,
00490 const std::type_info& input_if);
00491
00492 };
00493
00502 template<class T>
00503 class OutputInterfaceT : public OutputInterface
00504 {
00505 private:
00506
00507 size_t sequenceCapacity_;
00508 size_t sequenceLength_;
00509
00510 typedef InputInterfaceT<T> interf_type;
00511
00512 interf_type* connectedInterface;
00513 T* currentOutputSequence;
00514
00515 std::vector<interf_type*> multipleConnectedInterfaces;
00516
00517 bool isMultipleConnected_;
00518 protected:
00522 bool isMultipleConnected() const {return isMultipleConnected_;}
00523 public:
00524
00525 OutputInterfaceT(Device* const dev, int ID);
00526
00527 virtual size_t sequenceCapacity() const {return sequenceCapacity_;}
00528 virtual size_t sequenceLength() const {return sequenceLength_;}
00529
00530 virtual void setSequenceCapacity(size_t size);
00531 virtual void setSequenceLength(size_t size);
00532
00533 T* const internSequence();
00534
00535 virtual void connect(InputInterface* interfacePtr);
00536
00537 virtual void reset();
00538
00539
00540 virtual bool isConnected() const {return connectedInterface != NULL;}
00541
00542 virtual void flushProcessedSequences();
00543
00544 virtual void processFinished();
00545
00546 };
00547
00548 }
00549
00550
00551 #endif
00552
00553