34 #include "SALOME_NamingService.hxx"
35 #include "SALOME_ModuleCatalog.hh"
36 #include "Basics_Utils.hxx"
44 #if defined WIN32 || defined __APPLE__
50 using namespace YACS::ENGINE;
58 static char doc[] =
"driver -- a SALOME YACS graph executor";
61 #if defined WIN32 || defined __APPLE__
65 {
"display",
'd',
"level", 0,
"Display dot files: 0=never to 3=very often (default 0)"},
66 {
"verbose",
'v', 0, 0,
"Produce verbose output" },
67 {
"stop-on-error",
's', 0, 0,
"Stop on first error" },
68 {
"dump-on-error",
'e',
"file", OPTION_ARG_OPTIONAL,
"Stop on first error and dump state"},
69 {
"dump-final",
'f',
"file", OPTION_ARG_OPTIONAL,
"dump final state"},
70 {
"dump",
'g',
"nbsec", OPTION_ARG_OPTIONAL,
"dump state"},
71 {
"load-state",
'l',
"file", 0,
"Load State from a previous partial execution"},
72 {
"save-xml-schema",
'x',
"file", OPTION_ARG_OPTIONAL,
"dump xml schema"},
73 {
"shutdown",
't',
"level", 0,
"Shutdown the schema: 0=no shutdown to 3=full shutdown (default 1)"},
74 {
"reset",
'r',
"level", 0,
"Reset the schema before execution: 0=nothing, 1=reset error nodes to ready state (default 0)"},
75 {
"kill-port",
'k',
"port", 0,
"Kill Salome application running on the specified port if the driver process is killed (with SIGINT or SIGTERM)"},
76 {
"init_port",
'i',
"value", OPTION_ARG_OPTIONAL,
"Initialisation value of a port, specified as bloc.node.port=value."},
116 static const char SYMBOLE_NAME_1[]=
"DefineCustomObservers";
117 static const char SYMBOLE_NAME_2[]=
"CleanUpObservers";
122 char *yacsDriverPluginPath(getenv(
"YACS_DRIVER_PLUGIN_PATH"));
123 if(!yacsDriverPluginPath)
125 void *handle(dlopen(yacsDriverPluginPath, RTLD_LAZY | RTLD_GLOBAL));
128 std::string message(dlerror());
129 std::ostringstream oss; oss <<
"Error during load of \"" << yacsDriverPluginPath <<
"\" defined by the YACS_DRIVER_PLUGIN_PATH env var : " << message;
135 std::ostringstream oss; oss <<
"Error during load of \"" << yacsDriverPluginPath <<
"\" ! Library has been correctly loaded but symbol " << SYMBOLE_NAME_1 <<
" does not exists !";
141 std::ostringstream oss; oss <<
"Error during load of \"" << yacsDriverPluginPath <<
"\" ! Library has been correctly loaded but symbol " << SYMBOLE_NAME_2 <<
" does not exists !";
160 #if defined WIN32 || defined __APPLE__
167 #if defined WIN32 || defined __APPLE__
182 myArgs->
reset = atoi(arg);
201 myArgs->
finalDump = (
char *)
"finalDumpState.xml";
205 myArgs->
dump = atoi(arg);
216 myArgs->
xmlSchema = (
char *)
"saveSchema.xml";
223 myArgs->
init_ports.push_back(std::string(arg));
227 if (state->arg_num >=1)
229 myArgs->
args[state->arg_num] = arg;
233 if (state->arg_num < 1)
238 return ARGP_ERR_UNKNOWN;
245 #if defined WIN32 || defined __APPLE__
252 #if defined WIN32 || defined __APPLE__
255 gettimeofday(&tv,NULL);
256 long t=tv.tv_sec*1000+tv.tv_usec/1000;
258 gettimeofday(&tv,NULL);
259 std::cerr << msg << tv.tv_sec*1000+tv.tv_usec/1000-t0 <<
" ms" << std::endl;
288 ostringstream command;
290 int status = system(command.str().c_str());
292 cerr <<
"Salome application on port " <<
myArgs.
killPort <<
" is killed" << endl;
294 cerr <<
"Error: Can't kill Salome application on port " <<
myArgs.
killPort << endl;
309 string cmd =
"touch " + st->
lockFile;
327 struct sigaction context, ocontext;
328 context.sa_handler = handler;
329 sigemptyset(&context.sa_mask);
330 context.sa_flags = 0;
331 if (sigaction(sig, &context, &ocontext) == -1)
333 return ocontext.sa_handler;
337 bool parse_init_port(
const std::string& input, std::string& node, std::string& port, std::string& value)
340 size_t pos_eq = input.find(
'=');
341 if(pos_eq == std::string::npos || pos_eq == input.size())
343 value = input.substr(pos_eq+1);
344 size_t pos_dot = input.rfind(
'.', pos_eq);
345 if(!pos_dot || pos_dot == std::string::npos || pos_dot >= pos_eq-1)
347 port = input.substr(pos_dot+1, pos_eq-pos_dot-1);
348 node = input.substr(0, pos_dot);
352 int main (
int argc,
char* argv[])
370 #if defined WIN32 || defined __APPLE__
372 argp_parse (&
argp, argc, argv, 0, 0, &
myArgs);
376 std::cerr <<
" stop-on-error=" <<
myArgs.
stop;
384 std::cerr << std::endl;
385 std::list<std::string>::const_iterator it;
388 std::cerr << (*it) << std::endl;
409 SALOME_NamingService namingService(orb);
410 CORBA::Object_var obj = namingService.Resolve(
"/Kernel/ModulCatalog");
411 SALOME_ModuleCatalog::ModuleCatalog_var aModuleCatalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj);
412 if (! CORBA::is_nil(aModuleCatalog))
414 CORBA::String_var anIOR = orb->object_to_string( aModuleCatalog );
420 catch(ServiceUnreachable& e)
430 timer(
"Elapsed time before load: ");
434 std::cerr <<
"The imported file is probably not a YACS schema file" << std::endl;
440 std::string node, port, value;
443 std::cerr <<
"Initialization node=" << node
445 <<
" value=" << value << std::endl;
447 std::string init_state;
449 if(value.compare(init_state))
451 std::cerr <<
"Error on initialization:" << init_state << std::endl;
457 std::cerr <<
"Error on parsing initialization string:" << (*it) << std::endl;
467 std::cerr <<
"The imported file has errors" << std::endl;
468 std::cerr << logger->
getStr() << std::endl;
476 std::cerr <<
"The schema is not valid and can not be executed" << std::endl;
477 std::cerr << report << std::endl;
487 timer(
"Elapsed time after load: ");
492 std::cerr <<
"The schema is not valid and can not be executed" << std::endl;
493 std::cerr << report << std::endl;
501 timer(
"Elapsed time after validation: ");
508 std::cerr <<
"The schema is not consistent and can not be executed" << std::endl;
517 timer(
"Elapsed time after check consistency: ");
552 std::ofstream
f(
"toto");
566 pthread_create(&th,NULL,&
dumpState,(
void*)st);
569 cerr <<
"+++++++++++++++++++ start calculation +++++++++++++++++++" << endl;
571 cerr <<
"+++++++++++++++++++ end calculation +++++++++++++++++++" << endl;
573 timer(
"Elapsed time after execution: ");
578 int return_value = 0;
583 std::cerr <<
"Execution has ended in error" << std::endl;
584 std::cerr << report << std::endl;
590 std::ofstream g(
"titi");
597 pthread_join(th,NULL);
623 cerr <<
"Caught a YACS exception" << endl;
624 cerr << e.
what() << endl;
632 catch (
const std::ios_base::failure&)
634 cerr <<
"Caught an io failure exception" << endl;
637 catch(CORBA::SystemException& ex)
639 cerr <<
"Caught a CORBA::SystemException.:" << __FILE__ <<
":" << __LINE__ <<
":" ;
642 CORBA::TypeCode_var tc = tmp.type();
643 const char *
p = tc->name();
651 catch(omniORB::fatalException& fe)
653 cerr <<
"Caught omniORB::fatalException:" << endl;
654 cerr <<
" file: " << fe.file() << endl;
655 cerr <<
" line: " << fe.line() << endl;
656 cerr <<
" mesg: " << fe.errmsg() << endl;
661 cerr <<
"Caught unknown exception." << endl;