2 #include "yacsconfig.h"
3 #include "RuntimeSALOME.hxx"
6 #include "Exception.hxx"
7 #include "Executor.hxx"
9 #include "VisitorSaveState.hxx"
10 #include "VisitorSaveSalomeSchema.hxx"
11 #include "LoadState.hxx"
12 #include "Dispatcher.hxx"
13 #include "LinkInfo.hxx"
16 #include "SALOME_NamingService.hxx"
17 #include "SALOME_ModuleCatalog.hh"
24 using YACS::YACSLoader;
25 using namespace YACS::ENGINE;
29 // --- use of glibc argp interface for parsing unix-style arguments
31 const char *argp_program_version ="driver V0.1";
32 const char *argp_program_bug_address ="<nepal@nepal.edf.fr>";
33 static char doc[] ="driver -- a SALOME YACS graph executor";
34 static char args_doc[] = "graph.xml";
36 static struct argp_option options[] =
38 {"display", 'd', "level", 0, "Display dot files: 0=never to 3=very often"},
39 {"verbose", 'v', 0, 0, "Produce verbose output" },
40 {"stop-on-error", 's', 0, 0, "Stop on first error" },
41 {"dump-on-error", 'e', "file", OPTION_ARG_OPTIONAL, "Stop on first error and dump state"},
42 {"dump-final", 'f', "file", OPTION_ARG_OPTIONAL, "dump final state"},
43 {"load-state", 'l', "file", 0, "Load State from a previous partial execution"},
44 {"save-xml-schema", 'x', "file", OPTION_ARG_OPTIONAL, "dump xml schema"},
61 parse_opt (int key, char *arg, struct argp_state *state)
63 // Get the input argument from argp_parse, which we
64 // know is a pointer to our arguments structure.
65 struct arguments *myArgs = (arguments*)state->input;
70 myArgs->display = atoi(arg);
81 myArgs->dumpErrorFile = arg;
83 myArgs->dumpErrorFile = "dumpErrorState.xml";
87 myArgs->finalDump = arg;
89 myArgs->finalDump = "finalDumpState.xml";
92 myArgs->loadState = arg;
96 myArgs->xmlSchema = arg;
98 myArgs->xmlSchema = "saveSchema.xml";
102 if (state->arg_num >=1) // Too many arguments.
104 myArgs->args[state->arg_num] = arg;
108 if (state->arg_num < 1) // Not enough arguments.
113 return ARGP_ERR_UNKNOWN;
119 static struct argp argp = { options, parse_opt, args_doc, doc };
122 main (int argc, char* argv[])
124 struct arguments myArgs;
130 myArgs.dumpErrorFile= "";
131 myArgs.finalDump = "";
132 myArgs.loadState = "";
133 myArgs.xmlSchema = "";
135 // Parse our arguments; every option seen by parse_opt will be reflected in arguments.
136 argp_parse (&argp, argc, argv, 0, 0, &myArgs);
137 cerr << "graph = " << myArgs.args[0]
138 << " options: display=" << myArgs.display
139 << " verbose="<<myArgs.verbose
140 << " stop-on-error=" << myArgs.stop;
142 cerr << " dumpErrorFile=" << myArgs.dumpErrorFile << endl;
146 RuntimeSALOME::setRuntime();
148 // Try to load the session catalog if it exists
151 YACS::ENGINE::RuntimeSALOME* runTime = YACS::ENGINE::getSALOMERuntime();
152 CORBA::ORB_ptr orb = runTime->getOrb();
155 SALOME_NamingService namingService(orb);
156 CORBA::Object_var obj = namingService.Resolve("/Kernel/ModulCatalog");
157 SALOME_ModuleCatalog::ModuleCatalog_var aModuleCatalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj);
158 if (! CORBA::is_nil(aModuleCatalog))
160 CORBA::String_var anIOR = orb->object_to_string( aModuleCatalog );
161 YACS::ENGINE::Catalog* aCatalog = runTime->loadCatalog( "session", anIOR.in() );
162 runTime->addCatalog(aCatalog);
166 catch(ServiceUnreachable& e)
168 //Naming service unreachable don't add catalog
176 Proc* p=loader.load(myArgs.args[0]);
179 std::cerr << "The imported file is probably not a YACS schema file" << std::endl;
182 //Get the parser logger
183 Logger* logger=p->getLogger("parser");
184 //Print errors logged if any
185 if(!logger->isEmpty())
187 std::cerr << "The imported file has errors" << std::endl;
188 std::cerr << logger->getStr() << std::endl;
190 //Don't execute if there are errors
191 if(logger->hasErrors())
194 Runtime* r=YACS::ENGINE::getRuntime();
195 Dispatcher* disp=Dispatcher::getDispatcher();
204 std::string report=p->getErrorReport();
205 std::cerr << "The schema is not valid and can not be executed" << std::endl;
206 std::cerr << report << std::endl;
207 Runtime* r=YACS::ENGINE::getRuntime();
208 Dispatcher* disp=Dispatcher::getDispatcher();
216 LinkInfo info(LinkInfo::ALL_DONT_STOP);
217 p->checkConsistency(info);
218 if(info.areWarningsOrErrors())
220 std::cerr << "The schema is not consistent and can not be executed" << std::endl;
221 std::cerr << info.getGlobalRepr() << std::endl;
222 Runtime* r=YACS::ENGINE::getRuntime();
223 Dispatcher* disp=Dispatcher::getDispatcher();
231 bool isXmlSchema = (strlen(myArgs.xmlSchema) != 0);
234 YACS::ENGINE::VisitorSaveSalomeSchema vss(p);
235 vss.openFileSchema(myArgs.xmlSchema);
237 vss.closeFileSchema();
240 bool fromScratch = (strlen(myArgs.loadState) == 0);
245 stateParser* rootParser = new stateParser();
246 stateLoader myStateLoader(rootParser, p);
247 myStateLoader.parse(myArgs.loadState);
251 if (strlen(myArgs.dumpErrorFile) >0)
252 executor.setStopOnError(true, myArgs.dumpErrorFile);
254 executor.setStopOnError(false, myArgs.dumpErrorFile);
256 std::ofstream f("toto");
260 cerr << "+++++++++++++++++++ start calculation +++++++++++++++++++" << endl;
261 executor.RunW(p,myArgs.display, fromScratch);
262 cerr << "+++++++++++++++++++ end calculation +++++++++++++++++++" << endl;
263 cerr << "Proc state : " << p->getEffectiveState() << endl;
265 if(p->getEffectiveState() != YACS::DONE)
267 std::string report=p->getErrorReport();
268 std::cerr << "Execution has ended in error" << std::endl;
269 std::cerr << report << std::endl;
272 std::ofstream g("titi");
276 bool isFinalDump = (strlen(myArgs.finalDump) != 0);
279 YACS::ENGINE::VisitorSaveState vst(p);
280 vst.openFileDump(myArgs.finalDump);
285 Runtime* r=YACS::ENGINE::getRuntime();
286 Dispatcher* disp=Dispatcher::getDispatcher();
292 catch (YACS::Exception& e)
294 cerr << "Caught a YACS exception" << endl;
295 cerr << e.what() << endl;
296 Runtime* r=YACS::ENGINE::getRuntime();
297 Dispatcher* disp=Dispatcher::getDispatcher();
303 catch (const std::ios_base::failure&)
305 cerr << "Caught an io failure exception" << endl;
308 catch(CORBA::SystemException& ex)
310 cerr << "Caught a CORBA::SystemException." ;
313 CORBA::TypeCode_var tc = tmp.type();
314 const char *p = tc->name();
322 catch(omniORB::fatalException& fe)
324 cerr << "Caught omniORB::fatalException:" << endl;
325 cerr << " file: " << fe.file() << endl;
326 cerr << " line: " << fe.line() << endl;
327 cerr << " mesg: " << fe.errmsg() << endl;
332 cerr << "Caught unknown exception." << endl;