[1365] | 1 | // This may look like C code, but it is really -*- C++ -*-
|
---|
| 2 |
|
---|
| 3 |
|
---|
| 4 | #ifndef TOIPROCESSOR_H
|
---|
| 5 | #define TOIPROCESSOR_H
|
---|
| 6 |
|
---|
| 7 | #include "config.h"
|
---|
| 8 |
|
---|
| 9 | #include <pthread.h>
|
---|
| 10 |
|
---|
| 11 | #include <string>
|
---|
| 12 | #include <map>
|
---|
[1410] | 13 | #include <iostream.h>
|
---|
[1365] | 14 |
|
---|
| 15 | #ifndef NO_SOPHYA
|
---|
| 16 | #include "tarray.h"
|
---|
| 17 | using namespace SOPHYA;
|
---|
| 18 | #endif
|
---|
| 19 |
|
---|
| 20 | #include "toi.h"
|
---|
| 21 |
|
---|
| 22 |
|
---|
| 23 | class TOIProcessor {
|
---|
| 24 | public:
|
---|
| 25 | virtual void init();
|
---|
| 26 | // Les methodes qui suivent peuvent etre appelees par init
|
---|
| 27 | protected:
|
---|
| 28 | int declareInput(string toi);
|
---|
| 29 | int declareOutput(string toi);
|
---|
| 30 |
|
---|
| 31 | // void declareMultInput(string toi);
|
---|
| 32 | // Question : multiple output ?
|
---|
| 33 |
|
---|
| 34 | void chkinit() {
|
---|
| 35 | if (!inited) {init(); afterinit(); inited=true;}
|
---|
| 36 | }
|
---|
| 37 | bool inited;
|
---|
| 38 | virtual void afterinit();
|
---|
| 39 |
|
---|
| 40 | public:
|
---|
| 41 | virtual void run();
|
---|
| 42 | // Les methodes qui suivent peut etre appelees par run
|
---|
| 43 | protected:
|
---|
| 44 | #ifndef NO_SOPHYA
|
---|
| 45 | Array getData(int toiIndex, int iStart, int iEnd);
|
---|
| 46 | Array getError(int toiIndex, int iStart, int iEnd);
|
---|
| 47 | TArray<int_4> getFlag(int toiIndex, int iStart, int iEnd);
|
---|
| 48 | #endif
|
---|
| 49 | // si multiple input (indexed input), tableau 2D.
|
---|
| 50 |
|
---|
| 51 | // Les methodes qui suivent ne peuvent etre
|
---|
| 52 | // utilisees que sur des entrees simples
|
---|
| 53 | double getData(int toiIndex, int i);
|
---|
[1462] | 54 | void getData(int toiIndex, int i, double &data,int_4 &flag);
|
---|
| 55 |
|
---|
| 56 | //RZCMV double getError(int toiIndex, int i);
|
---|
| 57 | //RZCMV int_4 getFlag(int toiIndex, int i);
|
---|
[1365] | 58 |
|
---|
| 59 | void wontNeedBefore(int i);
|
---|
| 60 | int wontNeedValue;
|
---|
| 61 | void setNeededHistory(int nsamples); // -1 : disable
|
---|
| 62 |
|
---|
| 63 | void putData(int toiIndex, int i, double value, int_4 flag=0);
|
---|
[1462] | 64 | //RZCMV void putDataError(int toiIndex, int i, double value,
|
---|
| 65 | //RZCMV double error, int_4 flag=0);
|
---|
[1365] | 66 |
|
---|
| 67 | // Gestion des bornes pour les transformations de TOIs...
|
---|
| 68 | virtual int calcMinOut();
|
---|
| 69 | virtual int calcMaxOut();
|
---|
| 70 |
|
---|
| 71 | virtual int getMinOut();
|
---|
| 72 | virtual int getMaxOut();
|
---|
| 73 | int minOut;
|
---|
| 74 | int maxOut;
|
---|
| 75 |
|
---|
| 76 | virtual int getMinIn();
|
---|
| 77 | virtual int getMaxIn();
|
---|
| 78 | // Implementation par defaut
|
---|
| 79 | int upExtra;
|
---|
| 80 | int lowExtra;
|
---|
| 81 |
|
---|
| 82 | int neededHistory;
|
---|
| 83 |
|
---|
| 84 | protected:
|
---|
| 85 | int getInputTOIIndex(string toi);
|
---|
| 86 | int getOutputTOIIndex(string toi);
|
---|
[1437] | 87 |
|
---|
| 88 | // Methodes rajoutees par Reza 11/3/2001
|
---|
| 89 | TOI* getInputTOI(int toiIndex);
|
---|
| 90 | TOI* getOutputTOI(int toiIndex);
|
---|
| 91 | bool checkInputTOIIndex(int toiIndex);
|
---|
| 92 | bool checkOutputTOIIndex(int toiIndex);
|
---|
| 93 |
|
---|
| 94 | // Fin rajout Reza 11/3/2001
|
---|
| 95 |
|
---|
[1365] | 96 | void autoWontNeed(int iCur);
|
---|
| 97 | int lastAWN;
|
---|
| 98 |
|
---|
| 99 | public:
|
---|
| 100 | // Appele par les assembleurs de pipeline
|
---|
| 101 | virtual void addInput(string name, TOI* toi);
|
---|
| 102 | virtual void addOutput(string name, TOI* toi);
|
---|
| 103 |
|
---|
[1367] | 104 |
|
---|
| 105 | int getNIn() {chkinit(); return inIx.size();}
|
---|
| 106 | int getNOut() {chkinit(); return outIx.size();}
|
---|
| 107 | string getOutName(int i);
|
---|
| 108 | string getInName(int i);
|
---|
| 109 |
|
---|
[1437] | 110 | // Methodes rajoutees par Reza 11/3/2001
|
---|
[1443] | 111 | virtual void PrintStatus(ostream & os) ; // const plus tard
|
---|
[1437] | 112 | // Fin rajout Reza 11/3/2001
|
---|
| 113 |
|
---|
[1365] | 114 | virtual void start();
|
---|
| 115 |
|
---|
| 116 | TOIProcessor();
|
---|
| 117 | virtual ~TOIProcessor();
|
---|
| 118 |
|
---|
| 119 | protected:
|
---|
| 120 |
|
---|
| 121 | map<string, int> inIx;
|
---|
| 122 | map<string, int> outIx;
|
---|
| 123 | TOI** inTOIs;
|
---|
| 124 | TOI** outTOIs;
|
---|
| 125 |
|
---|
| 126 | string name;
|
---|
| 127 | // Thread handling
|
---|
| 128 | pthread_t thread;
|
---|
| 129 | pthread_cond_t dataReady;
|
---|
| 130 | pthread_mutex_t mutex;
|
---|
| 131 | pthread_mutexattr_t mutattr;
|
---|
| 132 |
|
---|
| 133 | void lock() {
|
---|
| 134 | pthread_mutex_lock(&mutex);
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | void unlock() {
|
---|
| 138 | pthread_mutex_unlock(&mutex);
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | void wait() {
|
---|
| 142 | pthread_cond_wait(&dataReady, &mutex);
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | void notify();
|
---|
| 146 |
|
---|
| 147 |
|
---|
| 148 | friend class TOI;
|
---|
| 149 |
|
---|
| 150 | static void* ThreadStart(void *);
|
---|
| 151 | };
|
---|
| 152 |
|
---|
[1437] | 153 | inline ostream & operator << (ostream & os, TOIProcessor /*const*/ & toip)
|
---|
| 154 | { toip.PrintStatus(os); return os; }
|
---|
| 155 |
|
---|
| 156 |
|
---|
[1365] | 157 | #endif
|
---|
[1437] | 158 |
|
---|