| [1365] | 1 | // This may look like C code, but it is really -*- C++ -*- | 
|---|
| [1738] | 2 |  | 
|---|
|  | 3 | // ArchTOIPipe           (C)     CEA/DAPNIA/SPP IN2P3/LAL | 
|---|
|  | 4 | //                               Eric Aubourg | 
|---|
|  | 5 | //                               Christophe Magneville | 
|---|
|  | 6 | //                               Reza Ansari | 
|---|
| [2454] | 7 | // $Id: toi.h,v 1.18 2003-11-14 12:34:55 aubourg Exp $ | 
|---|
| [1738] | 8 |  | 
|---|
| [1365] | 9 | #ifndef TOI_H | 
|---|
|  | 10 | #define TOI_H | 
|---|
|  | 11 |  | 
|---|
|  | 12 | #include "config.h" | 
|---|
| [1766] | 13 | #include <vector> | 
|---|
| [1477] | 14 | using namespace std; | 
|---|
| [1365] | 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 |  | 
|---|
| [1437] | 36 | //   ----- Rajouts Reza 12/3/2001 | 
|---|
| [1762] | 37 | virtual void PrintStatus(::ostream & os) const; | 
|---|
| [1437] | 38 | //  Fin rajouts Reza 12/3/2001 ------ | 
|---|
|  | 39 |  | 
|---|
| [1464] | 40 |  | 
|---|
| [1365] | 41 | #ifdef WITH_SOPHYA | 
|---|
| [1464] | 42 | /* l'interface va etre modifiee, NE PAS UTILISER | 
|---|
| [1365] | 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); | 
|---|
| [1464] | 46 | l'interface va etre modifiee, NE PAS UTILISER */ | 
|---|
| [1365] | 47 | #endif | 
|---|
| [1462] | 48 |  | 
|---|
|  | 49 | enum DataStatus       {DATA_OK=0, DATA_DELETED, DATA_NOT_YET}; | 
|---|
| [1365] | 50 |  | 
|---|
| [2454] | 51 | virtual double        getData(long i); | 
|---|
|  | 52 | virtual void          getData(long i, double &data, uint_8 &flag); | 
|---|
|  | 53 | //RZCMV  virtual DataStatus    getDataError(long i,double &data,double &error,int_4 &flag); | 
|---|
|  | 54 | virtual void          getData(long i, int n, double* data, uint_8* flg=0); | 
|---|
| [1365] | 55 |  | 
|---|
| [2454] | 56 | virtual DataStatus    isDataAvail(long iStart, long iEnd); | 
|---|
|  | 57 | virtual DataStatus    isDataAvail(long i); | 
|---|
|  | 58 | virtual void          waitForData(long iStart, long iEnd); | 
|---|
|  | 59 | virtual void          waitForData(long i); | 
|---|
| [1365] | 60 | virtual void          waitForAnyData(); | 
|---|
| [2454] | 61 | virtual long           nextDataAvail(long iAfter)=0; | 
|---|
| [1365] | 62 | virtual bool          hasSomeData()=0; | 
|---|
|  | 63 |  | 
|---|
| [2454] | 64 | virtual void          putData(long i, double value, uint_8 flag=0); | 
|---|
|  | 65 | //RZCMV  virtual void          putDataError(long i, double value, | 
|---|
| [1462] | 66 | //                                 double error, int_4 flag=0); | 
|---|
| [2454] | 67 | virtual void          putData(long i, int n, double const* val, uint_8 const* flg); | 
|---|
| [1689] | 68 | virtual void          putDone() {} | 
|---|
| [1365] | 69 |  | 
|---|
| [2454] | 70 | virtual void          wontNeedBefore(long i); | 
|---|
| [1365] | 71 |  | 
|---|
|  | 72 | bool  dbg; | 
|---|
|  | 73 |  | 
|---|
|  | 74 | void setName(string n) {name =n;} | 
|---|
| [1437] | 75 | string getName() const {return name;} | 
|---|
| [1365] | 76 |  | 
|---|
| [1740] | 77 | bool needSyncOldWay() const {return syncOldWay;} | 
|---|
|  | 78 |  | 
|---|
| [1365] | 79 | protected: | 
|---|
|  | 80 | TOI*                  errorTOI; | 
|---|
|  | 81 | pthread_mutex_t       mutex; | 
|---|
| [1437] | 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 |  | 
|---|
| [2187] | 92 | // variables pour propagation | 
|---|
|  | 93 | TOIProcessor*         producer;       //producteur du toi | 
|---|
|  | 94 | vector<TOIProcessor*> consumers;      //consomateurs du toi | 
|---|
|  | 95 |  | 
|---|
| [1365] | 96 | double                defaultValue; | 
|---|
| [1740] | 97 | bool  syncOldWay; | 
|---|
|  | 98 |  | 
|---|
| [1365] | 99 | #ifdef WITH_SOPHYA | 
|---|
| [1464] | 100 | /* l'interface va etre modifiee, NE PAS UTILISER | 
|---|
| [2454] | 101 | virtual Array         doGetData(long iStart, long iEnd)=0; | 
|---|
|  | 102 | virtual TArray<int_4> doGetFlag(long iStart, long iEnd)=0; | 
|---|
| [1464] | 103 | l'interface va etre modifiee, NE PAS UTILISER */ | 
|---|
| [1365] | 104 | #endif | 
|---|
| [1464] | 105 |  | 
|---|
| [2454] | 106 | virtual void          doGetData(long i, double& data, uint_8& flag)=0; | 
|---|
|  | 107 | virtual void          doPutData(long i, double value, uint_8 flag=0)=0; | 
|---|
|  | 108 | virtual void          doWontNeedBefore(long i); | 
|---|
| [1365] | 109 |  | 
|---|
| [2454] | 110 | virtual DataStatus    isDataAvailNL(long iStart, long iEnd)=0; | 
|---|
|  | 111 | virtual DataStatus    isDataAvailNL(long i); | 
|---|
| [1365] | 112 |  | 
|---|
|  | 113 | virtual void          setProducer(TOIProcessor* prod); | 
|---|
| [1692] | 114 | public: // for toiprocessors redefining addInput. Change ? | 
|---|
| [1365] | 115 | virtual void          addConsumer(TOIProcessor* prod); | 
|---|
| [1692] | 116 | protected: | 
|---|
| [1365] | 117 | friend class          TOIProcessor; | 
|---|
|  | 118 |  | 
|---|
|  | 119 | string name; | 
|---|
|  | 120 |  | 
|---|
| [2454] | 121 | virtual long           getMinSn(); | 
|---|
|  | 122 | virtual long           getMaxSn(); | 
|---|
| [1365] | 123 | void  TOIInit(); | 
|---|
|  | 124 |  | 
|---|
| [1437] | 125 | // Il faut faire attention avec mutex et condv, si TOI cree sur le stack ! | 
|---|
|  | 126 | // Il faut donc faire new TOI  -    Reza 11/3/2001 | 
|---|
| [1365] | 127 | void lock() {pthread_mutex_lock(&mutex);} | 
|---|
|  | 128 | void unlock() {pthread_mutex_unlock(&mutex);} | 
|---|
|  | 129 |  | 
|---|
| [1437] | 130 | //   ----- Rajouts Reza 12/3/2001 | 
|---|
| [1993] | 131 | inline void wait() {pthread_cond_wait(&condv, &mutex);} | 
|---|
|  | 132 | inline void signal() {pthread_cond_signal(&condv);} | 
|---|
|  | 133 | inline void broadcast() {pthread_cond_broadcast(&condv);} | 
|---|
| [1437] | 134 | inline void waitPut() | 
|---|
|  | 135 | {fgwaitput=true; countwaitput++; pthread_cond_wait(&condv, &mutex);} | 
|---|
|  | 136 | inline void waitGet() | 
|---|
|  | 137 | {fgwaitget=true; countwaitget++; pthread_cond_wait(&condv, &mutex);} | 
|---|
|  | 138 | inline bool isPutWaiting() const { return fgwaitput; } | 
|---|
|  | 139 | inline bool isGetWaiting() const { return fgwaitget; } | 
|---|
| [1993] | 140 | inline void signalPut() {fgsigput=true; } | 
|---|
|  | 141 | inline void signalGet() {fgsigget=true; } | 
|---|
| [1437] | 142 | inline void cleanWaitPut() { fgsigput = fgwaitput = false; } | 
|---|
|  | 143 | inline void cleanWaitGet() { fgsigget = fgwaitget = false; } | 
|---|
|  | 144 |  | 
|---|
| [2187] | 145 |  | 
|---|
|  | 146 | // ajout vf 31/07/2002 | 
|---|
|  | 147 | bool checkSampleLimits(long &Min, long &Max, int pass); | 
|---|
|  | 148 |  | 
|---|
|  | 149 |  | 
|---|
|  | 150 |  | 
|---|
|  | 151 |  | 
|---|
|  | 152 |  | 
|---|
| [1437] | 153 | public: | 
|---|
|  | 154 | inline int  getCountWaitPut() const { return countwaitput; } | 
|---|
|  | 155 | inline int  getCountWaitGet() const { return countwaitget; } | 
|---|
|  | 156 | //  Fin rajouts Reza 12/3/2001 ------ | 
|---|
|  | 157 |  | 
|---|
| [1365] | 158 | }; | 
|---|
|  | 159 |  | 
|---|
| [1762] | 160 | inline ::ostream & operator << (::ostream & os, TOI const & toi) | 
|---|
| [1437] | 161 | { toi.PrintStatus(os); return os; } | 
|---|
|  | 162 |  | 
|---|
| [1365] | 163 | class TOIRegular : public TOI { | 
|---|
|  | 164 | }; | 
|---|
|  | 165 |  | 
|---|
|  | 166 |  | 
|---|
|  | 167 | #endif | 
|---|
| [2187] | 168 |  | 
|---|
|  | 169 |  | 
|---|
|  | 170 |  | 
|---|
|  | 171 |  | 
|---|
|  | 172 |  | 
|---|
|  | 173 |  | 
|---|