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;
281 sigemptyset (&sigmask);
282 sigaddset(&sigmask, sig);
283 sigprocmask(SIG_UNBLOCK, &sigmask, NULL);
284 struct sigaction context, ocontext;
285 context.sa_handler = handler;
286 sigemptyset(&context.sa_mask);
287 context.sa_flags = 0;
288 if (sigaction(sig, &context, &ocontext) == -1)
290 return ocontext.sa_handler;
294 bool parse_init_port(
const std::string& input, std::string& node, std::string& port, std::string& value)
297 size_t pos_eq = input.find(
'=');
298 if(pos_eq == std::string::npos || pos_eq == input.size())
300 value = input.substr(pos_eq+1);
301 size_t pos_dot = input.rfind(
'.', pos_eq);
302 if(!pos_dot || pos_dot == std::string::npos || pos_dot >= pos_eq-1)
304 port = input.substr(pos_dot+1, pos_eq-pos_dot-1);
305 node = input.substr(0, pos_dot);
312 KERNEL::getLauncherSA();
326 CORBA::Object_var objDSM(namingService.
Resolve(SALOMESDS::DataServerManager::NAME_IN_NS));
327 SALOME::DataServerManager_var dsm(SALOME::DataServerManager::_narrow(objDSM));
328 if ( !CORBA::is_nil(dsm) )
329 dsm->shutdownScopes();
332 catch(
const CORBA::Exception& )
336 catch(ServiceUnreachable& e)
342 int main (
int argc,
char* argv[])
345 #if defined WIN32 || defined __APPLE__
347 argp_parse (&
argp, argc, argv, 0, 0, &
myArgs);
351 std::cerr <<
" stop-on-error=" <<
myArgs.
stop;
359 std::cerr << std::endl;
360 std::list<std::string>::const_iterator it;
363 std::cerr << (*it) << std::endl;
388 CORBA::Object_var obj = namingService.
Resolve(
"/Kernel/ModulCatalog");
389 SALOME_ModuleCatalog::ModuleCatalog_var aModuleCatalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj);
390 if (! CORBA::is_nil(aModuleCatalog))
392 CORBA::String_var anIOR =
orb->object_to_string( aModuleCatalog );
398 catch(ServiceUnreachable& e)
408 timer(
"Elapsed time before load: ");
412 std::cerr <<
"The imported file is probably not a YACS schema file" << std::endl;
418 for(
auto node : allNodes)
430 std::string node, port, value;
433 std::cerr <<
"Initialization node=" << node
435 <<
" value=" << value << std::endl;
437 std::string init_state;
439 if(value.compare(init_state))
441 std::cerr <<
"Error on initialization:" << init_state << std::endl;
447 std::cerr <<
"Error on parsing initialization string:" << (*it) << std::endl;
457 std::cerr <<
"The imported file has errors" << std::endl;
458 std::cerr << logger->
getStr() << std::endl;
466 std::cerr <<
"The schema is not valid and can not be executed" << std::endl;
467 std::cerr << report << std::endl;
477 timer(
"Elapsed time after load: ");
482 std::cerr <<
"The schema is not valid and can not be executed" << std::endl;
483 std::cerr << report << std::endl;
491 timer(
"Elapsed time after validation: ");
498 std::cerr <<
"The schema is not consistent and can not be executed" << std::endl;
507 timer(
"Elapsed time after check consistency: ");
543 std::ofstream
f(
"toto");
557 pthread_create(&th,NULL,&
dumpState,(
void*)st);
560 cerr <<
"+++++++++++++++++++ start calculation +++++++++++++++++++" << endl;
562 cerr <<
"+++++++++++++++++++ end calculation +++++++++++++++++++" << endl;
564 timer(
"Elapsed time after execution: ");
569 int return_value = 0;
574 std::cerr <<
"Execution has ended in error" << std::endl;
575 std::cerr << report << std::endl;
581 std::ofstream g(
"titi");
588 pthread_join(th,NULL);
615 cerr <<
"Caught a YACS exception" << endl;
616 cerr << e.what() << endl;
624 catch (
const std::ios_base::failure&)
626 cerr <<
"Caught an io failure exception" << endl;
629 catch(CORBA::SystemException&
ex)
631 cerr <<
"Caught a CORBA::SystemException.:" << __FILE__ <<
":" << __LINE__ <<
":" ;
634 CORBA::TypeCode_var tc = tmp.type();
635 const char *
p = tc->name();
643 catch(omniORB::fatalException& fe)
645 cerr <<
"Caught omniORB::fatalException:" << endl;
646 cerr <<
" file: " << fe.file() << endl;
647 cerr <<
" line: " << fe.line() << endl;
648 cerr <<
" mesg: " << fe.errmsg() << endl;
653 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