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