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>
|
---|
13 | #include <iostream.h>
|
---|
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);
|
---|
54 | double getError(int toiIndex, int i);
|
---|
55 | int_4 getFlag(int toiIndex, int i);
|
---|
56 |
|
---|
57 | void wontNeedBefore(int i);
|
---|
58 | int wontNeedValue;
|
---|
59 | void setNeededHistory(int nsamples); // -1 : disable
|
---|
60 |
|
---|
61 | void putData(int toiIndex, int i, double value, int_4 flag=0);
|
---|
62 | void putDataError(int toiIndex, int i, double value,
|
---|
63 | double error, int_4 flag=0);
|
---|
64 |
|
---|
65 | // Gestion des bornes pour les transformations de TOIs...
|
---|
66 | virtual int calcMinOut();
|
---|
67 | virtual int calcMaxOut();
|
---|
68 |
|
---|
69 | virtual int getMinOut();
|
---|
70 | virtual int getMaxOut();
|
---|
71 | int minOut;
|
---|
72 | int maxOut;
|
---|
73 |
|
---|
74 | virtual int getMinIn();
|
---|
75 | virtual int getMaxIn();
|
---|
76 | // Implementation par defaut
|
---|
77 | int upExtra;
|
---|
78 | int lowExtra;
|
---|
79 |
|
---|
80 | int neededHistory;
|
---|
81 |
|
---|
82 | protected:
|
---|
83 | int getInputTOIIndex(string toi);
|
---|
84 | int getOutputTOIIndex(string toi);
|
---|
85 |
|
---|
86 | // Methodes rajoutees par Reza 11/3/2001
|
---|
87 | TOI* getInputTOI(int toiIndex);
|
---|
88 | TOI* getOutputTOI(int toiIndex);
|
---|
89 | bool checkInputTOIIndex(int toiIndex);
|
---|
90 | bool checkOutputTOIIndex(int toiIndex);
|
---|
91 |
|
---|
92 | // Fin rajout Reza 11/3/2001
|
---|
93 |
|
---|
94 | void autoWontNeed(int iCur);
|
---|
95 | int lastAWN;
|
---|
96 |
|
---|
97 | public:
|
---|
98 | // Appele par les assembleurs de pipeline
|
---|
99 | virtual void addInput(string name, TOI* toi);
|
---|
100 | virtual void addOutput(string name, TOI* toi);
|
---|
101 |
|
---|
102 |
|
---|
103 | int getNIn() {chkinit(); return inIx.size();}
|
---|
104 | int getNOut() {chkinit(); return outIx.size();}
|
---|
105 | string getOutName(int i);
|
---|
106 | string getInName(int i);
|
---|
107 |
|
---|
108 | // Methodes rajoutees par Reza 11/3/2001
|
---|
109 | void PrintStatus(ostream & os) ; // const plus tard
|
---|
110 | // Fin rajout Reza 11/3/2001
|
---|
111 |
|
---|
112 | virtual void start();
|
---|
113 |
|
---|
114 | TOIProcessor();
|
---|
115 | virtual ~TOIProcessor();
|
---|
116 |
|
---|
117 | protected:
|
---|
118 |
|
---|
119 | map<string, int> inIx;
|
---|
120 | map<string, int> outIx;
|
---|
121 | TOI** inTOIs;
|
---|
122 | TOI** outTOIs;
|
---|
123 |
|
---|
124 | string name;
|
---|
125 | // Thread handling
|
---|
126 | pthread_t thread;
|
---|
127 | pthread_cond_t dataReady;
|
---|
128 | pthread_mutex_t mutex;
|
---|
129 | pthread_mutexattr_t mutattr;
|
---|
130 |
|
---|
131 | void lock() {
|
---|
132 | pthread_mutex_lock(&mutex);
|
---|
133 | }
|
---|
134 |
|
---|
135 | void unlock() {
|
---|
136 | pthread_mutex_unlock(&mutex);
|
---|
137 | }
|
---|
138 |
|
---|
139 | void wait() {
|
---|
140 | pthread_cond_wait(&dataReady, &mutex);
|
---|
141 | }
|
---|
142 |
|
---|
143 | void notify();
|
---|
144 |
|
---|
145 |
|
---|
146 | friend class TOI;
|
---|
147 |
|
---|
148 | static void* ThreadStart(void *);
|
---|
149 | };
|
---|
150 |
|
---|
151 | inline ostream & operator << (ostream & os, TOIProcessor /*const*/ & toip)
|
---|
152 | { toip.PrintStatus(os); return os; }
|
---|
153 |
|
---|
154 |
|
---|
155 | #endif
|
---|
156 |
|
---|