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