// This may look like C code, but it is really -*- C++ -*- #ifndef TOIPROCESSOR_H #define TOIPROCESSOR_H #include "config.h" #include #include #include #include #ifndef NO_SOPHYA #include "tarray.h" using namespace SOPHYA; #endif #include "toi.h" class TOIProcessor { public: virtual void init(); // Les methodes qui suivent peuvent etre appelees par init protected: int declareInput(string toi); int declareOutput(string toi); // void declareMultInput(string toi); // Question : multiple output ? void chkinit() { if (!inited) {init(); afterinit(); inited=true;} } bool inited; virtual void afterinit(); public: virtual void run(); // Les methodes qui suivent peut etre appelees par run protected: #ifndef NO_SOPHYA Array getData(int toiIndex, int iStart, int iEnd); Array getError(int toiIndex, int iStart, int iEnd); TArray getFlag(int toiIndex, int iStart, int iEnd); #endif // si multiple input (indexed input), tableau 2D. // Les methodes qui suivent ne peuvent etre // utilisees que sur des entrees simples double getData(int toiIndex, int i); double getError(int toiIndex, int i); int_4 getFlag(int toiIndex, int i); void wontNeedBefore(int i); int wontNeedValue; void setNeededHistory(int nsamples); // -1 : disable void putData(int toiIndex, int i, double value, int_4 flag=0); void putDataError(int toiIndex, int i, double value, double error, int_4 flag=0); // Gestion des bornes pour les transformations de TOIs... virtual int calcMinOut(); virtual int calcMaxOut(); virtual int getMinOut(); virtual int getMaxOut(); int minOut; int maxOut; virtual int getMinIn(); virtual int getMaxIn(); // Implementation par defaut int upExtra; int lowExtra; int neededHistory; protected: int getInputTOIIndex(string toi); int getOutputTOIIndex(string toi); void autoWontNeed(int iCur); int lastAWN; public: // Appele par les assembleurs de pipeline virtual void addInput(string name, TOI* toi); virtual void addOutput(string name, TOI* toi); virtual void start(); TOIProcessor(); virtual ~TOIProcessor(); protected: map inIx; map outIx; TOI** inTOIs; TOI** outTOIs; string name; // Thread handling pthread_t thread; pthread_cond_t dataReady; pthread_mutex_t mutex; pthread_mutexattr_t mutattr; void lock() { pthread_mutex_lock(&mutex); } void unlock() { pthread_mutex_unlock(&mutex); } void wait() { pthread_cond_wait(&dataReady, &mutex); } void notify(); friend class TOI; static void* ThreadStart(void *); }; #endif