From 238f9ea97c32572bd12b176ab6bdcb52f810d1de Mon Sep 17 00:00:00 2001 From: prascle Date: Thu, 27 Jan 2005 14:07:02 +0000 Subject: [PATCH] PR: merge from tag mergeto_HEAD_25Jan05 --- Makefile.in | 2 + bin/envSalome.py | 16 ++++ bin/launchConfigureParser.py | 85 ++++++-------------- bin/runSalome.py | 11 ++- bin/salomeConsole.py | 85 ++++++++++++++++++++ idl/SALOME_Component.idl | 8 ++ resources/KERNELCatalog.xml | 20 +++++ salome_adm/unix/config_files/check_sip.m4 | 44 +++++++--- salome_adm/unix/make_commence.in | 1 + src/Container/Container_i.cxx | 82 +++++++++++++++++++ src/Container/SALOME_ContainerPy.py | 22 +++++ src/Container/SALOME_Container_i.hxx | 3 + src/LifeCycleCORBA/Launchers.cxx | 79 ++++++++++++++++++ src/LifeCycleCORBA/Launchers.hxx | 6 ++ src/LifeCycleCORBA/Launchers.py | 82 +++++++++++++++++++ src/LifeCycleCORBA/LifeCycleCORBA.py | 65 +++++++++++++-- src/LifeCycleCORBA/Makefile.in | 7 +- src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx | 55 +++++++++++++ src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx | 3 + src/LifeCycleCORBA/TestLifeCycleCORBA.cxx | 24 +++++- src/Logger/SALOME_Trace.hxx | 2 +- src/NamingService/SALOME_NamingService.cxx | 4 + src/NamingService/SALOME_NamingService.hxx | 3 + src/SALOME_PYQT/Makefile.in | 12 ++- src/Utils/Utils_Identity.py | 21 +++++ 25 files changed, 654 insertions(+), 88 deletions(-) create mode 100755 bin/envSalome.py create mode 100755 bin/salomeConsole.py create mode 100644 src/LifeCycleCORBA/Launchers.cxx create mode 100644 src/LifeCycleCORBA/Launchers.hxx create mode 100644 src/LifeCycleCORBA/Launchers.py diff --git a/Makefile.in b/Makefile.in index ab8870626..5c92e402e 100644 --- a/Makefile.in +++ b/Makefile.in @@ -98,6 +98,8 @@ runSalome.csh \ runNS.sh \ launchConfigureParser.py \ salome.launch \ +envSalome.py \ +salomeConsole.py \ showNS.py # copy header files in common directory diff --git a/bin/envSalome.py b/bin/envSalome.py new file mode 100755 index 000000000..3eacc0c12 --- /dev/null +++ b/bin/envSalome.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python +import os +import sys + +kernel_root=os.getenv("KERNEL_ROOT_DIR") +sys.path[:0]=[kernel_root+"/bin/salome"] + +import runSalome + +argv=sys.argv[1:] +sys.argv=[] + +args, modules_list, modules_root_dir = runSalome.get_config() +runSalome.set_env(args, modules_list, modules_root_dir) + +os.execvp(argv[0],argv) diff --git a/bin/launchConfigureParser.py b/bin/launchConfigureParser.py index 717815401..b61515d19 100755 --- a/bin/launchConfigureParser.py +++ b/bin/launchConfigureParser.py @@ -92,53 +92,18 @@ class xml_parser: # ----------------------------------------------------------------------------- -### searching for launch configuration file : $HOME/.$(application_name)/$(application_name).launch - -appname = None -dirname = None -filename = None -for bindir in glob.glob(os.environ["KERNEL_ROOT_DIR"]+"/bin/*"): - appname = string.split(bindir, "/").pop() - print 'Application name: "'+appname+'"' - # find version number - versnb = "" - try: - file = open(os.environ["KERNEL_ROOT_DIR"]+"/bin/"+appname+"/VERSION", "r") - s = file.read() - l = string.split(s, ":") - vl = string.split(l[1], " ") - i = 0 - while len(versnb) == 0: - versnb = vl[i] - i += 1 - pass - versnb = string.split(versnb, "\n")[0] - print "Version ",versnb - except: - pass - # end find version number - dirname = os.environ["HOME"]+"/."+appname+"_"+versnb - filename = dirname+"/"+appname+".launch" - if not os.path.exists(filename) and \ - not os.path.exists(os.environ["KERNEL_ROOT_DIR"]+"/bin/"+appname+"/"+appname+".launch"): - filename = None - else: - break - pass -if not appname: - print "Can not find application name" - if not os.have_key("KERNEL_ROOT_DIR"): - print "KERNEL_ROOT_DIR environment variable must be set" - pass - sys.exit(1); -elif not filename or not os.path.exists(filename): - filename = dirname+"/"+appname+".launch" - #filename = os.environ["HOME"]+"/."+appname+"/"+appname+".launch" - print "Launch configuration file does not exist. Create default:",filename - os.system("mkdir -p "+dirname) - #os.system("mkdir -p "+os.environ["HOME"]+"/."+appname) - os.system("cp -f "+os.environ["KERNEL_ROOT_DIR"]+"/bin/"+appname+"/"+appname+".launch "+filename) - pass +### searching for launch configuration file : $HOME/applipath()/salome.launch + +appname="salome" +import Utils_Identity +versnb=Utils_Identity.version() +dirname = os.path.join(os.environ["HOME"],Utils_Identity.getapplipath()) +filename=os.path.join(dirname,"salome.launch") + +if not os.path.exists(filename): + print "Launch configuration file does not exist. Create default:",filename + os.system("mkdir -p "+dirname) + os.system("cp -f "+os.environ["KERNEL_ROOT_DIR"]+"/bin/salome/salome.launch "+filename) ### get options from launch configuration file @@ -251,28 +216,28 @@ if opts.has_key("h"): print """USAGE: runSalome.py [options] [command line options] : --help or -h : print this help - --gui or -g : lancement du GUI + --gui or -g : launching with GUI --terminal -t : launching without gui (to deny --gui) - --logger or -l : redirection des messages via CORBA - --file=filename or -l=filename: redirection des messages dans un fichier - --xterm or -x : les serveurs ouvrent une fenêtre xterm et les messages sont affichés dans cette fenêtre - --modules=module1,module2,... : où modulen est le nom d'un module Salome à charger dans le catalogue + --logger or -l : redirect messages in a CORBA collector + --file=filename or -f=filename: redirect messages in a log file + --xterm or -x : execute servers in xterm console (messages appear in xterm windows) + --modules=module1,module2,... : salome module list (modulen is the name of Salome module to load) or -m=module1,module2,... --embedded=registry,study,moduleCatalog,cppContainer or -e=registry,study,moduleCatalog,cppContainer - : serveurs CORBA embarqués (par defaut: registry,study,moduleCatalog,cppContainer) - : (logger,pyContainer,supervContainer ne peuvent pas être embarqués + : embedded CORBA servers (default: registry,study,moduleCatalog,cppContainer) + : (logger,pyContainer,supervContainer can't be embedded --standalone=registry,study,moduleCatalog,cppContainer,pyContainer,supervContainer or -s=registry,study,moduleCatalog,cppContainer,pyContainer,supervContainer - : executables serveurs CORBA indépendants (par défaut: pyContainer,supervContainer) - --containers=cpp,python,superv: (obsolete) lancement des containers cpp, python et de supervision - or -c=cpp,python,superv : = on prend les defauts de -e et -s + : standalone CORBA servers (default: pyContainer,supervContainer) + --containers=cpp,python,superv: (obsolete) launching of containers cpp, python and supervision + or -c=cpp,python,superv : = get default from -e and -s --portkill or -p : kill the salome with current port --killall or -k : kill salome - La variable d'environnement _ROOT_DIR doit etre préalablement - positionnée (modulen doit etre en majuscule). - KERNEL_ROOT_DIR est obligatoire. + For each Salome module, the environment variable _ROOT_DIR must be set. + The module name () must be uppercase. + KERNEL_ROOT_DIR is mandatory. """ sys.exit(1) pass diff --git a/bin/runSalome.py b/bin/runSalome.py index 5fb5c006d..75a0cc9ae 100755 --- a/bin/runSalome.py +++ b/bin/runSalome.py @@ -400,10 +400,12 @@ class NotifyServer(Server): self.modules_root_dir=modules_root_dir myLogName = os.environ["LOGNAME"] self.CMD=['notifd','-c', - self.modules_root_dir["KERNEL"] - +'/share/salome/resources/channel.cfg', + self.modules_root_dir["KERNEL"] +'/share/salome/resources/channel.cfg', '-DFactoryIORFileName=/tmp/'+myLogName+'_rdifact.ior', - '-DChannelIORFileName=/tmp/'+myLogName+'_rdichan.ior'] + '-DChannelIORFileName=/tmp/'+myLogName+'_rdichan.ior', + '-DReportLogFile=/tmp/'+myLogName+'_notifd.report', + '-DDebugLogFile=/tmp/'+myLogName+'_notifd.debug', + ] # # ----------------------------------------------------------------------------- @@ -582,6 +584,8 @@ def useSalome(args, modules_list, modules_root_dir): try: clt = startSalome(args, modules_list, modules_root_dir) except: + import traceback + traceback.print_exc() print print print "--- erreur au lancement Salome ---" @@ -668,4 +672,5 @@ def main(): # ----------------------------------------------------------------------------- if __name__ == "__main__": + import user clt,args = main() diff --git a/bin/salomeConsole.py b/bin/salomeConsole.py new file mode 100755 index 000000000..03c0a5e51 --- /dev/null +++ b/bin/salomeConsole.py @@ -0,0 +1,85 @@ +#!/usr/bin/env python + +import os +import sys +#------------------------------- +# Python completion and others if you want +# You should have set PYTHONSTARTUP env variable +# or import user should try to import $HOME/.pythonrc.py +#------------------------------- +import user + +#------------------------------- +# Get major CORBA objects +#------------------------------- +import CORBA +import CosNaming +# There are cyclic dependencies between Engines, SALOME and SALOMEDS. +# import first Engines, then SALOME and then SALOMEDS +# Or use reload(Engines) to be safe. +import Engines +import SALOME +import SALOMEDS +import SALOME_ModuleCatalog +reload(Engines) +reload(SALOME) +reload(SALOMEDS) + +import LifeCycleCORBA +import orbmodule +from runSalome import * + +import Utils_Identity +files = glob.glob(os.path.join(os.environ["HOME"],Utils_Identity.getapplipath(),".omni*.cfg")) + +filename="" +if len(files)==1: + filename=files[0] +else: + print "You have %d sessions running" % len(files) + for f in files: + print "Session:",f + rep= raw_input("Do you want to connect to this session [y|n]") + if rep == "y": + filename=f + break + +if filename != "": + os.environ['OMNIORB_CONFIG']=filename +else: + rep= raw_input("Do you want to try a local session on port 2810 ? [y|n]") + if rep == "y": + # Try a local session running on port 2810 + sys.argv=sys.argv+['-ORBInitRef','NameService=corbaname::localhost:2810'] + else: + sys.exit(1) + +print sys.argv + +#direct adress from clt.orb.object_to_string(clt.rootContext) +#sys.argv=sys.argv+['-ORBInitRef','NameService=IOR:010000000100000000000000010000000000000023000000010100000a0000006c6f63616c686f737400fa0a0b0000004e616d6553657276696365'] + +class client(orbmodule.client): + def initNS(self): + # Obtain a reference to the root naming context + obj = self.orb.resolve_initial_references("NameService") + try: + self.rootContext = obj._narrow(CosNaming.NamingContext) + return + except CORBA.COMM_FAILURE: + print "It's not a valid naming service" + self.rootContext = None + raise + +clt=client() +print "Naming Service address: ",clt.orb.object_to_string(clt.rootContext) + +clt.showNS() + +session=clt.waitNS("/Kernel/Session") +catalog=clt.waitNS("/Kernel/ModulCatalog") +studyMgr=clt.waitNS("/myStudyManager") +lcc = LifeCycleCORBA.LifeCycleCORBA(clt.orb) + +#c=lcc.FindOrStartContainer("","totoPy") +#print c diff --git a/idl/SALOME_Component.idl b/idl/SALOME_Component.idl index 8760ae9df..f60922c42 100644 --- a/idl/SALOME_Component.idl +++ b/idl/SALOME_Component.idl @@ -61,6 +61,14 @@ module Engines */ Component load_impl(in string nameToRegister, in string componentName); +/*! + Loads into the container a new component, registers it and starts it's CORBA servant. + \param nameToRegister Name used to register in Naming Service, the component instance + \param componentName Name of the %component + \return a new instance of the component or the registered component if already registered or Nil if not possible +*/ + Component instance(in string nameToRegister, in string componentName); + /*! Stops the component servant, and deletes all related objects \param component_i Component to be removed diff --git a/resources/KERNELCatalog.xml b/resources/KERNELCatalog.xml index 1208eb26f..4bad252ff 100644 --- a/resources/KERNELCatalog.xml +++ b/resources/KERNELCatalog.xml @@ -22,5 +22,25 @@ hostname = muna + + SalomeTestComponent + SalomeTestComponent + Other + NRI + 2.1.0 + GUI Neutral Context + 1 + 'linux' ~ OS + + + SALOME_TestComponentPy + SALOME_TestComponentPy + Other + NRI + 2.1.0 + GUI Neutral Context + 1 + 'linux' ~ OS + diff --git a/salome_adm/unix/config_files/check_sip.m4 b/salome_adm/unix/config_files/check_sip.m4 index 48a025918..84c2beaf7 100644 --- a/salome_adm/unix/config_files/check_sip.m4 +++ b/salome_adm/unix/config_files/check_sip.m4 @@ -21,42 +21,51 @@ else version=`sip -V` case "$version" in 3.2*) - sip_vers=old ;; + SIP_VERS=old ;; 3.3*) - sip_vers=old ;; + SIP_VERS=old ;; 3.4*) - sip_vers=new ;; + SIP_VERS=new ;; 3.5*) - sip_vers=new ;; + SIP_VERS=new ;; 3.6*) - sip_vers=new ;; + SIP_VERS=new ;; 3.7*) - sip_vers=new ;; + SIP_VERS=new ;; 3.8*) - sip_vers=new ;; + SIP_VERS=new ;; 3.9*) - sip_vers=new ;; - *) - sip_vers=no ;; + SIP_VERS=new ;; + 3.10*) + SIP_VERS=new2 ;; + *) + AC_MSG_RESULT(sip version $version not supported) + SIP_VERS=no ;; esac sip_ok=no - if test "x$sip_vers" = "xold" + if test "x$SIP_VERS" = "xold" then + dnl old install : includes and libs are in python install or in SIPDIR + AC_MSG_RESULT(old install detected) sip_ok=yes SIP_ROOT="$SIPDIR" SIP_INCLUDES="${PYTHON_INCLUDES} -I${SIPDIR}" SIP_LIBS="-L${PYTHON_PREFIX}/lib/python${PYTHON_VERSION}/site-packages -L${SIPDIR} -lsip" fi - if test "x$sip_vers" = "xnew" + if test "x$SIP_VERS" = "xnew" then sip_ok=yes if test -d ${SIPDIR}/include/python${PYTHON_VERSION} ; then + AC_MSG_RESULT(new install with include dir detected) + dnl new install with include dir : includes and libs are in python install or in SIPDIR/include SIP_ROOT="$SIPDIR" SIP_INCLUDES="${PYTHON_INCLUDES} -I${SIPDIR}/include/python${PYTHON_VERSION}" SIP_LIBS="-L${SIPDIR}/lib/python${PYTHON_VERSION}/site-packages -lsip" else + dnl new install without include dir : includes and libs are in SIPDIR + AC_MSG_RESULT(new install without include dir detected) sip_ok=yes SIP_ROOT="$SIPDIR" SIP_INCLUDES="-I${SIPDIR}" @@ -64,11 +73,22 @@ else fi fi + if test "x$SIP_VERS" = "xnew2" + then + dnl new2 install : includes and libs are in python install + AC_MSG_RESULT(new2 install detected) + sip_ok=yes + AC_CHECK_FILE($PYTHON_PREFIX/include/python$PYTHON_VERSION/sip.h,sip_ok=$sip_ok,sip_ok=no) + SIP_INCLUDES="${PYTHON_INCLUDES}" + AC_CHECK_FILE($PYTHON_PREFIX/lib/python$PYTHON_VERSION/site-packages/libsip.so,sip_ok=$sip_ok,sip_ok=no) + SIP_LIBS="-L${PYTHON_PREFIX}/lib/python${PYTHON_VERSION}/site-packages -lsip" + fi fi AC_SUBST(SIP) AC_SUBST(SIP_INCLUDES) AC_SUBST(SIP_LIBS) +AC_SUBST(SIP_VERS) AC_MSG_RESULT(for sip: $sip_ok) diff --git a/salome_adm/unix/make_commence.in b/salome_adm/unix/make_commence.in index 7e5122adb..620cfd9ff 100644 --- a/salome_adm/unix/make_commence.in +++ b/salome_adm/unix/make_commence.in @@ -91,6 +91,7 @@ QWT_LIBS=@QWT_LIBS@ SIP = @SIP@ SIP_INCLUDES = @SIP_INCLUDES@ SIP_LIBS = @SIP_LIBS@ +SIP_VERS = @SIP_VERS@ # PYQT PYQT_SIPS = @PYQT_SIPS@ diff --git a/src/Container/Container_i.cxx b/src/Container/Container_i.cxx index 301b56719..649a29b5e 100644 --- a/src/Container/Container_i.cxx +++ b/src/Container/Container_i.cxx @@ -358,3 +358,85 @@ string Engines_Container_i::BuildContainerNameForNS(const char *ContainerName, c return ret; } + +/* + * Create one instance of componentName component and register it + * as nameToRegister in naming service + */ +Engines::Component_ptr Engines_Container_i::instance( const char* nameToRegister, + const char* componentName ) { + + _numInstanceMutex.lock() ; // lock on the instance number + BEGIN_OF( "Container_i::instance " << componentName ) ; + + string _nameToRegister = nameToRegister; + string component_registerName = _containerName + "/" + _nameToRegister; + + Engines::Component_var iobject = Engines::Component::_nil() ; + + try { + CORBA::Object_var obj = _NS->Resolve( component_registerName.c_str() ) ; + if (! CORBA::is_nil( obj ) ) { + MESSAGE( "Container_i::instance " << component_registerName.c_str() << " already registered" ) ; + iobject = Engines::Component::_narrow( obj ) ; + } + else{ + string _compo_name = componentName; + string _impl_name = "lib" + _compo_name + "Engine.so"; + SCRUTE(_impl_name); + + void* handle; + handle = dlopen( _impl_name.c_str() , RTLD_LAZY ) ; + + if ( handle ) { + string factory_name = _compo_name + "Engine_factory"; + SCRUTE(factory_name) ; + + typedef PortableServer::ObjectId * (*FACTORY_FUNCTION) + (CORBA::ORB_ptr, + PortableServer::POA_ptr, + PortableServer::ObjectId *, + const char *, + const char *) ; + FACTORY_FUNCTION Component_factory = (FACTORY_FUNCTION) dlsym(handle, factory_name.c_str()); + + char *error ; + if ( (error = dlerror() ) == NULL) { + // Instanciate required CORBA object + _numInstance++ ; + char _aNumI[12]; + sprintf( _aNumI , "%d" , _numInstance ) ; + string instanceName = _compo_name + "_inst_" + _aNumI ; + SCRUTE(instanceName); + + PortableServer::ObjectId * id ; + id = (Component_factory) ( _orb, _poa, _id, instanceName.c_str() , + _nameToRegister.c_str() ) ; + // get reference from id + obj = _poa->id_to_reference(*id); + iobject = Engines::Component::_narrow( obj ) ; + + // register the engine under the name containerName.dir/nameToRegister.object + _NS->Register( iobject , component_registerName.c_str() ) ; + MESSAGE( "Container_i::instance " << component_registerName.c_str() << " registered" ) ; + handle_map[instanceName] = handle; + } + else{ + INFOS("Can't resolve symbol: " + factory_name); + SCRUTE(error); + } + } + else{ + INFOS("Can't load shared library : " << _impl_name); + INFOS("error dlopen: " << dlerror()); + } + } + } + catch (...) { + INFOS( "Container_i::instance exception caught" ) ; + } + END_OF("Container_i::instance"); + _numInstanceMutex.unlock() ; + return Engines::Component::_duplicate(iobject); +} + diff --git a/src/Container/SALOME_ContainerPy.py b/src/Container/SALOME_ContainerPy.py index 417599eb9..dbaa9f65e 100755 --- a/src/Container/SALOME_ContainerPy.py +++ b/src/Container/SALOME_ContainerPy.py @@ -36,6 +36,8 @@ from omniORB import CORBA, PortableServer # (if not, incomplete import done by SALOME module: no load of SALOMEDS_attributes) import SALOMEDS import Engines, Engines__POA +reload(Engines) +reload(Engines__POA) from SALOME_NamingServicePy import * from SALOME_ComponentPy import * @@ -133,6 +135,22 @@ class SALOME_ContainerPy_i (Engines__POA.Container): #------------------------------------------------------------------------- + def instance(self, nameToRegister, componentName): + MESSAGE( "SALOME_ContainerPy_i::instance " + str(nameToRegister) + ' ' + str(componentName) ) + self._numInstance = self._numInstance +1 + instanceName = nameToRegister + "_inst_" + `self._numInstance` + + component=__import__(componentName) + factory=getattr(component,componentName) + comp_i=factory(self._orb, self._poa, self._this(), self._containerName, + instanceName, nameToRegister) + + MESSAGE( "SALOME_ContainerPy_i::instance : component created") + comp_o = comp_i._this() + return comp_o + + #------------------------------------------------------------------------- + def load_impl(self, nameToRegister, componentName): MESSAGE( "SALOME_ContainerPy_i::load_impl " + str(nameToRegister) + ' ' + str(componentName) ) self._numInstance = self._numInstance +1 @@ -150,21 +168,25 @@ class SALOME_ContainerPy_i (Engines__POA.Container): def remove_impl(self, component): MESSAGE( "SALOME_ContainerPy_i::remove_impl" ) + return None #------------------------------------------------------------------------- def finalize_removal(self): MESSAGE( "SALOME_ContainerPy_i::finalize_removal" ) + return None #------------------------------------------------------------------------- def ping(self): MESSAGE( "SALOME_ContainerPy_i::ping" ) + return None #------------------------------------------------------------------------- def _get_name(self): MESSAGE( "SALOME_ContainerPy_i::_get_name" ) + return self._containerName #------------------------------------------------------------------------- diff --git a/src/Container/SALOME_Container_i.hxx b/src/Container/SALOME_Container_i.hxx index 249f80657..0aa0658ae 100644 --- a/src/Container/SALOME_Container_i.hxx +++ b/src/Container/SALOME_Container_i.hxx @@ -60,6 +60,9 @@ public: Engines::Component_ptr load_impl(const char* nameToRegister, const char* componentName); + Engines::Component_ptr instance(const char* nameToRegister, + const char* componentName); + //! Unload component from current container void remove_impl(Engines::Component_ptr component_i); void finalize_removal(); diff --git a/src/LifeCycleCORBA/Launchers.cxx b/src/LifeCycleCORBA/Launchers.cxx new file mode 100644 index 000000000..f3622465d --- /dev/null +++ b/src/LifeCycleCORBA/Launchers.cxx @@ -0,0 +1,79 @@ +#include + +static int Launchers_IsLoaded = 0; +static PyObject * Launchers_module = 0; +static char * Launchers_name="Launchers"; + +PyThreadState *mainThreadState=0; + +PyThreadState * getMainThreadState(){ + PyInterpreterState *interp; + PyThreadState *p; + interp=PyInterpreterState_Head(); + for (interp = PyInterpreterState_Head(); interp != NULL; ){ + if(interp->next == NULL)break; + interp=interp->next; + } + for (p = interp->tstate_head; p != NULL; ){ + if(p->next == NULL)break; + p=p->next; + } + return p; +} +PyThreadState *acquireMainThread(){ + PyEval_AcquireLock(); + return PyThreadState_Swap(mainThreadState); +} +void releaseMainThread(PyThreadState *tstate){ + PyThreadState_Swap(tstate); + PyEval_ReleaseLock(); +} + +void Launchers_assertInitialized() { + PyThreadState *_save; + if( !Py_IsInitialized() ) { + Py_Initialize(); + PyEval_InitThreads(); + PyEval_SaveThread(); + } + if( !Launchers_IsLoaded ) { + mainThreadState=getMainThreadState(); + _save=acquireMainThread(); + Launchers_module=PyImport_ImportModule(Launchers_name); + if(!Launchers_module){ + PyErr_Print(); + return; + } + Py_INCREF(Launchers_module); + Launchers_IsLoaded = 1; + releaseMainThread(_save); + } +} + +PyObject * getLauncher(char* arg0) { + PyObject *v; + PyThreadState *_save; + Launchers_assertInitialized(); + _save=acquireMainThread(); + v=PyObject_CallMethod(Launchers_module,"getLauncher","s",arg0); + if(!v){ + PyErr_Print(); + return NULL; + } + releaseMainThread(_save); + Py_INCREF(v); + return v; +} + +void Launcher_Slaunch(PyObject *self, char* arg1, char* arg2) { + PyObject *v; + PyThreadState *_save; + Launchers_assertInitialized(); + _save=acquireMainThread(); + v=PyObject_CallMethod(self,"Slaunch","ss",arg1,arg2); + if(!v){ + PyErr_Print(); + } + releaseMainThread(_save); +} + diff --git a/src/LifeCycleCORBA/Launchers.hxx b/src/LifeCycleCORBA/Launchers.hxx new file mode 100644 index 000000000..f402b7e51 --- /dev/null +++ b/src/LifeCycleCORBA/Launchers.hxx @@ -0,0 +1,6 @@ +#include +#define elDEBUG 0 + +PyObject * getLauncher(char* ); +void Launcher_Slaunch(PyObject * objId, char*, char* ); + diff --git a/src/LifeCycleCORBA/Launchers.py b/src/LifeCycleCORBA/Launchers.py new file mode 100644 index 000000000..0888b17b9 --- /dev/null +++ b/src/LifeCycleCORBA/Launchers.py @@ -0,0 +1,82 @@ +import os +import Utils_Identity +import ConfigParser + +class Config: + defaults={'user':'','opt':''} + def __init__(self): + self.config=ConfigParser.ConfigParser(self.defaults) + self.config.read(os.path.join(os.environ['HOME'],Utils_Identity.getapplipath(),'launchers.cfg')) + def computers(self): + return self.config.sections() + def options(self,computer): + if not self.config.has_section(computer): + return self.defaults + else: + d={} + for opt in self.config.options(computer): + d[opt]=self.config.get(computer,opt) + return d + +config=None +def setConfig(conf): + global config + config=conf + +setConfig(Config()) + +class Launcher: + def Slaunch(self,computer,CMD): + self.launch(computer,CMD.split()) + +class SSH(Launcher): + def launch(self,computer,CMD): + print computer,CMD + conf=config.options(computer) + print conf + command=["ssh",computer] + if conf["user"]: + command=command+['-l',conf["user"]] + if conf["opt"]: + command=command+string.split(conf["opt"]) + command=command+[os.path.join(Utils_Identity.getapplipath(),'runSession')]+CMD + command=command+['>', "/tmp/" + CMD[1] + "_" + computer + ".log 2>&1"] + + print command + pid = os.spawnvp(os.P_NOWAIT, command[0], command) + +launcher=None +_register={} + +def register(name,klass): + _register[name]=klass + +register("ssh",SSH()) + +def setLauncher(name): + global launcher + launcher=_register[name] + +def getLauncher(computer): + """ + Return a launcher for the computer + If can be specified in config + If not return the default one : launcher + """ + conf=config.options(computer) + name=conf.get("launcher","") + return _register.get(name,launcher) + +setLauncher("ssh") + +try: + # Try to import a plugin module (user defined) that + # can define other launchers and register them + # 1- define a class + # 2- register it with : Launchers.register(name,klass) + # 3- eventually set it as default one : Launchers.setLauncher(name) + import pluginLauncher +except: + import traceback + traceback.print_exc() + pass diff --git a/src/LifeCycleCORBA/LifeCycleCORBA.py b/src/LifeCycleCORBA/LifeCycleCORBA.py index 82c364936..5c9c3796a 100644 --- a/src/LifeCycleCORBA/LifeCycleCORBA.py +++ b/src/LifeCycleCORBA/LifeCycleCORBA.py @@ -37,6 +37,8 @@ import SALOME_ModuleCatalog from SALOME_utilities import * from Utils_Identity import getShortHostName +import Utils_Identity +import Launchers class LifeCycleCORBA: _orb = None @@ -96,12 +98,10 @@ class LifeCycleCORBA: except: theComputer = "" theContainer = containerName - if theComputer == "" : - theComputer = getShortHostName() - if theComputer == "localhost" : + + if theComputer in ("","localhost") : theComputer = getShortHostName() - computerSplitName = theComputer.split('.') - theComputer = computerSplitName[0] + MESSAGE( theComputer + theContainer ) return theComputer,theContainer @@ -182,6 +182,61 @@ class LifeCycleCORBA: #------------------------------------------------------------------------- + def setLauncher(self,name): + """Change default launcher to the launcher identified by name + + See module Launchers.py + """ + Launchers.setLauncher(name) + + #------------------------------------------------------------------------- + + def StartContainer(self, theComputer , theContainer ): + """Start a container on theComputer machine with theContainer name + """ + # Get the Naming Service address + # + addr=self._orb.object_to_string(self._rootContext) + # + # If container name contains "Py" launch a Python Container + # + if theContainer.find('Py') == -1 : + CMD=['SALOME_Container',theContainer,'-ORBInitRef','NameService='+addr] + else: + CMD=['SALOME_ContainerPy.py',theContainer,'-ORBInitRef','NameService='+addr] + if theComputer in ("","localhost"): + theComputer=getShortHostName() + # + # Get the appropriate launcher and ask to launch + # + Launchers.getLauncher(theComputer).launch(theComputer,CMD) + # + # Wait until the container is registered in Naming Service + # + count =5 + aContainer=None + while aContainer is None and count > 0: + time.sleep(1) + count = count - 1 + MESSAGE( str(count) + ". Waiting for " + theComputer + "/" + theContainer ) + aContainer = self.FindContainer( theComputer + "/" + theContainer ) + return aContainer + + #------------------------------------------------------------------------- + + def FindOrStartContainer(self, theComputer , theContainer ): + """Find or Start a container on theComputer machine with theContainer name + """ + if theComputer in ("","localhost"): + theComputer=getShortHostName() + MESSAGE( "FindOrStartContainer: " + theComputer + theContainer ) + aContainer = self.FindContainer( theComputer + "/" + theContainer ) + if aContainer is None : + aContainer= self.StartContainer(theComputer , theContainer ) + return aContainer + + #------------------------------------------------------------------------- + def LoadComponent(self,containerName,componentName,listOfMachine): container=self._contManager.FindOrStartContainer(containerName,listOfMachine) implementation="lib"+componentName+"Engine.so" diff --git a/src/LifeCycleCORBA/Makefile.in b/src/LifeCycleCORBA/Makefile.in index 64daf70e8..3b825582f 100644 --- a/src/LifeCycleCORBA/Makefile.in +++ b/src/LifeCycleCORBA/Makefile.in @@ -36,12 +36,12 @@ VPATH=.:@srcdir@:@top_srcdir@/idl EXPORT_HEADERS = SALOME_LifeCycleCORBA.hxx -EXPORT_PYSCRIPTS = LifeCycleCORBA.py +EXPORT_PYSCRIPTS = LifeCycleCORBA.py Launchers.py # Libraries targets LIB = libSalomeLifeCycleCORBA.la -LIB_SRC = SALOME_LifeCycleCORBA.cxx +LIB_SRC = SALOME_LifeCycleCORBA.cxx Launchers.cxx LIB_CLIENT_IDL = SALOME_Component.idl SALOME_TestComponent.idl \ SALOME_ModuleCatalog.idl SALOME_ContainerManager.idl @@ -51,10 +51,11 @@ BIN_SRC = BIN_CLIENT_IDL = SALOME_Component.idl SALOME_TestComponent.idl \ SALOME_ModuleCatalog.idl SALOME_ContainerManager.idl -CPPFLAGS += $(QT_MT_INCLUDES) +CPPFLAGS += $(PYTHON_INCLUDES) $(QT_MT_INCLUDES) LDFLAGS += -lSalomeNS -lOpUtil -lSALOMELocalTrace -lSalomeContainer -lSalomeResourcesManager LDFLAGSFORBIN= $(LDFLAGS) -lRegistry -lSalomeNotification -lSALOMETraceCollector +LIBS += $(PYTHON_LIBS) @CONCLUDE@ diff --git a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx index 466fa70d6..af5848155 100644 --- a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx +++ b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx @@ -33,6 +33,7 @@ #include "OpUtil.hxx" #include "utilities.h" +#include "Launchers.hxx" #include @@ -267,3 +268,57 @@ Engines::Component_ptr SALOME_LifeCycleCORBA::LoadComponent(const char *containe string implementation=Engines_Component_i::GetDynLibraryName(componentName); return cont->load_impl(componentName, implementation.c_str()); } + + +Engines::Container_ptr SALOME_LifeCycleCORBA::FindOrStartContainer( + const string aComputerContainer , + const string theComputer , + const string theContainer ) { + SCRUTE( aComputerContainer ) ; + SCRUTE( theComputer ) ; + SCRUTE( theContainer ) ; + + Engines::Container_var aContainer = FindContainer( aComputerContainer.c_str() ) ; + + if ( !CORBA::is_nil( aContainer ) ) { + return aContainer ; + } + + Engines::Container_var aFactoryServer ; + + bool pyCont = false ; + int len = theContainer.length() ; + if ( !strcmp( &theContainer.c_str()[len-2] , "Py" ) ) { + pyCont = true ; + } + + string addr=_NS->getIORaddr(); + string CMD="SALOME_Container"; + if ( pyCont ) { + CMD="SALOME_ContainerPy.py"; + } + CMD=CMD + " " + theContainer; + CMD=CMD + " -ORBInitRef NameService="+addr; + + /* + * Get the appropriate launcher and ask to launch + */ + PyObject * launcher=getLauncher((char *)theComputer.c_str()); + Launcher_Slaunch(launcher,(char *)theComputer.c_str(),(char *)CMD.c_str()); + /* + * Wait until the container is registered in Naming Service + */ + int count = 5 ; + while ( CORBA::is_nil( aFactoryServer ) && count ) { + sleep( 1 ) ; + count-- ; + if ( count != 10 ) + MESSAGE( count << ". Waiting for FactoryServer on " << theComputer) + aFactoryServer = FindContainer( aComputerContainer.c_str() ) ; + } + if ( !CORBA::is_nil( aFactoryServer ) ) { + return aFactoryServer; + } + MESSAGE("SALOME_LifeCycleCORBA::StartOrFindContainer rsh failed") ; + return Engines::Container::_nil(); +} diff --git a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx index a7a145c27..ca91a238f 100644 --- a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx +++ b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx @@ -67,6 +67,9 @@ protected: std::string * theComputer , std::string * theContainer ) ; std::string ComputerPath( const char * theComputer ) ; + Engines::Container_ptr FindOrStartContainer(const std::string aComputerContainer , + const std::string theComputer , + const std::string theContainer ) ; } ; #endif diff --git a/src/LifeCycleCORBA/TestLifeCycleCORBA.cxx b/src/LifeCycleCORBA/TestLifeCycleCORBA.cxx index 603c32814..49e3b28b0 100644 --- a/src/LifeCycleCORBA/TestLifeCycleCORBA.cxx +++ b/src/LifeCycleCORBA/TestLifeCycleCORBA.cxx @@ -26,7 +26,6 @@ // Module : SALOME // $Header$ -#include "utilities.h" #include #include #include @@ -34,7 +33,10 @@ #include CORBA_CLIENT_HEADER(SALOME_TestComponent) #include "SALOME_NamingService.hxx" #include "SALOME_LifeCycleCORBA.hxx" +#include "utilities.h" +#include "SALOMETraceCollector.hxx" #include + using namespace std; int main (int argc, char * argv[]) @@ -44,6 +46,7 @@ int main (int argc, char * argv[]) { // Initializing omniORB CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); + SALOMETraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb); // Obtain a reference to the root POA CORBA::Object_var obj = orb->resolve_initial_references("RootPOA") ; @@ -58,6 +61,10 @@ int main (int argc, char * argv[]) string containerName = GetHostname(); + cout << containerName << endl; + cout << "FindOrLoadComponent " + containerName + "/" + "SalomeTestComponent" << endl; + MESSAGE("FindOrLoadComponent " + containerName + "/" + "SalomeTestComponent" ); + Engines::Component_var mycompo = _LCC.FindOrLoad_Component(containerName.c_str(),"SalomeTestComponent"); @@ -87,7 +94,22 @@ int main (int argc, char * argv[]) ASSERT(!CORBA::is_nil(m2)); SCRUTE(m2->instanceName()); + cout << m2->instanceName() << endl; MESSAGE("Coucou " << m2->Coucou(1L)); + + Engines::Component_var mycompo3 = _LCC.FindOrLoad_Component("totoPy","SALOME_TestComponentPy"); + ASSERT(!CORBA::is_nil(mycompo3)); + Engines::TestComponent_var m3 = Engines::TestComponent::_narrow(mycompo3); + ASSERT(!CORBA::is_nil(m3)); + cout << m3->instanceName() << endl; + + string containerName4 = containerName + "/titiPy"; + Engines::Component_var mycompo4 = _LCC.FindOrLoad_Component(containerName4.c_str(),"SALOME_TestComponentPy"); + ASSERT(!CORBA::is_nil(mycompo4)); + Engines::TestComponent_var m4 = Engines::TestComponent::_narrow(mycompo4); + ASSERT(!CORBA::is_nil(m4)); + cout << m4->instanceName() << endl; + } catch(CORBA::COMM_FAILURE& ex) { diff --git a/src/Logger/SALOME_Trace.hxx b/src/Logger/SALOME_Trace.hxx index e0019a1f5..4652aeaa4 100644 --- a/src/Logger/SALOME_Trace.hxx +++ b/src/Logger/SALOME_Trace.hxx @@ -11,7 +11,7 @@ #if !defined(AFX_LOGGER_H__96F2A3AB_F6F8_11D6_BFA6_000476A0958C__INCLUDED_) #define AFX_LOGGER_H__96F2A3AB_F6F8_11D6_BFA6_000476A0958C__INCLUDED_ -#include +#include #include "Logger.hh" //these declarations for files don't using OCC includes (for example HDF) diff --git a/src/NamingService/SALOME_NamingService.cxx b/src/NamingService/SALOME_NamingService.cxx index 2db7a59b5..e939d5341 100644 --- a/src/NamingService/SALOME_NamingService.cxx +++ b/src/NamingService/SALOME_NamingService.cxx @@ -1382,3 +1382,7 @@ void SALOME_NamingService::_list_directory_recurs(vector& myList, const } //---------------------------------------------------------------------- + +char * SALOME_NamingService::getIORaddr(){ + return _orb->object_to_string(_root_context); +} diff --git a/src/NamingService/SALOME_NamingService.hxx b/src/NamingService/SALOME_NamingService.hxx index e6ee89213..db9c39e17 100644 --- a/src/NamingService/SALOME_NamingService.hxx +++ b/src/NamingService/SALOME_NamingService.hxx @@ -97,6 +97,9 @@ public: virtual void Destroy_Directory(const char* Path) throw(ServiceUnreachable); + //! get IORstring naming service address + char * getIORaddr(); + protected: CORBA::ORB_ptr _orb; CosNaming::NamingContext_var _root_context, _current_context; diff --git a/src/SALOME_PYQT/Makefile.in b/src/SALOME_PYQT/Makefile.in index 6797d4dbf..a72114d91 100644 --- a/src/SALOME_PYQT/Makefile.in +++ b/src/SALOME_PYQT/Makefile.in @@ -34,12 +34,18 @@ SIP_SRC=$(CURDIR)/SalomePyQtcmodule.cc \ $(CURDIR)/sipSalomePyQtSalomePyQt.cc \ $(CURDIR)/sipSalomePyQtSALOME_Selection.cc +ifeq ($(SIP_VERS),new2) +MOC_SRC = SalomePyQtcmodule_moc.cxx +MOC_H = SalomePyQtcmodule.h +else +MOC_SRC = sipSalomePyQtProxySalomePyQt_moc.cxx +MOC_H = sipSalomePyQtProxySalomePyQt.h +endif + # Libraries targets LIB = libSalomePyQtcmodule.la -MOC_SRC = sipSalomePyQtProxySalomePyQt_moc.cxx - LIB_SRC += SalomePyQt.cxx SALOME_PYQT_GUI.cxx $(SIP_SRC) $(MOC_SRC) LIB_MOC = SALOME_PYQT_GUI.h @@ -59,7 +65,7 @@ LDFLAGS+= -lSalomeGUI -lqtcmodule $(SIP_SRC): $(SIP_FILES) $(SIP) $(SIP_FLAGS) $< -$(MOC_SRC): sipSalomePyQtProxySalomePyQt.h +$(MOC_SRC): $(MOC_H) $(MOC) $< -o $@ @CONCLUDE@ diff --git a/src/Utils/Utils_Identity.py b/src/Utils/Utils_Identity.py index 4f4cc4520..e73a5f596 100644 --- a/src/Utils/Utils_Identity.py +++ b/src/Utils/Utils_Identity.py @@ -57,3 +57,24 @@ class Identity: self._tc_start = time.time() self._cstart = time.ctime(self._tc_start) self._cdir = os.getcwd() + +def getapplipath(): + """ + Gives short application path (the complete path is $HOME/$APPLI) + """ + return os.environ.get("APPLI",".salome_"+versnb) + +try: + file = open(os.path.join(os.environ["KERNEL_ROOT_DIR"],"bin","salome","VERSION"), "r") + s = file.readline() + versnb = string.strip(string.split(s, ":")[1]) + dirname=".salome_"+versnb +except: + versnb = "" + dirname=".salome" + +def version(): + """ + Gives salome version number + """ + return versnb -- 2.39.2