[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);
|
---|
[1365] | 59 |
|
---|
| 60 | virtual void wontNeedBefore(int i);
|
---|
| 61 |
|
---|
| 62 | bool dbg;
|
---|
| 63 |
|
---|
| 64 | void setName(string n) {name =n;}
|
---|
[1437] | 65 | string getName() const {return name;}
|
---|
[1365] | 66 |
|
---|
| 67 | protected:
|
---|
| 68 | TOI* errorTOI;
|
---|
| 69 | pthread_mutex_t mutex;
|
---|
[1437] | 70 | // ----- Rajouts Reza 12/3/2001
|
---|
| 71 | pthread_cond_t condv;
|
---|
| 72 | bool fgwaitput;
|
---|
| 73 | bool fgwaitget;
|
---|
| 74 | bool fgsigput;
|
---|
| 75 | bool fgsigget;
|
---|
| 76 | int countwaitput;
|
---|
| 77 | int countwaitget;
|
---|
| 78 | // Fin rajouts Reza 12/3/2001 ------
|
---|
| 79 |
|
---|
[1365] | 80 | TOIProcessor* producer;
|
---|
| 81 | vector<TOIProcessor*> consumers;
|
---|
| 82 | double defaultValue;
|
---|
| 83 |
|
---|
| 84 | #ifdef WITH_SOPHYA
|
---|
[1464] | 85 | /* l'interface va etre modifiee, NE PAS UTILISER
|
---|
[1365] | 86 | virtual Array doGetData(int iStart, int iEnd)=0;
|
---|
| 87 | virtual TArray<int_4> doGetFlag(int iStart, int iEnd)=0;
|
---|
[1464] | 88 | l'interface va etre modifiee, NE PAS UTILISER */
|
---|
[1365] | 89 | #endif
|
---|
[1464] | 90 |
|
---|
[1532] | 91 | virtual void doGetData(int i, double& data, uint_8& flag)=0;
|
---|
| 92 | virtual void doPutData(int i, double value, uint_8 flag=0)=0;
|
---|
[1365] | 93 | virtual void doWontNeedBefore(int i);
|
---|
| 94 |
|
---|
| 95 | virtual DataStatus isDataAvailNL(int iStart, int iEnd)=0;
|
---|
| 96 | virtual DataStatus isDataAvailNL(int i);
|
---|
| 97 |
|
---|
| 98 | virtual void setProducer(TOIProcessor* prod);
|
---|
| 99 | virtual void addConsumer(TOIProcessor* prod);
|
---|
| 100 | friend class TOIProcessor;
|
---|
| 101 |
|
---|
| 102 | string name;
|
---|
| 103 |
|
---|
| 104 | virtual int getMinSn();
|
---|
| 105 | virtual int getMaxSn();
|
---|
| 106 | void TOIInit();
|
---|
| 107 |
|
---|
[1437] | 108 | // Il faut faire attention avec mutex et condv, si TOI cree sur le stack !
|
---|
| 109 | // Il faut donc faire new TOI - Reza 11/3/2001
|
---|
[1365] | 110 | void lock() {pthread_mutex_lock(&mutex);}
|
---|
| 111 | void unlock() {pthread_mutex_unlock(&mutex);}
|
---|
| 112 |
|
---|
[1437] | 113 | // ----- Rajouts Reza 12/3/2001
|
---|
| 114 | void wait() {pthread_cond_wait(&condv, &mutex);}
|
---|
| 115 | void signal() {pthread_cond_signal(&condv);}
|
---|
| 116 | void broadcast() {pthread_cond_broadcast(&condv);}
|
---|
| 117 | inline void waitPut()
|
---|
| 118 | {fgwaitput=true; countwaitput++; pthread_cond_wait(&condv, &mutex);}
|
---|
| 119 | inline void waitGet()
|
---|
| 120 | {fgwaitget=true; countwaitget++; pthread_cond_wait(&condv, &mutex);}
|
---|
| 121 | inline bool isPutWaiting() const { return fgwaitput; }
|
---|
| 122 | inline bool isGetWaiting() const { return fgwaitget; }
|
---|
| 123 | inline void signalPut() {fgsigput=true;}
|
---|
| 124 | inline void signalGet() {fgsigget=true;}
|
---|
| 125 | inline void cleanWaitPut() { fgsigput = fgwaitput = false; }
|
---|
| 126 | inline void cleanWaitGet() { fgsigget = fgwaitget = false; }
|
---|
| 127 |
|
---|
| 128 | public:
|
---|
| 129 | inline int getCountWaitPut() const { return countwaitput; }
|
---|
| 130 | inline int getCountWaitGet() const { return countwaitget; }
|
---|
| 131 | // Fin rajouts Reza 12/3/2001 ------
|
---|
| 132 |
|
---|
[1365] | 133 | };
|
---|
| 134 |
|
---|
[1437] | 135 | inline ostream & operator << (ostream & os, TOI const & toi)
|
---|
| 136 | { toi.PrintStatus(os); return os; }
|
---|
| 137 |
|
---|
[1365] | 138 | class TOIRegular : public TOI {
|
---|
| 139 | };
|
---|
| 140 |
|
---|
| 141 |
|
---|
| 142 | #endif
|
---|