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 | void autoWontNeed(int iCur);
|
---|
86 | int lastAWN;
|
---|
87 |
|
---|
88 | public:
|
---|
89 | // Appele par les assembleurs de pipeline
|
---|
90 | virtual void addInput(string name, TOI* toi);
|
---|
91 | virtual void addOutput(string name, TOI* toi);
|
---|
92 |
|
---|
93 |
|
---|
94 | int getNIn() {chkinit(); return inIx.size();}
|
---|
95 | int getNOut() {chkinit(); return outIx.size();}
|
---|
96 | string getOutName(int i);
|
---|
97 | string getInName(int i);
|
---|
98 |
|
---|
99 | virtual void start();
|
---|
100 |
|
---|
101 | TOIProcessor();
|
---|
102 | virtual ~TOIProcessor();
|
---|
103 |
|
---|
104 | protected:
|
---|
105 |
|
---|
106 | map<string, int> inIx;
|
---|
107 | map<string, int> outIx;
|
---|
108 | TOI** inTOIs;
|
---|
109 | TOI** outTOIs;
|
---|
110 |
|
---|
111 | string name;
|
---|
112 | // Thread handling
|
---|
113 | pthread_t thread;
|
---|
114 | pthread_cond_t dataReady;
|
---|
115 | pthread_mutex_t mutex;
|
---|
116 | pthread_mutexattr_t mutattr;
|
---|
117 |
|
---|
118 | void lock() {
|
---|
119 | pthread_mutex_lock(&mutex);
|
---|
120 | }
|
---|
121 |
|
---|
122 | void unlock() {
|
---|
123 | pthread_mutex_unlock(&mutex);
|
---|
124 | }
|
---|
125 |
|
---|
126 | void wait() {
|
---|
127 | pthread_cond_wait(&dataReady, &mutex);
|
---|
128 | }
|
---|
129 |
|
---|
130 | void notify();
|
---|
131 |
|
---|
132 |
|
---|
133 | friend class TOI;
|
---|
134 |
|
---|
135 | static void* ThreadStart(void *);
|
---|
136 | };
|
---|
137 |
|
---|
138 | #endif
|
---|