source: Sophya/trunk/ArchTOIPipe/TestPipes/mainxmlpipe.cc@ 2220

Last change on this file since 2220 was 2220, checked in by aubourg, 23 years ago

vf_231002

File size: 10.2 KB
Line 
1
2// main genere automatiquement par xsl
3// ne pas modifier
4// derniere mise a jour : VF le 22/10/2002
5
6// inclusions expat
7#include <stdio.h>
8#include "expat.h"
9
10// inclusions c++
11#include <string>
12#include "config.h"
13#include <map>
14using namespace std;
15#include <iostream.h>
16#include "toi.h"
17#include "toiprocessor.h"
18#include "toimanager.h"
19#include "toisegment.h"
20#include "sophyainit.h"
21#include <stdexcept>
22
23#ifndef MAXINT
24#define MAXINT 2147483647
25#endif
26
27#include "smoothtoi.h"
28#include "demopipe.h"
29#include "fitstoirdr.h"
30#include "fitstoiwtr.h"
31
32// classe de gestion des balises en design patern object call-back
33class ToiPipe
34{
35public:
36 ToiPipe(void);
37 virtual ~ToiPipe();
38 static void startElement(void *userData, const char *name, const char **atts);
39 static void endElement(void *userData, const char *name);
40private:
41 // pour concordances instances - nom
42 map<string,TOIProcessor*> toiProc;
43 string id;
44 // gestionnaire de TOI
45 TOIManager* mgr;
46 void startElementC(const char *name, const char **atts);
47 void endElementC(const char *name);
48};
49
50
51
52ToiPipe::ToiPipe()
53{
54 // Ouverture du gestionnaire de TOI.
55 mgr = TOIManager::getManager();
56 // initialisation du processeur courant
57 id="";
58
59}
60
61ToiPipe::~ToiPipe()
62{
63
64}
65
66void ToiPipe::startElement(void *userData, const char *name, const char **atts)
67{
68 ToiPipe *toiPipe = (ToiPipe*) userData;
69 toiPipe->startElementC(name, atts);
70}
71
72void ToiPipe::endElement(void *userData, const char *name)
73{
74 ToiPipe* toiPipe = (ToiPipe*) userData;
75 toiPipe->endElementC(name);
76}
77
78
79void ToiPipe::startElementC(const char *name, const char **atts)
80{
81 int i;
82 //puts(name);
83
84 // filtrage des balises
85 if ((string)name == "connect") {
86 // mise en ordre des arguments
87 string nom;
88 TOIProcessor* procin=NULL;
89 TOIProcessor* procout=NULL;
90 string input;
91 string output;
92 int taille = 1024;
93 bool writeflag = false;
94 for (i=0; atts[i]; i+=2) {
95 if ((string)atts[i] == "name") {
96 nom=atts[i+1];
97 }
98 if ((string)atts[i] == "procin") {
99 map<string,TOIProcessor*>::iterator j=toiProc.find(atts[i+1]);
100 if (j != toiProc.end()) {
101 procin = (*j).second;
102 } else {
103 throw ParmError("Connect error: processor in not found");
104 }
105 }
106 if ((string)atts[i] == "procout") {
107 map<string,TOIProcessor*>::iterator j=toiProc.find(atts[i+1]);
108 if (j != toiProc.end()) {
109 procout = (*j).second;
110 } else {
111 throw ParmError("Connect error: processor out not found");
112 }
113 }
114 if ((string)atts[i] == "input") {
115 input = atts[i+1];
116 }
117 if ((string)atts[i] == "output") {
118 output = atts[i+1];
119 }
120 }
121 // connection automatique des toiprocesseurs
122 if (procin != NULL && procout != NULL ) {
123 cout << "connect " << output << " " << input << endl;
124 mgr->connect(*procout, output, *procin, input, nom, taille, writeflag);
125 cout << "connect done" << endl;
126 }
127
128 } else if ((string)name == "constraint") { // si balise de contrainte
129 TOIProcessor* proc=NULL;
130 int min=0;
131 int max=MAXINT;
132 for (i=0; atts[i]; i+=2) {
133 if ((string)atts[i] =="proc") {
134 map<string,TOIProcessor*>::iterator j=toiProc.find(atts[i+1]);
135 if (j != toiProc.end()) {
136 proc = (*j).second;
137 } else {
138 throw ParmError("Constraint error: processor not found");
139 }
140 }
141 if ((string)atts[i] == "min") {
142 min = atoi(atts[i+1]);
143 }
144 if ((string)atts[i] == "max") {
145 max = atoi(atts[i+1]);
146 }
147 }
148 cout << "setting " << proc << " " << min << " " << max << endl;
149 proc->setRequestedSample(min, max);
150 cout << "constraint done" << endl;
151
152 } else if ((string)name == "start") { // si balise de demarrage
153 cout << "***** Starting execution *****" << endl;
154 mgr->startAll();
155 // Gestion de la re-connection des threads
156 cout<<"***** Joining threads *****"<<endl;
157 mgr->joinAll();
158 cout<<"***** End threads *****"<<endl;
159 // destruction du toimanager et des processeurs a implementer dans toimanager pour l'utilisation de plusieurs start
160 //TOIManager::~toimanager();
161 //toiProc.clear();
162
163 } else if (id == "") { // si nouveau processeur
164
165 if ((string)name == "smooth") {
166 uint_4 lsm;
167 uint_4 deg;
168
169
170 // gestion des arguments du constructeur
171 for (i=0; atts[i]; i+=2) {
172 // var pour instanciation
173 if ((string)atts[i] == "id") {
174 id=atts[i+1];
175 }
176
177 //initialisation des arguments par defaut si existants
178
179
180 // mise a jour des arguments
181
182 if ((string)atts[i] == "lsm") {
183 lsm = atoi(atts[i+1]);
184
185 }
186
187 if ((string)atts[i] == "deg") {
188 deg = atoi(atts[i+1]);
189
190 }
191
192 }
193
194 // creation du toiprocesseur
195 toiProc[id] = new DataSmooth (lsm, deg);
196 }
197
198 if ((string)name == "demopipe") {
199
200
201 // gestion des arguments du constructeur
202 for (i=0; atts[i]; i+=2) {
203 // var pour instanciation
204 if ((string)atts[i] == "id") {
205 id=atts[i+1];
206 }
207
208 //initialisation des arguments par defaut si existants
209
210
211 // mise a jour des arguments
212
213 }
214
215 // creation du toiprocesseur
216 toiProc[id] = new DemoPipe ();
217 }
218
219 if ((string)name == "fitsreader") {
220 string fn;
221
222
223 // gestion des arguments du constructeur
224 for (i=0; atts[i]; i+=2) {
225 // var pour instanciation
226 if ((string)atts[i] == "id") {
227 id=atts[i+1];
228 }
229
230 //initialisation des arguments par defaut si existants
231 fn = "test.fits";
232
233
234 // mise a jour des arguments
235
236 if ((string)atts[i] == "fn") {
237 fn = atts[i+1];
238
239 }
240
241 }
242
243 // creation du toiprocesseur
244 toiProc[id] = new FITSTOIReader (fn);
245 }
246
247 if ((string)name == "fitswriter") {
248 string fn;
249
250
251 // gestion des arguments du constructeur
252 for (i=0; atts[i]; i+=2) {
253 // var pour instanciation
254 if ((string)atts[i] == "id") {
255 id=atts[i+1];
256 }
257
258 //initialisation des arguments par defaut si existants
259
260
261 // mise a jour des arguments
262
263 if ((string)atts[i] == "fn") {
264 fn = atts[i+1];
265
266 }
267
268 }
269
270 // creation du toiprocesseur
271 toiProc[id] = new FITSTOIWriter (fn);
272 }
273
274
275 } else { // sinon c une methode
276 // gestion des methodes
277
278 if (id == "smooth") {
279
280 if ((string)name == "DoNotLookAt") {
281 uint_8 flag;
282
283
284 // gestion des arguments de la methode
285 for (i=0; atts[i]; i+=2) {
286 //initialisation des arguments par defaut si existants
287 flag = FlgToiAll;
288
289
290 // mise a jour des arguments
291
292 if ((string)atts[i] == "flag") {
293 flag = atoi(atts[i+1]);
294
295 }
296
297 }
298
299 // appelle de la methode du processeur concerne
300 ((DataSmooth*)toiProc[id])->DoNotLookAt (flag);
301 }
302
303 if ((string)name == "SetFlagFailed") {
304 uint_8 flag;
305
306
307 // gestion des arguments de la methode
308 for (i=0; atts[i]; i+=2) {
309 //initialisation des arguments par defaut si existants
310 flag = FlgToiInterp;
311
312
313 // mise a jour des arguments
314
315 if ((string)atts[i] == "flag") {
316 flag = atoi(atts[i+1]);
317
318 }
319
320 }
321
322 // appelle de la methode du processeur concerne
323 ((DataSmooth*)toiProc[id])->SetFlagFailed (flag);
324 }
325
326 if ((string)name == "SetBuff") {
327 uint_4 bupd;
328
329
330 // gestion des arguments de la methode
331 for (i=0; atts[i]; i+=2) {
332 //initialisation des arguments par defaut si existants
333 bupd = 100;
334
335
336 // mise a jour des arguments
337
338 if ((string)atts[i] == "bupd") {
339 bupd = atoi(atts[i+1]);
340
341 }
342
343 }
344
345 // appelle de la methode du processeur concerne
346 ((DataSmooth*)toiProc[id])->SetBuffUpd (bupd);
347 }
348
349 if ((string)name == "MinSmoothLength") {
350 uint_4 lsmin;
351
352
353 // gestion des arguments de la methode
354 for (i=0; atts[i]; i+=2) {
355 //initialisation des arguments par defaut si existants
356 lsmin = 0;
357
358
359 // mise a jour des arguments
360
361 if ((string)atts[i] == "lsmin") {
362 lsmin = atoi(atts[i+1]);
363
364 }
365
366 }
367
368 // appelle de la methode du processeur concerne
369 ((DataSmooth*)toiProc[id])->MinSmoothLength (lsmin);
370 }
371
372 }
373
374 if (id == "demopipe") {
375
376 }
377
378 if (id == "fitsreader") {
379
380 }
381
382 if (id == "fitswriter") {
383
384 }
385
386
387 }
388
389}
390
391
392void ToiPipe::endElementC(const char *name)
393{
394 // verification si une balise processeur est fermee pour la gestion des methodes d'initialisation
395
396 if ((string)name == "smooth") {
397 id="";
398 }
399
400 if ((string)name == "demopipe") {
401 id="";
402 }
403
404 if ((string)name == "fitsreader") {
405 id="";
406 }
407
408 if ((string)name == "fitswriter") {
409 id="";
410 }
411
412
413 // execution du pipeline
414 if ((string)name == "toipipe") {
415 cout << "***** Starting execution *****" << endl;
416 mgr->startAll();
417 // Gestion de la re-connection des threads
418 cout<<"***** Joining threads *****"<<endl;
419 mgr->joinAll();
420 cout<<"***** End threads *****"<<endl;
421 }
422}
423
424
425int main(int argc, char *argv[])
426{
427 char buf[BUFSIZ];
428 XML_Parser parser = XML_ParserCreate(NULL);
429 int done;
430 FILE* fich=fopen(argv[1],"r");
431
432 ToiPipe* toiPipe = new ToiPipe();
433
434 // Initialisation de Sophya
435 SophyaInit();
436 cout << "-- Application start --" << endl;
437 XML_SetUserData(parser, toiPipe);
438 XML_SetElementHandler(parser, ToiPipe::startElement, ToiPipe::endElement);
439 if (fich != NULL) {
440 cout << "-- Reading file --" << endl;
441 // traitement des balises
442 do {
443 try {
444 size_t len = fread(buf, 1, sizeof(buf), fich);
445 done = len < sizeof(buf);
446 if (!XML_Parse(parser, buf, len, done)) {
447 fprintf(stderr,
448 "%s at line %d\n",
449 XML_ErrorString(XML_GetErrorCode(parser)),
450 XML_GetCurrentLineNumber(parser));
451 return 1;
452 }
453 } catch (PThrowable & exc) { // Sophya exceptions
454 cout << "\ntstdemopipe: Catched Exception \n" << (string)typeid(exc).name()
455 << " - Msg= " << exc.Msg() << endl;
456 } catch (const std::exception & sex) { // Standard exceptions
457 cout << "\ntstdemopipe: Catched std::exception \n"
458 << (string)typeid(sex).name() << endl;
459 } catch (...) { // Other exceptions
460 cout << "\ntstdemopipe: some other exception was caught ! " << endl;
461 }
462 } while (!done);
463 XML_ParserFree(parser);
464 fclose(fich);
465 } else {
466 fprintf(stderr,"file not found");
467 return 1;
468 }
469 return(0);
470}
471
Note: See TracBrowser for help on using the repository browser.