--- /dev/null
+#!/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)
--- /dev/null
+#!/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
<constraint>hostname = muna</constraint>
</component>
+ <component>
+ <component-name>SalomeTestComponent</component-name>
+ <component-username>SalomeTestComponent</component-username>
+ <component-type>Other</component-type>
+ <component-author>NRI</component-author>
+ <component-version>2.1.0</component-version>
+ <component-comment>GUI Neutral Context</component-comment>
+ <component-multistudy>1</component-multistudy>
+ <constraint>'linux' ~ OS</constraint>
+ </component>
+ <component>
+ <component-name>SALOME_TestComponentPy</component-name>
+ <component-username>SALOME_TestComponentPy</component-username>
+ <component-type>Other</component-type>
+ <component-author>NRI</component-author>
+ <component-version>2.1.0</component-version>
+ <component-comment>GUI Neutral Context</component-comment>
+ <component-multistudy>1</component-multistudy>
+ <constraint>'linux' ~ OS</constraint>
+ </component>
</component-list>
</begin-catalog>
--- /dev/null
+#include <Launchers.hxx>
+
+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);
+}
+
--- /dev/null
+#include <Python.h>
+#define elDEBUG 0
+
+PyObject * getLauncher(char* );
+void Launcher_Slaunch(PyObject * objId, char*, char* );
+
--- /dev/null
+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
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 :
@COMMENCE@
-EXPORT_HEADERS = SALOME_LifeCycleCORBA.hxx
+EXPORT_HEADERS = SALOME_LifeCycleCORBA.hxx
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
BIN_CLIENT_IDL = SALOME_Component.idl SALOME_TestComponent.idl \
SALOME_ModuleCatalog.idl
-LDFLAGS += -lSalomeNS -lOpUtil -lSALOMELocalTrace
+CPPFLAGS+= $(PYTHON_INCLUDES)
+LDFLAGS += -lSalomeNS -lOpUtil -lSALOMELocalTrace -lSALOMETraceCollector
+LIBS += $(PYTHON_LIBS)
@CONCLUDE@
#include "OpUtil.hxx"
#include "utilities.h"
+#include "Launchers.hxx"
#include <ServiceUnreachable.hxx>
const string aComputerContainer ,
const string theComputer ,
const string theContainer ) {
- Engines::Container_var aContainer = FindContainer( aComputerContainer.c_str() ) ;
- Engines::Container_var aFactoryServer ;
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 ;
}
- if ( !CORBA::is_nil( aContainer ) ) {
- return aContainer ;
+
+ string addr=_NS->getIORaddr();
+ string CMD="SALOME_Container";
+ if ( pyCont ) {
+ CMD="SALOME_ContainerPy.py";
}
- else {
- string FactoryServer = theComputer ;
- if ( pyCont ) {
- FactoryServer += "/FactoryServerPy" ;
- }
- else {
- FactoryServer += "/FactoryServer" ;
- }
- aFactoryServer = FindContainer( FactoryServer.c_str() ) ;
- if ( CORBA::is_nil( aFactoryServer ) ) {
-// rsh -n ikkyo /export/home/rahuel/SALOME_ROOT/bin/runSession SALOME_Container -ORBInitRef NameService=corbaname::dm2s0017:1515 &
- string rsh( "" ) ;
- if ( theComputer!= GetHostname() ) {
- rsh += "rsh -n " ;
- rsh += theComputer ;
- rsh += " " ;
- }
- string path = ComputerPath( theComputer.c_str() ) ;
- SCRUTE( path ) ;
- if ( path[0] != '\0' ) {
- rsh += path ;
- rsh += "/../bin/" ;
- }
- rsh += "runSession " ;
- if ( pyCont ) {
- rsh += "SALOME_ContainerPy.py " ;
- rsh += "FactoryServerPy -" ;
- }
- else {
- rsh += "SALOME_Container " ;
- rsh += "FactoryServer -" ;
- }
- string omniORBcfg( getenv( "OMNIORB_CONFIG" ) ) ;
- ifstream omniORBfile( omniORBcfg.c_str() ) ;
- char ORBInitRef[12] ;
- char nameservice[132] ;
- omniORBfile >> ORBInitRef ;
- rsh += ORBInitRef ;
- rsh += " " ;
- omniORBfile >> nameservice ;
- omniORBfile.close() ;
- char * bsn = strchr( nameservice , '\n' ) ;
- if ( bsn ) {
- bsn[ 0 ] = '\0' ;
- }
- rsh += nameservice ;
- if ( pyCont ) {
- rsh += " > /tmp/FactoryServerPy_" ;
- }
- else {
- rsh += " > /tmp/FactoryServer_" ;
- }
- rsh += theComputer ;
- rsh += ".log 2>&1 &" ;
- SCRUTE( rsh );
- int status = system( rsh.c_str() ) ;
- if (status == -1) {
- MESSAGE("SALOME_LifeCycleCORBA::StartOrFindContainer rsh failed (system command status -1)") ;
- }
- else if (status == 217) {
- MESSAGE("SALOME_LifeCycleCORBA::StartOrFindContainer rsh failed (system command status 217)") ;
- }
- else {
- int count = 21 ;
- while ( CORBA::is_nil( aFactoryServer ) && count ) {
- sleep( 1 ) ;
- count-- ;
- if ( count != 10 )
+ 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( FactoryServer.c_str() ) ;
- }
- if ( CORBA::is_nil( aFactoryServer ) ) {
- MESSAGE("SALOME_LifeCycleCORBA::StartOrFindContainer rsh failed") ;
- }
- else if ( strcmp( theComputer.c_str() , GetHostname().c_str() ) ) {
- _FactoryServer = aFactoryServer ;
- }
- }
- }
- if ( !CORBA::is_nil( aFactoryServer ) ) {
- if ( strcmp( theContainer.c_str() , "FactoryServer" ) ||
- strcmp( theContainer.c_str() , "FactoryServerPy" ) ) {
- MESSAGE("Container not found ! trying to start " << aComputerContainer);
- Engines::Container_var myContainer = aFactoryServer->start_impl( theContainer.c_str() ) ;
- if ( !CORBA::is_nil( myContainer ) ) {
- MESSAGE("Container " << aComputerContainer << " started");
- return myContainer ;
- }
- else {
- MESSAGE("Container " << aComputerContainer << " NOT started");
- }
- }
- else {
- MESSAGE("Container " << aComputerContainer << " started");
- return aFactoryServer ;
- }
- }
+ aFactoryServer = FindContainer( aComputerContainer.c_str() ) ;
+ }
+ if ( !CORBA::is_nil( aFactoryServer ) ) {
+ return aFactoryServer;
}
+ MESSAGE("SALOME_LifeCycleCORBA::StartOrFindContainer rsh failed") ;
return Engines::Container::_nil();
}
// Module : SALOME
// $Header$
-#include "utilities.h"
#include <iostream>
#include <unistd.h>
#include <SALOMEconfig.h>
#include CORBA_CLIENT_HEADER(SALOME_TestComponent)
#include "SALOME_NamingService.hxx"
#include "SALOME_LifeCycleCORBA.hxx"
+#include "utilities.h"
+#include "SALOMETraceCollector.hxx"
#include <OpUtil.hxx>
+
using namespace std;
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") ;
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");
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)
{
_current_context = _ref_context ;
}
//----------------------------------------------------------------------
+
+char * SALOME_NamingService::getIORaddr(){
+ return _orb->object_to_string(_root_context);
+}
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;