2 #include "RuntimeSALOME.hxx"
4 #include "Exception.hxx"
5 #include "Executor.hxx"
7 #include "VisitorSaveState.hxx"
8 #include "VisitorSaveSchema.hxx"
9 #include "LoadState.hxx"
10 #include "Dispatcher.hxx"
16 using YACS::YACSLoader;
17 using namespace YACS::ENGINE;
21 // --- use of glibc argp interface for parsing unix-style arguments
23 const char *argp_program_version ="driver V0.1";
24 const char *argp_program_bug_address ="<nepal@nepal.edf.fr>";
25 static char doc[] ="driver -- a SALOME YACS graph executor";
26 static char args_doc[] = "graph.xml";
28 static struct argp_option options[] =
30 {"display", 'd', "level", 0, "Display dot files: 0=never to 3=very often"},
31 {"verbose", 'v', 0, 0, "Produce verbose output" },
32 {"stop-on-error", 's', 0, 0, "Stop on first error" },
33 {"dump-on-error", 'e', "file", OPTION_ARG_OPTIONAL, "Stop on first error and dump state"},
34 {"dump-final", 'f', "file", OPTION_ARG_OPTIONAL, "dump final state"},
35 {"load-state", 'l', "file", 0, "Load State from a previous partial execution"},
36 {"save-xml-schema", 'x', "file", OPTION_ARG_OPTIONAL, "dump xml schema"},
53 parse_opt (int key, char *arg, struct argp_state *state)
55 // Get the input argument from argp_parse, which we
56 // know is a pointer to our arguments structure.
57 struct arguments *myArgs = (arguments*)state->input;
62 myArgs->display = atoi(arg);
73 myArgs->dumpErrorFile = arg;
75 myArgs->dumpErrorFile = "dumpErrorState.xml";
79 myArgs->finalDump = arg;
81 myArgs->finalDump = "finalDumpState.xml";
84 myArgs->loadState = arg;
88 myArgs->xmlSchema = arg;
90 myArgs->xmlSchema = "saveSchema.xml";
94 if (state->arg_num >=1) // Too many arguments.
96 myArgs->args[state->arg_num] = arg;
100 if (state->arg_num < 1) // Not enough arguments.
105 return ARGP_ERR_UNKNOWN;
111 static struct argp argp = { options, parse_opt, args_doc, doc };
114 main (int argc, char* argv[])
116 struct arguments myArgs;
122 myArgs.dumpErrorFile= "";
123 myArgs.finalDump = "";
124 myArgs.loadState = "";
125 myArgs.xmlSchema = "";
127 // Parse our arguments; every option seen by parse_opt will be reflected in arguments.
128 argp_parse (&argp, argc, argv, 0, 0, &myArgs);
129 cerr << "graph = " << myArgs.args[0]
130 << " options: display=" << myArgs.display
131 << " verbose="<<myArgs.verbose
132 << " stop-on-error=" << myArgs.stop;
134 cerr << " dumpErrorFile=" << myArgs.dumpErrorFile << endl;
138 RuntimeSALOME::setRuntime();
145 Proc* p=loader.load(myArgs.args[0]);
147 bool isXmlSchema = (strlen(myArgs.xmlSchema) != 0);
150 YACS::ENGINE::VisitorSaveSchema vss(p);
151 vss.openFileSchema(myArgs.xmlSchema);
153 vss.closeFileSchema();
156 bool fromScratch = (strlen(myArgs.loadState) == 0);
161 stateParser* rootParser = new stateParser();
162 stateLoader myStateLoader(rootParser, p);
163 myStateLoader.parse(myArgs.loadState);
167 if (strlen(myArgs.dumpErrorFile) >0)
168 executor.setStopOnError(true, myArgs.dumpErrorFile);
170 executor.setStopOnError(false, myArgs.dumpErrorFile);
172 std::ofstream f("toto");
176 cerr << "+++++++++++++++++++ start calculation +++++++++++++++++++" << endl;
177 executor.RunW(p,myArgs.display, fromScratch);
178 cerr << "+++++++++++++++++++ end calculation +++++++++++++++++++" << endl;
179 cerr << "Proc state : " << p->getEffectiveState() << endl;
181 std::ofstream g("titi");
185 bool isFinalDump = (strlen(myArgs.finalDump) != 0);
188 YACS::ENGINE::VisitorSaveState vst(p);
189 vst.openFileDump(myArgs.finalDump);
194 Runtime* r=YACS::ENGINE::getRuntime();
195 Dispatcher* disp=Dispatcher::getDispatcher();
201 catch (YACS::Exception& e)
203 cerr << "Caught a YACS exception" << endl;
204 cerr << e.what() << endl;
205 Runtime* r=YACS::ENGINE::getRuntime();
206 Dispatcher* disp=Dispatcher::getDispatcher();
212 catch (const std::ios_base::failure&)
214 cerr << "Caught an io failure exception" << endl;
217 catch(CORBA::SystemException& ex)
219 cerr << "Caught a CORBA::SystemException." ;
222 CORBA::TypeCode_var tc = tmp.type();
223 const char *p = tc->name();
231 catch(omniORB::fatalException& fe)
233 cerr << "Caught omniORB::fatalException:" << endl;
234 cerr << " file: " << fe.file() << endl;
235 cerr << " line: " << fe.line() << endl;
236 cerr << " mesg: " << fe.errmsg() << endl;
241 cerr << "Caught unknown exception." << endl;