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 | #include <vector>
|
---|
7 | using namespace std;
|
---|
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 |
|
---|
29 | // ----- Rajouts Reza 12/3/2001
|
---|
30 | virtual void PrintStatus(ostream & os) const;
|
---|
31 | // Fin rajouts Reza 12/3/2001 ------
|
---|
32 |
|
---|
33 |
|
---|
34 | #ifdef WITH_SOPHYA
|
---|
35 | /* l'interface va etre modifiee, NE PAS UTILISER
|
---|
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);
|
---|
39 | l'interface va etre modifiee, NE PAS UTILISER */
|
---|
40 | #endif
|
---|
41 |
|
---|
42 | enum DataStatus {DATA_OK=0, DATA_DELETED, DATA_NOT_YET};
|
---|
43 |
|
---|
44 | virtual double getData(int i);
|
---|
45 | virtual void getData(int i, double &data, uint_8 &flag);
|
---|
46 | //RZCMV virtual DataStatus getDataError(int i,double &data,double &error,int_4 &flag);
|
---|
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 |
|
---|
56 | virtual void putData(int i, double value, uint_8 flag=0);
|
---|
57 | //RZCMV virtual void putDataError(int i, double value,
|
---|
58 | // double error, int_4 flag=0);
|
---|
59 | virtual void putDone() {}
|
---|
60 |
|
---|
61 | virtual void wontNeedBefore(int i);
|
---|
62 |
|
---|
63 | bool dbg;
|
---|
64 |
|
---|
65 | void setName(string n) {name =n;}
|
---|
66 | string getName() const {return name;}
|
---|
67 |
|
---|
68 | protected:
|
---|
69 | TOI* errorTOI;
|
---|
70 | pthread_mutex_t mutex;
|
---|
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 |
|
---|
81 | TOIProcessor* producer;
|
---|
82 | vector<TOIProcessor*> consumers;
|
---|
83 | double defaultValue;
|
---|
84 |
|
---|
85 | #ifdef WITH_SOPHYA
|
---|
86 | /* l'interface va etre modifiee, NE PAS UTILISER
|
---|
87 | virtual Array doGetData(int iStart, int iEnd)=0;
|
---|
88 | virtual TArray<int_4> doGetFlag(int iStart, int iEnd)=0;
|
---|
89 | l'interface va etre modifiee, NE PAS UTILISER */
|
---|
90 | #endif
|
---|
91 |
|
---|
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;
|
---|
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 | public: // for toiprocessors redefining addInput. Change ?
|
---|
101 | virtual void addConsumer(TOIProcessor* prod);
|
---|
102 | protected:
|
---|
103 | friend class TOIProcessor;
|
---|
104 |
|
---|
105 | string name;
|
---|
106 |
|
---|
107 | virtual int getMinSn();
|
---|
108 | virtual int getMaxSn();
|
---|
109 | void TOIInit();
|
---|
110 |
|
---|
111 | // Il faut faire attention avec mutex et condv, si TOI cree sur le stack !
|
---|
112 | // Il faut donc faire new TOI - Reza 11/3/2001
|
---|
113 | void lock() {pthread_mutex_lock(&mutex);}
|
---|
114 | void unlock() {pthread_mutex_unlock(&mutex);}
|
---|
115 |
|
---|
116 | // ----- Rajouts Reza 12/3/2001
|
---|
117 | void wait() {pthread_cond_wait(&condv, &mutex);}
|
---|
118 | void signal() {pthread_cond_signal(&condv);}
|
---|
119 | void broadcast() {pthread_cond_broadcast(&condv);}
|
---|
120 | inline void waitPut()
|
---|
121 | {fgwaitput=true; countwaitput++; pthread_cond_wait(&condv, &mutex);}
|
---|
122 | inline void waitGet()
|
---|
123 | {fgwaitget=true; countwaitget++; pthread_cond_wait(&condv, &mutex);}
|
---|
124 | inline bool isPutWaiting() const { return fgwaitput; }
|
---|
125 | inline bool isGetWaiting() const { return fgwaitget; }
|
---|
126 | inline void signalPut() {fgsigput=true;}
|
---|
127 | inline void signalGet() {fgsigget=true;}
|
---|
128 | inline void cleanWaitPut() { fgsigput = fgwaitput = false; }
|
---|
129 | inline void cleanWaitGet() { fgsigget = fgwaitget = false; }
|
---|
130 |
|
---|
131 | public:
|
---|
132 | inline int getCountWaitPut() const { return countwaitput; }
|
---|
133 | inline int getCountWaitGet() const { return countwaitget; }
|
---|
134 | // Fin rajouts Reza 12/3/2001 ------
|
---|
135 |
|
---|
136 | };
|
---|
137 |
|
---|
138 | inline ostream & operator << (ostream & os, TOI const & toi)
|
---|
139 | { toi.PrintStatus(os); return os; }
|
---|
140 |
|
---|
141 | class TOIRegular : public TOI {
|
---|
142 | };
|
---|
143 |
|
---|
144 |
|
---|
145 | #endif
|
---|