-// Copyright (C) 2006-2013 CEA/DEN, EDF R&D
+// Copyright (C) 2006-2021 CEA/DEN, EDF R&D
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
#include "Exception.hxx"
#include "Executor.hxx"
#include "parsers.hxx"
-#include "VisitorSaveState.hxx"
+#include "VisitorSalomeSaveState.hxx"
#include "VisitorSaveSalomeSchema.hxx"
#include "LoadState.hxx"
#include "Dispatcher.hxx"
#include "LinkInfo.hxx"
+#include "ObserverAsPlugin.hxx"
#ifdef SALOME_KERNEL
+
+#include "KernelBasis.hxx"
+#include "SALOME_Launcher.hxx"
+#include "ServiceUnreachable.hxx"
+#include "SALOME_NamingService_Wrapper.hxx"
#include "SALOME_NamingService.hxx"
#include "SALOME_ModuleCatalog.hh"
#include "Basics_Utils.hxx"
#include <iostream>
#include <fstream>
#include <signal.h>
+#include <list>
-#ifdef WIN32
+#if defined WIN32 || defined __APPLE__
#else
#include <argp.h>
#endif
static char doc[] ="driver -- a SALOME YACS graph executor";
static char args_doc[] = "graph.xml";
-#ifdef WIN32
+#if defined WIN32 || defined __APPLE__
#else
static struct argp_option options[] =
{
{"shutdown", 't', "level", 0, "Shutdown the schema: 0=no shutdown to 3=full shutdown (default 1)"},
{"reset", 'r', "level", 0, "Reset the schema before execution: 0=nothing, 1=reset error nodes to ready state (default 0)"},
{"kill-port", 'k', "port", 0, "Kill Salome application running on the specified port if the driver process is killed (with SIGINT or SIGTERM)"},
+ {"init_port", 'i', "value", OPTION_ARG_OPTIONAL, "Initialisation value of a port, specified as bloc.node.port=value."},
{ 0 }
};
#endif
int shutdown;
int reset;
int killPort;
+ std::list<std::string> init_ports;
};
typedef struct {
string lockFile;
} thread_st;
-#ifdef WIN32
+#if defined WIN32 || defined __APPLE__
static int
#else
static error_t
#endif
parse_opt (int key, char *arg, struct argp_state *state)
{
-#ifdef WIN32
+#if defined WIN32 || defined __APPLE__
#else
// Get the input argument from argp_parse, which we
// know is a pointer to our arguments structure.
case 'k':
myArgs->killPort = atoi(arg);
break;
+ case 'i':
+ if (arg)
+ myArgs->init_ports.push_back(std::string(arg));
+ break;
case ARGP_KEY_ARG:
if (state->arg_num >=1) // Too many arguments.
}
// Our argp parser.
-#ifdef WIN32
+#if defined WIN32 || defined __APPLE__
#else
static struct argp argp = { options, parse_opt, args_doc, doc };
#endif
void timer(std::string msg)
{
-#ifdef WIN32
+#if defined WIN32 || defined __APPLE__
#else
struct timeval tv;
gettimeofday(&tv,NULL);
bool isFinalDump = (strlen(myArgs.finalDump) != 0);
if (isFinalDump)
{
- YACS::ENGINE::VisitorSaveState vst(p);
+ YACS::ENGINE::VisitorSalomeSaveState vst(p);
vst.openFileDump(myArgs.finalDump);
p->accept(&vst);
vst.closeFileDump();
#endif
string cmd = "touch " + st->lockFile;
system(cmd.c_str());
- YACS::ENGINE::VisitorSaveState vst(p);
+ YACS::ENGINE::VisitorSalomeSaveState vst(p);
vst.openFileDump(st->dumpFile);
p->accept(&vst);
vst.closeFileDump();
}
#endif
+bool parse_init_port(const std::string& input, std::string& node, std::string& port, std::string& value)
+{
+ bool ok = true;
+ size_t pos_eq = input.find('=');
+ if(pos_eq == std::string::npos || pos_eq == input.size())
+ return false;
+ value = input.substr(pos_eq+1);
+ size_t pos_dot = input.rfind('.', pos_eq);
+ if(!pos_dot || pos_dot == std::string::npos || pos_dot >= pos_eq-1)
+ return false;
+ port = input.substr(pos_dot+1, pos_eq-pos_dot-1);
+ node = input.substr(0, pos_dot);
+ return true;
+}
+
+void InitializeSSL()
+{
+ setSSLMode(true);
+ KERNEL::getLauncherSA();
+}
int main (int argc, char* argv[])
{
myArgs.shutdown = 1;
myArgs.reset = 0;
myArgs.killPort = 0;
+ myArgs.init_ports.clear();
// Parse our arguments; every option seen by parse_opt will be reflected in arguments.
-#ifdef WIN32
+#if defined WIN32 || defined __APPLE__
#else
argp_parse (&argp, argc, argv, 0, 0, &myArgs);
std::cerr << "graph = " << myArgs.args[0];
std::cerr << " dumpErrorFile=" << myArgs.dumpErrorFile << std::endl;
else
std::cerr << std::endl;
+ std::list<std::string>::const_iterator it;
+ for(it=myArgs.init_ports.begin(); it != myArgs.init_ports.end(); it++)
+ {
+ std::cerr << (*it) << std::endl;
+ }
#endif
#ifndef WIN32
setsig(SIGTERM,&Handler);
#endif
+ InitializeSSL();
+
timer("Starting ");
- RuntimeSALOME::setRuntime();
+ long flags = RuntimeSALOME::UsePython + RuntimeSALOME::UseCorba + RuntimeSALOME::UseXml + \
+ RuntimeSALOME::UseCpp + RuntimeSALOME::UseSalome;
+ RuntimeSALOME::setRuntime(flags, argc, argv);
// Try to load the session catalog if it exists
try
CORBA::ORB_ptr orb = runTime->getOrb();
if (orb)
{
- SALOME_NamingService namingService(orb);
+ SALOME_NamingService_Wrapper namingService(orb);
+ //SALOME_NamingService namingService(orb);
CORBA::Object_var obj = namingService.Resolve("/Kernel/ModulCatalog");
SALOME_ModuleCatalog::ModuleCatalog_var aModuleCatalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj);
if (! CORBA::is_nil(aModuleCatalog))
std::cerr << "The imported file is probably not a YACS schema file" << std::endl;
return 1;
}
+ // Initialize the ports
+ for(std::list<std::string>::iterator it=myArgs.init_ports.begin(); it != myArgs.init_ports.end(); it++)
+ {
+ std::string node, port, value;
+ if(parse_init_port((*it), node, port, value))
+ {
+ std::cerr << "Initialization node=" << node
+ << " port=" << port
+ << " value=" << value << std::endl;
+
+ std::string init_state;
+ init_state = p->setInPortValue(node, port, value);
+ if(value.compare(init_state))
+ {
+ std::cerr << "Error on initialization:" << init_state << std::endl;
+ return 1;
+ }
+ }
+ else
+ {
+ std::cerr << "Error on parsing initialization string:" << (*it) << std::endl;
+ return 1;
+ }
+ }
+
//Get the parser logger
Logger* logger=p->getLogger("parser");
//Print errors logged if any
st->lockFile = rootFile + ".lock";
pthread_create(&th,NULL,&dumpState,(void*)st);
}
-
+ YACS::ENGINE::LoadObserversPluginIfAny(p,&executor);
cerr << "+++++++++++++++++++ start calculation +++++++++++++++++++" << endl;
executor.RunW(p,myArgs.display, fromScratch);
cerr << "+++++++++++++++++++ end calculation +++++++++++++++++++" << endl;
bool isFinalDump = (strlen(myArgs.finalDump) != 0);
if (isFinalDump)
{
- YACS::ENGINE::VisitorSaveState vst(p);
+ YACS::ENGINE::VisitorSalomeSaveState vst(p);
vst.openFileDump(myArgs.finalDump);
p->accept(&vst);
vst.closeFileDump();
r->fini();
delete r;
delete disp;
+ YACS::ENGINE::UnLoadObserversPluginIfAny();
return return_value;
}
catch (YACS::Exception& e)