[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 | #include <vector>
|
---|
| 9 | using namespace std;
|
---|
| 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 |
|
---|
[1365] | 33 | #ifdef WITH_SOPHYA
|
---|
[1462] | 34 | // l'interface va etre modifiee, NE PAS UTILISER
|
---|
[1365] | 35 | virtual Array getData(int iStart, int iEnd);
|
---|
| 36 | virtual Array getError(int iStart, int iEnd);
|
---|
| 37 | virtual TArray<int_4> getFlag(int iStart, int iEnd);
|
---|
[1462] | 38 | // l'interface va etre modifiee, NE PAS UTILISER
|
---|
[1365] | 39 | #endif
|
---|
[1462] | 40 |
|
---|
| 41 | enum DataStatus {DATA_OK=0, DATA_DELETED, DATA_NOT_YET};
|
---|
[1365] | 42 |
|
---|
| 43 | virtual double getData(int i);
|
---|
[1462] | 44 | virtual void getData(int i,double &data,int_4 &flag);
|
---|
| 45 | //RZCMV virtual DataStatus getDataError(int i,double &data,double &error,int_4 &flag);
|
---|
[1365] | 46 |
|
---|
| 47 | virtual DataStatus isDataAvail(int iStart, int iEnd);
|
---|
| 48 | virtual DataStatus isDataAvail(int i);
|
---|
| 49 | virtual void waitForData(int iStart, int iEnd);
|
---|
| 50 | virtual void waitForData(int i);
|
---|
| 51 | virtual void waitForAnyData();
|
---|
| 52 | virtual int nextDataAvail(int iAfter)=0;
|
---|
| 53 | virtual bool hasSomeData()=0;
|
---|
| 54 |
|
---|
| 55 | virtual void putData(int i, double value, int_4 flag=0);
|
---|
[1462] | 56 | //RZCMV virtual void putDataError(int i, double value,
|
---|
| 57 | // double error, int_4 flag=0);
|
---|
[1365] | 58 |
|
---|
| 59 | virtual void wontNeedBefore(int i);
|
---|
| 60 |
|
---|
| 61 | bool dbg;
|
---|
| 62 |
|
---|
| 63 | void setName(string n) {name =n;}
|
---|
[1437] | 64 | string getName() const {return name;}
|
---|
[1365] | 65 |
|
---|
| 66 | protected:
|
---|
| 67 | TOI* errorTOI;
|
---|
| 68 | pthread_mutex_t mutex;
|
---|
[1437] | 69 | // ----- Rajouts Reza 12/3/2001
|
---|
| 70 | pthread_cond_t condv;
|
---|
| 71 | bool fgwaitput;
|
---|
| 72 | bool fgwaitget;
|
---|
| 73 | bool fgsigput;
|
---|
| 74 | bool fgsigget;
|
---|
| 75 | int countwaitput;
|
---|
| 76 | int countwaitget;
|
---|
| 77 | // Fin rajouts Reza 12/3/2001 ------
|
---|
| 78 |
|
---|
[1365] | 79 | TOIProcessor* producer;
|
---|
| 80 | vector<TOIProcessor*> consumers;
|
---|
| 81 | double defaultValue;
|
---|
| 82 |
|
---|
| 83 | #ifdef WITH_SOPHYA
|
---|
| 84 | virtual Array doGetData(int iStart, int iEnd)=0;
|
---|
| 85 | virtual TArray<int_4> doGetFlag(int iStart, int iEnd)=0;
|
---|
| 86 | #endif
|
---|
[1462] | 87 | virtual void doGetData(int i, double& data, int_4& flag)=0;
|
---|
[1365] | 88 | virtual void doPutData(int i, double value, int_4 flag=0)=0;
|
---|
| 89 | virtual void doWontNeedBefore(int i);
|
---|
| 90 |
|
---|
| 91 | virtual DataStatus isDataAvailNL(int iStart, int iEnd)=0;
|
---|
| 92 | virtual DataStatus isDataAvailNL(int i);
|
---|
| 93 |
|
---|
| 94 | virtual void setProducer(TOIProcessor* prod);
|
---|
| 95 | virtual void addConsumer(TOIProcessor* prod);
|
---|
| 96 | friend class TOIProcessor;
|
---|
| 97 |
|
---|
| 98 | string name;
|
---|
| 99 |
|
---|
| 100 | virtual int getMinSn();
|
---|
| 101 | virtual int getMaxSn();
|
---|
| 102 | void TOIInit();
|
---|
| 103 |
|
---|
[1437] | 104 | // Il faut faire attention avec mutex et condv, si TOI cree sur le stack !
|
---|
| 105 | // Il faut donc faire new TOI - Reza 11/3/2001
|
---|
[1365] | 106 | void lock() {pthread_mutex_lock(&mutex);}
|
---|
| 107 | void unlock() {pthread_mutex_unlock(&mutex);}
|
---|
| 108 |
|
---|
[1437] | 109 | // ----- Rajouts Reza 12/3/2001
|
---|
| 110 | void wait() {pthread_cond_wait(&condv, &mutex);}
|
---|
| 111 | void signal() {pthread_cond_signal(&condv);}
|
---|
| 112 | void broadcast() {pthread_cond_broadcast(&condv);}
|
---|
| 113 | inline void waitPut()
|
---|
| 114 | {fgwaitput=true; countwaitput++; pthread_cond_wait(&condv, &mutex);}
|
---|
| 115 | inline void waitGet()
|
---|
| 116 | {fgwaitget=true; countwaitget++; pthread_cond_wait(&condv, &mutex);}
|
---|
| 117 | inline bool isPutWaiting() const { return fgwaitput; }
|
---|
| 118 | inline bool isGetWaiting() const { return fgwaitget; }
|
---|
| 119 | inline void signalPut() {fgsigput=true;}
|
---|
| 120 | inline void signalGet() {fgsigget=true;}
|
---|
| 121 | inline void cleanWaitPut() { fgsigput = fgwaitput = false; }
|
---|
| 122 | inline void cleanWaitGet() { fgsigget = fgwaitget = false; }
|
---|
| 123 |
|
---|
| 124 | public:
|
---|
| 125 | inline int getCountWaitPut() const { return countwaitput; }
|
---|
| 126 | inline int getCountWaitGet() const { return countwaitget; }
|
---|
| 127 | // Fin rajouts Reza 12/3/2001 ------
|
---|
| 128 |
|
---|
[1365] | 129 | };
|
---|
| 130 |
|
---|
[1437] | 131 | inline ostream & operator << (ostream & os, TOI const & toi)
|
---|
| 132 | { toi.PrintStatus(os); return os; }
|
---|
| 133 |
|
---|
[1365] | 134 | class TOIRegular : public TOI {
|
---|
| 135 | };
|
---|
| 136 |
|
---|
| 137 | // Classe de TOI avec une fenetre glissante, et echantillonnage regulier.
|
---|
| 138 | // Pour le moment au moins,
|
---|
| 139 | // il faut que les providers fassent arriver les donnees par samplenum croissant.
|
---|
| 140 | class TOIRegularWindow : public TOIRegular {
|
---|
| 141 | public:
|
---|
| 142 | TOIRegularWindow();
|
---|
| 143 | TOIRegularWindow(string nm);
|
---|
[1437] | 144 | virtual ~TOIRegularWindow();
|
---|
[1365] | 145 |
|
---|
| 146 | virtual DataStatus isDataAvailNL(int iStart, int iEnd);
|
---|
| 147 | virtual DataStatus isDataAvailNL(int i); // override required
|
---|
| 148 |
|
---|
| 149 |
|
---|
| 150 | //protected:
|
---|
| 151 | vector<double> data;
|
---|
| 152 | vector<int_4> flags;
|
---|
| 153 | long i0;
|
---|
| 154 | double defaultValue;
|
---|
[1437] | 155 |
|
---|
[1365] | 156 | #ifdef WITH_SOPHYA
|
---|
| 157 | virtual Array doGetData(int iStart, int iEnd);
|
---|
| 158 | virtual TArray<int_4> doGetFlag(int iStart, int iEnd);
|
---|
| 159 | #endif
|
---|
[1462] | 160 | virtual void doGetData(int i, double & val, int_4 & flg);
|
---|
[1365] | 161 |
|
---|
| 162 | virtual void doPutData(int i, double value, int_4 flag=0);
|
---|
| 163 | virtual void doWontNeedBefore(int i);
|
---|
| 164 |
|
---|
| 165 | virtual int nextDataAvail(int iAfter);
|
---|
| 166 | virtual bool hasSomeData();
|
---|
| 167 | };
|
---|
| 168 |
|
---|
| 169 | #endif
|
---|