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