00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "Object.hh"
00027 #include "ObjectClass.hh"
00028 #include "ObjectClassAttribute.hh"
00029 #include "ObjectClassSet.hh"
00030 #include "Interaction.hh"
00031 #include "InteractionSet.hh"
00032 #include "Dimension.hh"
00033 #include "RoutingSpace.hh"
00034 #include "PrettyDebug.hh"
00035
00036 #include "fed.hh"
00037
00038
00039 #include <iostream>
00040 #include <utility>
00041 #include <string>
00042 #include <list>
00043
00044 using std::cout ;
00045 using std::endl ;
00046 using std::pair ;
00047 using std::string ;
00048 using std::list ;
00049
00050 extern FILE *yyin ;
00051 int yyparse();
00052 void yyrestart(FILE*);
00053
00054 namespace certi {
00055 namespace fedparser {
00056
00057 extern std::string arg ;
00058 extern OrderType order ;
00059 extern TransportType transport ;
00060 extern int line_number ;
00061 static pdCDebug D("FEDPARSER", __FILE__);
00062
00063 static RootObject *root_object = 0 ;
00064 static bool verbose = false ;
00065 static int indentation = 0 ;
00066 const char *fed_filename ;
00067
00068
00069 static std::list<ObjectClass *> objects ;
00070
00071
00072 static std::list<Interaction *> interactions ;
00073 static string federate ;
00074 static ObjectClassAttribute *attribute ;
00075 static Parameter *parameter ;
00076 static RoutingSpace routing_space ;
00077
00078 static int objectHandle = 1 ;
00079 static int interactionHandle = 1 ;
00080 static int attributeHandle = 1 ;
00081 static int parameterHandle = 1 ;
00082 static int spaceHandle = 1 ;
00083 static int dimensionHandle = 1 ;
00084
00085
00086 int
00087 build(const char *filename, RootObject *root, bool verboseArg)
00088 {
00089 fed_filename = filename ;
00090 line_number = 1 ;
00091 verbose = verboseArg ;
00092 root_object = root ;
00093 FILE *file = fopen(filename, "r");
00094 if (file == NULL)
00095 return 1 ;
00096 yyin = file ;
00097 indentation = 0 ;
00098 objectHandle = 1 ;
00099 interactionHandle = 1 ;
00100 attributeHandle = 1 ;
00101 parameterHandle = 1 ;
00102 spaceHandle = 1 ;
00103 dimensionHandle = 1 ;
00104 objects.clear();
00105 interactions.clear();
00106 federate = "" ;
00107 attribute = 0 ;
00108 parameter = 0 ;
00109 #ifndef _WIN32
00110
00111 rewind(yyin);
00112 yyrestart(yyin);
00113 #endif
00114 int result = yyparse();
00115 fclose(file);
00116 return result ;
00117 }
00118
00119
00120 void
00121 indent()
00122 {
00123 if(verbose) {
00124 cout << endl ;
00125 for (int i = 0 ; i < indentation ; ++i) {
00126 cout << " " << " " << " " << " " ;
00127 }
00128 }
00129 }
00130
00131
00132 void
00133 startFed()
00134 {
00135 indent();
00136 if(verbose) {
00137 cout << "(FED";
00138 }
00139 ++indentation ;
00140 }
00141
00142
00143 void
00144 endFed()
00145 {
00146 --indentation ;
00147 if(verbose) {
00148 cout << ")" << endl << endl ;
00149 }
00150 }
00151
00152
00153 void
00154 addFederation()
00155 {
00156 indent();
00157 if(verbose) {
00158 cout << "(federation \"" << arg << "\")" ;
00159 }
00160 }
00161
00162
00163 void
00164 addFedVersion()
00165 {
00166 indent();
00167 if(verbose) {
00168 cout << "(FEDversion \"" << arg << "\")" ;
00169 }
00170 }
00171
00172
00173 void
00174 startSpaces()
00175 {
00176 indent();
00177 if(verbose) {
00178 cout << "(spaces" ;
00179 }
00180 ++indentation ;
00181 }
00182
00183
00184 void
00185 end()
00186 {
00187 --indentation ;
00188 if(verbose) {
00189 cout << ")" ;
00190 }
00191 }
00192
00193
00194 void
00195 startObjects()
00196 {
00197 indent();
00198 if(verbose) {
00199 cout << "(objects" ;
00200 }
00201 ++indentation ;
00202 }
00203
00204
00205 void
00206 startInteractions()
00207 {
00208 indent();
00209 if(verbose) {
00210 cout << "(interactions" ;
00211 }
00212 ++indentation ;
00213 }
00214
00215
00216 void
00217 startFederate()
00218 {
00219 federate = arg ;
00220 }
00221
00222
00223 void
00224 endFederate()
00225 {
00226 SecurityLevelID level = root_object->getSecurityLevelID(arg);
00227 root_object->registerFederate(federate, level);
00228 indent();
00229 if(verbose) {
00230 cout <<"(federate \"" << federate << "\" \""
00231 << arg << "\")" ;
00232 }
00233 }
00234
00235
00236 void
00237 startObject()
00238 {
00239 ObjectClass *parent = NULL;
00240
00241 ObjectClass *object = new ObjectClass(arg,objectHandle++);
00242
00243
00244
00245
00246 if (objects.size() > 0) {
00247 parent = objects.back();
00248 }
00249
00250
00251 objects.push_back(object);
00252
00253
00254 root_object->addObjectClass(object,parent);
00255
00256 indent();
00257 if(verbose) {
00258 cout << "(class \"" << arg << "\" (id "
00259 << object->getHandle() << ")" ;
00260 }
00261 ++indentation ;
00262 }
00263
00264
00265 void
00266 addObjectSecLevel(string name)
00267 {
00268 SecurityLevelID level = root_object->getSecurityLevelID(name);
00269 objects.back()->setSecurityLevelId(level);
00270 indent();
00271 if(verbose) {
00272 cout << "(sec_level \"" << name << "\")" ;
00273 }
00274 }
00275
00276
00277 void
00278 addAttribute()
00279 {
00280 attribute = new ObjectClassAttribute(arg,transport,order);
00281 objects.back()->addAttribute(attribute);
00282
00283 indent();
00284 if(verbose) {
00285 cout << "(attribute \"" << arg << "\" (id "
00286 << attribute->getHandle() << ")" ;
00287 }
00288 printTransport();
00289 printOrder();
00290 if(verbose) {
00291 cout << ")" ;
00292 }
00293 }
00294
00295
00296 void
00297 endObject()
00298 {
00299 if(verbose) {
00300 cout << ")" ;
00301 }
00302 objects.pop_back();
00303 if (objects.size() == 0) attributeHandle = 1 ;
00304 --indentation ;
00305 }
00306
00307
00308 void
00309 startInteraction()
00310 {
00311 Interaction *parent = NULL;
00312 Interaction *interaction = new Interaction(arg,interactionHandle++,transport,order);
00313
00314
00315 if (interactions.size() > 0) {
00316 parent = interactions.back();
00317 }
00318
00319 root_object->addInteractionClass(interaction,parent);
00320
00321
00322
00323 interactions.push_back(interaction);
00324
00325 indent();
00326 if(verbose)
00327 cout << "(interaction \"" << arg << "\" (id "
00328 << interaction->getHandle() << ")" ;
00329 printTransport();
00330 printOrder();
00331 ++indentation ;
00332 }
00333
00334
00335 void
00336 addInteractionSecurityLevel()
00337 {
00338 SecurityLevelID level = root_object->getSecurityLevelID(arg);
00339 interactions.back()->setSecurityLevelId(level);
00340 indent();
00341 if(verbose)
00342 cout << "(sec_level \"" << arg << "\")" ;
00343 }
00344
00345
00346 void
00347 addObjectSecurityLevel()
00348 {
00349 SecurityLevelID level = root_object->getSecurityLevelID(arg);
00350 objects.back()->setSecurityLevelId(level);
00351 indent();
00352 if(verbose) {
00353 cout << "(sec_level \"" << arg << "\")" ;
00354 }
00355 }
00356
00357
00358 void
00359 addParameter()
00360 {
00361 parameter = new Parameter();
00362 parameter->setHandle(parameterHandle++);
00363 parameter->setName(arg);
00364 interactions.back()->addParameter(parameter);
00365
00366 indent();
00367 if(verbose) {
00368 cout << "(parameter \"" << arg << "\" (id "
00369 << parameter->getHandle() << "))" << std::flush;
00370 }
00371 }
00372
00373
00374 void
00375 endInteraction()
00376 {
00377 if(verbose) {
00378 cout << ")" ;
00379 }
00380 interactions.pop_back();
00381 if (interactions.size() == 0) parameterHandle = 1 ;
00382 --indentation ;
00383 }
00384
00385
00386 void
00387 printOrder()
00388 {
00389 switch (order) {
00390 case RECEIVE: if(verbose)
00391 cout << " receive" ; break ;
00392 case TIMESTAMP: if(verbose)
00393 cout << " timestamp" ; break ;
00394 }
00395 }
00396
00397
00398 void
00399 printTransport()
00400 {
00401 switch (transport) {
00402 case RELIABLE: if(verbose)
00403 cout << " reliable" ; break ;
00404 case BEST_EFFORT: if(verbose)
00405 cout << " best_effort" ; break ;
00406 }
00407 }
00408
00409
00410 void
00411 startSpace()
00412 {
00413 routing_space = RoutingSpace();
00414 routing_space.setHandle(spaceHandle++);
00415 routing_space.setName(arg);
00416 dimensionHandle = 1 ;
00417
00418 indent();
00419 if(verbose) {
00420 cout << "(space \"" << arg << "\" (id "
00421 << routing_space.getHandle() << ")" ;
00422 }
00423 ++indentation ;
00424 }
00425
00426
00427 void
00428 endSpace()
00429 {
00430 root_object->addRoutingSpace(routing_space);
00431
00432 --indentation ;
00433 if(verbose) {
00434 cout << ")" ;
00435 }
00436 }
00437
00438
00439 void
00440 addDimension()
00441 {
00442 Dimension dimension(dimensionHandle++);
00443 dimension.setName(arg);
00444 routing_space.addDimension(dimension);
00445
00446 indent();
00447 if(verbose) {
00448 cout << "(dimension \"" << arg << "\" (id "
00449 << dimension.getHandle() << "))" ;
00450 }
00451 }
00452
00453 }}
00454
00455