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