| 1 | // This may look like C code, but it is really -*- C++ -*- | 
|---|
| 2 |  | 
|---|
| 3 | // ArchTOIPipe           (C)     CEA/DAPNIA/SPP IN2P3/LAL | 
|---|
| 4 | //                               Eric Aubourg | 
|---|
| 5 | //                               Christophe Magneville | 
|---|
| 6 | //                               Reza Ansari | 
|---|
| 7 | // $Id: toi.h,v 1.16 2002-05-09 20:22:37 ansari Exp $ | 
|---|
| 8 |  | 
|---|
| 9 | #ifndef TOI_H | 
|---|
| 10 | #define TOI_H | 
|---|
| 11 |  | 
|---|
| 12 | #include "config.h" | 
|---|
| 13 | #include <vector> | 
|---|
| 14 | using namespace std; | 
|---|
| 15 |  | 
|---|
| 16 | #include <pthread.h> | 
|---|
| 17 |  | 
|---|
| 18 | #ifdef WITH_SOPHYA | 
|---|
| 19 | #include "array.h" | 
|---|
| 20 | #include "pexceptions.h" | 
|---|
| 21 | using namespace SOPHYA; | 
|---|
| 22 | #else | 
|---|
| 23 | #include "apexceptions.h" | 
|---|
| 24 | #endif | 
|---|
| 25 |  | 
|---|
| 26 |  | 
|---|
| 27 |  | 
|---|
| 28 | class TOIProcessor; | 
|---|
| 29 |  | 
|---|
| 30 | class TOI { | 
|---|
| 31 | public: | 
|---|
| 32 | TOI(); | 
|---|
| 33 | TOI(string name); | 
|---|
| 34 | virtual ~TOI(); | 
|---|
| 35 |  | 
|---|
| 36 | //   ----- Rajouts Reza 12/3/2001 | 
|---|
| 37 | virtual void PrintStatus(::ostream & os) const; | 
|---|
| 38 | //  Fin rajouts Reza 12/3/2001 ------ | 
|---|
| 39 |  | 
|---|
| 40 |  | 
|---|
| 41 | #ifdef WITH_SOPHYA | 
|---|
| 42 | /* l'interface va etre modifiee, NE PAS UTILISER | 
|---|
| 43 | virtual Array         getData(int iStart, int iEnd); | 
|---|
| 44 | virtual Array         getError(int iStart, int iEnd); | 
|---|
| 45 | virtual TArray<int_4> getFlag(int iStart, int iEnd); | 
|---|
| 46 | l'interface va etre modifiee, NE PAS UTILISER */ | 
|---|
| 47 | #endif | 
|---|
| 48 |  | 
|---|
| 49 | enum DataStatus       {DATA_OK=0, DATA_DELETED, DATA_NOT_YET}; | 
|---|
| 50 |  | 
|---|
| 51 | virtual double        getData(int i); | 
|---|
| 52 | virtual void          getData(int i, double &data, uint_8 &flag); | 
|---|
| 53 | //RZCMV  virtual DataStatus    getDataError(int i,double &data,double &error,int_4 &flag); | 
|---|
| 54 | virtual void          getData(int i, int n, double* data, uint_8* flg=0); | 
|---|
| 55 |  | 
|---|
| 56 | virtual DataStatus    isDataAvail(int iStart, int iEnd); | 
|---|
| 57 | virtual DataStatus    isDataAvail(int i); | 
|---|
| 58 | virtual void          waitForData(int iStart, int iEnd); | 
|---|
| 59 | virtual void          waitForData(int i); | 
|---|
| 60 | virtual void          waitForAnyData(); | 
|---|
| 61 | virtual int           nextDataAvail(int iAfter)=0; | 
|---|
| 62 | virtual bool          hasSomeData()=0; | 
|---|
| 63 |  | 
|---|
| 64 | virtual void          putData(int i, double value, uint_8 flag=0); | 
|---|
| 65 | //RZCMV  virtual void          putDataError(int i, double value, | 
|---|
| 66 | //                                 double error, int_4 flag=0); | 
|---|
| 67 | virtual void          putData(int i, int n, double const* val, uint_8 const* flg); | 
|---|
| 68 | virtual void          putDone() {} | 
|---|
| 69 |  | 
|---|
| 70 | virtual void          wontNeedBefore(int i); | 
|---|
| 71 |  | 
|---|
| 72 | bool  dbg; | 
|---|
| 73 |  | 
|---|
| 74 | void setName(string n) {name =n;} | 
|---|
| 75 | string getName() const {return name;} | 
|---|
| 76 |  | 
|---|
| 77 | bool needSyncOldWay() const {return syncOldWay;} | 
|---|
| 78 |  | 
|---|
| 79 | protected: | 
|---|
| 80 | TOI*                  errorTOI; | 
|---|
| 81 | pthread_mutex_t       mutex; | 
|---|
| 82 | //   ----- Rajouts Reza 12/3/2001 | 
|---|
| 83 | pthread_cond_t        condv; | 
|---|
| 84 | bool                  fgwaitput; | 
|---|
| 85 | bool                  fgwaitget; | 
|---|
| 86 | bool                  fgsigput; | 
|---|
| 87 | bool                  fgsigget; | 
|---|
| 88 | int                   countwaitput; | 
|---|
| 89 | int                   countwaitget; | 
|---|
| 90 | //  Fin rajouts Reza 12/3/2001 ------ | 
|---|
| 91 |  | 
|---|
| 92 | TOIProcessor*         producer; | 
|---|
| 93 | vector<TOIProcessor*> consumers; | 
|---|
| 94 | double                defaultValue; | 
|---|
| 95 | bool  syncOldWay; | 
|---|
| 96 |  | 
|---|
| 97 | #ifdef WITH_SOPHYA | 
|---|
| 98 | /* l'interface va etre modifiee, NE PAS UTILISER | 
|---|
| 99 | virtual Array         doGetData(int iStart, int iEnd)=0; | 
|---|
| 100 | virtual TArray<int_4> doGetFlag(int iStart, int iEnd)=0; | 
|---|
| 101 | l'interface va etre modifiee, NE PAS UTILISER */ | 
|---|
| 102 | #endif | 
|---|
| 103 |  | 
|---|
| 104 | virtual void          doGetData(int i, double& data, uint_8& flag)=0; | 
|---|
| 105 | virtual void          doPutData(int i, double value, uint_8 flag=0)=0; | 
|---|
| 106 | virtual void          doWontNeedBefore(int i); | 
|---|
| 107 |  | 
|---|
| 108 | virtual DataStatus    isDataAvailNL(int iStart, int iEnd)=0; | 
|---|
| 109 | virtual DataStatus    isDataAvailNL(int i); | 
|---|
| 110 |  | 
|---|
| 111 | virtual void          setProducer(TOIProcessor* prod); | 
|---|
| 112 | public: // for toiprocessors redefining addInput. Change ? | 
|---|
| 113 | virtual void          addConsumer(TOIProcessor* prod); | 
|---|
| 114 | protected: | 
|---|
| 115 | friend class          TOIProcessor; | 
|---|
| 116 |  | 
|---|
| 117 | string name; | 
|---|
| 118 |  | 
|---|
| 119 | virtual int           getMinSn(); | 
|---|
| 120 | virtual int           getMaxSn(); | 
|---|
| 121 | void  TOIInit(); | 
|---|
| 122 |  | 
|---|
| 123 | // Il faut faire attention avec mutex et condv, si TOI cree sur le stack ! | 
|---|
| 124 | // Il faut donc faire new TOI  -    Reza 11/3/2001 | 
|---|
| 125 | void lock() {pthread_mutex_lock(&mutex);} | 
|---|
| 126 | void unlock() {pthread_mutex_unlock(&mutex);} | 
|---|
| 127 |  | 
|---|
| 128 | //   ----- Rajouts Reza 12/3/2001 | 
|---|
| 129 | inline void wait() {pthread_cond_wait(&condv, &mutex);} | 
|---|
| 130 | inline void signal() {pthread_cond_signal(&condv);} | 
|---|
| 131 | inline void broadcast() {pthread_cond_broadcast(&condv);} | 
|---|
| 132 | inline void waitPut() | 
|---|
| 133 | {fgwaitput=true; countwaitput++; pthread_cond_wait(&condv, &mutex);} | 
|---|
| 134 | inline void waitGet() | 
|---|
| 135 | {fgwaitget=true; countwaitget++; pthread_cond_wait(&condv, &mutex);} | 
|---|
| 136 | inline bool isPutWaiting() const { return fgwaitput; } | 
|---|
| 137 | inline bool isGetWaiting() const { return fgwaitget; } | 
|---|
| 138 | inline void signalPut() {fgsigput=true; } | 
|---|
| 139 | inline void signalGet() {fgsigget=true; } | 
|---|
| 140 | inline void cleanWaitPut() { fgsigput = fgwaitput = false; } | 
|---|
| 141 | inline void cleanWaitGet() { fgsigget = fgwaitget = false; } | 
|---|
| 142 |  | 
|---|
| 143 | public: | 
|---|
| 144 | inline int  getCountWaitPut() const { return countwaitput; } | 
|---|
| 145 | inline int  getCountWaitGet() const { return countwaitget; } | 
|---|
| 146 | //  Fin rajouts Reza 12/3/2001 ------ | 
|---|
| 147 |  | 
|---|
| 148 | }; | 
|---|
| 149 |  | 
|---|
| 150 | inline ::ostream & operator << (::ostream & os, TOI const & toi) | 
|---|
| 151 | { toi.PrintStatus(os); return os; } | 
|---|
| 152 |  | 
|---|
| 153 | class TOIRegular : public TOI { | 
|---|
| 154 | }; | 
|---|
| 155 |  | 
|---|
| 156 |  | 
|---|
| 157 | #endif | 
|---|