35 #include "KernelBasis.hxx"
36 #include "SALOME_Launcher.hxx"
37 #include "ServiceUnreachable.hxx"
39 #include "SALOME_NamingService.hxx"
40 #include "SALOME_ModuleCatalog.hh"
41 #include "SALOMESDS_DataServerManager.hxx"
42 #include "Basics_Utils.hxx"
49 #if defined WIN32 || defined __APPLE__
63 static char doc[] =
"driver -- a SALOME YACS graph executor";
66 #if defined WIN32 || defined __APPLE__
68 static struct argp_option
options[] =
70 {
"display",
'd',
"level", 0,
"Display dot files: 0=never to 3=very often (default 0)"},
71 {
"verbose",
'v', 0, 0,
"Produce verbose output" },
72 {
"stop-on-error",
's', 0, 0,
"Stop on first error" },
73 {
"dump-on-error",
'e',
"file", OPTION_ARG_OPTIONAL,
"Stop on first error and dump state"},
74 {
"dump-final",
'f',
"file", OPTION_ARG_OPTIONAL,
"dump final state"},
75 {
"dump",
'g',
"nbsec", OPTION_ARG_OPTIONAL,
"dump state"},
76 {
"load-state",
'l',
"file", 0,
"Load State from a previous partial execution"},
77 {
"save-xml-schema",
'x',
"file", OPTION_ARG_OPTIONAL,
"dump xml schema"},
78 {
"shutdown",
't',
"level", 0,
"Shutdown the schema: 0=no shutdown to 3=full shutdown (default 1)"},
79 {
"reset",
'r',
"level", 0,
"Reset the schema before execution: 0=nothing, 1=reset error nodes to ready state (default 0)"},
80 {
"kill-port",
'k',
"port", 0,
"Kill Salome application running on the specified port if the driver process is killed (with SIGINT or SIGTERM)"},
81 {
"init_port",
'i',
"value", OPTION_ARG_OPTIONAL,
"Initialisation value of a port, specified as bloc.node.port=value."},
82 {
"donotsqueeze",
'z',
"value", 0,
"Desactivate squeeze memory optimization."},
101 bool squeezeMemory =
true;
111 #if defined WIN32 || defined __APPLE__
118 #if defined WIN32 || defined __APPLE__
180 if (
state->arg_num >=1)
186 if (
state->arg_num < 1)
191 return ARGP_ERR_UNKNOWN;
198 #if defined WIN32 || defined __APPLE__
205 #if defined WIN32 || defined __APPLE__
208 gettimeofday(&
tv,NULL);
209 long t=
tv.tv_sec*1000+
tv.tv_usec/1000;
211 gettimeofday(&
tv,NULL);
212 std::cerr << msg <<
tv.tv_sec*1000+
tv.tv_usec/1000-t0 <<
" ms" << std::endl;
241 ostringstream command;
243 int status = system(command.str().c_str());
245 cerr <<
"Salome application on port " <<
myArgs.
killPort <<
" is killed" << endl;
247 cerr <<
"Error: Can't kill Salome application on port " <<
myArgs.
killPort << endl;
262 string cmd =
"touch " + st->
lockFile;
280 struct sigaction context, ocontext;
281 context.sa_handler = handler;
282 sigemptyset(&context.sa_mask);
283 context.sa_flags = 0;
284 if (sigaction(sig, &context, &ocontext) == -1)
286 return ocontext.sa_handler;
290 bool parse_init_port(
const std::string& input, std::string& node, std::string& port, std::string& value)
293 size_t pos_eq = input.find(
'=');
294 if(pos_eq == std::string::npos || pos_eq == input.size())
296 value = input.substr(pos_eq+1);
297 size_t pos_dot = input.rfind(
'.', pos_eq);
298 if(!pos_dot || pos_dot == std::string::npos || pos_dot >= pos_eq-1)
300 port = input.substr(pos_dot+1, pos_eq-pos_dot-1);
301 node = input.substr(0, pos_dot);
308 KERNEL::getLauncherSA();
322 CORBA::Object_var objDSM(namingService.
Resolve(SALOMESDS::DataServerManager::NAME_IN_NS));
323 SALOME::DataServerManager_var dsm(SALOME::DataServerManager::_narrow(objDSM));
324 if ( !CORBA::is_nil(dsm) )
325 dsm->shutdownScopes();
328 catch(
const CORBA::Exception& )
332 catch(ServiceUnreachable& e)
338 int main (
int argc,
char* argv[])
341 #if defined WIN32 || defined __APPLE__
343 argp_parse (&
argp, argc, argv, 0, 0, &
myArgs);
347 std::cerr <<
" stop-on-error=" <<
myArgs.
stop;
355 std::cerr << std::endl;
356 std::list<std::string>::const_iterator it;
359 std::cerr << (*it) << std::endl;
384 CORBA::Object_var obj = namingService.
Resolve(
"/Kernel/ModulCatalog");
385 SALOME_ModuleCatalog::ModuleCatalog_var aModuleCatalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj);
386 if (! CORBA::is_nil(aModuleCatalog))
388 CORBA::String_var anIOR =
orb->object_to_string( aModuleCatalog );
394 catch(ServiceUnreachable& e)
404 timer(
"Elapsed time before load: ");
408 std::cerr <<
"The imported file is probably not a YACS schema file" << std::endl;
414 for(
auto node : allNodes)
426 std::string node, port, value;
429 std::cerr <<
"Initialization node=" << node
431 <<
" value=" << value << std::endl;
433 std::string init_state;
435 if(value.compare(init_state))
437 std::cerr <<
"Error on initialization:" << init_state << std::endl;
443 std::cerr <<
"Error on parsing initialization string:" << (*it) << std::endl;
453 std::cerr <<
"The imported file has errors" << std::endl;
454 std::cerr << logger->
getStr() << std::endl;
462 std::cerr <<
"The schema is not valid and can not be executed" << std::endl;
463 std::cerr << report << std::endl;
473 timer(
"Elapsed time after load: ");
478 std::cerr <<
"The schema is not valid and can not be executed" << std::endl;
479 std::cerr << report << std::endl;
487 timer(
"Elapsed time after validation: ");
494 std::cerr <<
"The schema is not consistent and can not be executed" << std::endl;
503 timer(
"Elapsed time after check consistency: ");
539 std::ofstream
f(
"toto");
553 pthread_create(&th,NULL,&
dumpState,(
void*)st);
556 cerr <<
"+++++++++++++++++++ start calculation +++++++++++++++++++" << endl;
558 cerr <<
"+++++++++++++++++++ end calculation +++++++++++++++++++" << endl;
560 timer(
"Elapsed time after execution: ");
565 int return_value = 0;
570 std::cerr <<
"Execution has ended in error" << std::endl;
571 std::cerr << report << std::endl;
577 std::ofstream g(
"titi");
584 pthread_join(th,NULL);
611 cerr <<
"Caught a YACS exception" << endl;
612 cerr << e.what() << endl;
620 catch (
const std::ios_base::failure&)
622 cerr <<
"Caught an io failure exception" << endl;
625 catch(CORBA::SystemException&
ex)
627 cerr <<
"Caught a CORBA::SystemException.:" << __FILE__ <<
":" << __LINE__ <<
":" ;
630 CORBA::TypeCode_var tc = tmp.type();
631 const char *
p = tc->name();
639 catch(omniORB::fatalException& fe)
641 cerr <<
"Caught omniORB::fatalException:" << endl;
642 cerr <<
" file: " << fe.file() << endl;
643 cerr <<
" line: " << fe.line() << endl;
644 cerr <<
" mesg: " << fe.errmsg() << endl;
649 cerr <<
"Caught unknown exception." << endl;
void display(CORBA::Any *data)
CORBA::Object_ptr Resolve(const char *Path) override
void init(bool start=true)
Initialize the bloc.
void exUpdateState()
Update the bloc state.
std::list< Node * > getAllRecursiveNodes()
Get all children nodes elementary and composed including this node.
virtual std::string getErrorReport()
returns a string that contains an error report if the node is in error
virtual void shutdown(int level)
Stop all pending activities of the composed node.
virtual void resetState(int level)
Reset the state of the node and its children depending on the parameter level.
virtual void cleanNodes()
Clean the composed node in case of not clean exit.
void checkConsistency(LinkInfo &info) const
Base class for dispatcher in observer pattern.
static Dispatcher * getDispatcher()
void setStopOnError(bool dumpRequested=false, std::string xmlFile="")
ask to stop execution on the first node found in error
void RunW(Scheduler *graph, int debug=0, bool fromScratch=true)
Class that deal with list of semantics links for high level analysis.
static const unsigned char ALL_DONT_STOP
std::string getGlobalRepr() const
bool areWarningsOrErrors() const
Class for logging error messages.
virtual std::string getStr()
static std::string getStateName(YACS::StatesForNode state)
Return the name of a state.
virtual int isValid()
indicates if the node is valid (returns 1) or not (returns 0)
virtual YACS::StatesForNode getEffectiveState() const
Return the node state in the context of its father.
Base class for all schema objects.
std::string setInPortValue(std::string nodeName, std::string portName, std::string value)
virtual Logger * getLogger(const std::string &name)
virtual void accept(Visitor *visitor)
virtual void writeDot(std::ostream &os) const
Dump to the input stream a dot representation of the node.
void setSqueezeStatus(bool sqStatus)
static void setRuntime(long flags=UsePython+UseCorba+UseXml+UseCpp+UseSalome, int argc=0, char *argv[]=NULL)
CORBA::ORB_ptr getOrb() const
virtual void addCatalog(Catalog *catalog)
Add a catalog of types and nodes to the runtime.
virtual Catalog * loadCatalog(const std::string &sourceKind, const std::string &path)
Load a catalog of calculation to use as factory.
void openFileSchema(std::string xmlDump)
void openFileDump(const std::string &xmlDump)
class for parse an xml file, use a dedicated parser, to load a saved state of a SALOME execution.
virtual void parse(std::string xmlState)
specialized parser to load SALOME execution saved states.
static struct arguments myArgs
int main(int argc, char *argv[])
bool parse_init_port(const std::string &input, std::string &node, std::string &port, std::string &value)
static error_t parse_opt(int key, char *arg, struct argp_state *state)
void * dumpState(void *arg)
void Handler(int theSigId)
sighandler_t setsig(int sig, sighandler_t handler)
const char * argp_program_version
void(* sighandler_t)(int)
const char * argp_program_bug_address
static struct argp_option options[]
void timer(std::string msg)
YACSRUNTIMESALOME_EXPORT RuntimeSALOME * getSALOMERuntime()
void YACSLIBENGINE_EXPORT UnLoadObserversPluginIfAny()
YACSLIBENGINE_EXPORT Runtime * getRuntime()
void YACSLIBENGINE_EXPORT LoadObserversPluginIfAny(ComposedNode *rootNode, Executor *executor)
std::list< std::string > init_ports
std::string dumpErrorFile
YACS::YACSLoader::YACSLoader * loader