]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
CCAR: Update of start container modifications. BR_CCAR_V220a1
authorcaremoli <caremoli>
Mon, 24 Jan 2005 13:08:28 +0000 (13:08 +0000)
committercaremoli <caremoli>
Mon, 24 Jan 2005 13:08:28 +0000 (13:08 +0000)
Adding files forgotten in previous commit
Adding C++ functionnality (wrap of python module)

12 files changed:
bin/envSalome.py [new file with mode: 0755]
bin/salomeConsole.py [new file with mode: 0755]
resources/KERNELCatalog.xml
src/LifeCycleCORBA/Launchers.cxx [new file with mode: 0644]
src/LifeCycleCORBA/Launchers.hxx [new file with mode: 0644]
src/LifeCycleCORBA/Launchers.py [new file with mode: 0644]
src/LifeCycleCORBA/LifeCycleCORBA.py
src/LifeCycleCORBA/Makefile.in
src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx
src/LifeCycleCORBA/TestLifeCycleCORBA.cxx
src/NamingService/SALOME_NamingService.cxx
src/NamingService/SALOME_NamingService.hxx

diff --git a/bin/envSalome.py b/bin/envSalome.py
new file mode 100755 (executable)
index 0000000..3eacc0c
--- /dev/null
@@ -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/salomeConsole.py b/bin/salomeConsole.py
new file mode 100755 (executable)
index 0000000..03c0a5e
--- /dev/null
@@ -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
index c0d046504edb48917b2e694a5e856e600d7be0cc..1edacc08b168440bc2719b9ba3d1ba9910d957db 100644 (file)
 
        <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>
diff --git a/src/LifeCycleCORBA/Launchers.cxx b/src/LifeCycleCORBA/Launchers.cxx
new file mode 100644 (file)
index 0000000..f362246
--- /dev/null
@@ -0,0 +1,79 @@
+#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);
+}
+
diff --git a/src/LifeCycleCORBA/Launchers.hxx b/src/LifeCycleCORBA/Launchers.hxx
new file mode 100644 (file)
index 0000000..f402b7e
--- /dev/null
@@ -0,0 +1,6 @@
+#include <Python.h>
+#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 (file)
index 0000000..0888b17
--- /dev/null
@@ -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
index c6106dcb2479a0adb7aa6515fe878174a734b63e..79fa9cb7e5a13218e64a5008cbaed5159ef840fc 100644 (file)
@@ -175,6 +175,8 @@ class LifeCycleCORBA:
     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 :
index 8926e289a7da1bfcdd15c540a15f42ef0ae598b0..c75b9d1f2d7555571ba5548e490a7e8ba4debfbc 100644 (file)
@@ -34,14 +34,14 @@ VPATH=.:@srcdir@:@top_srcdir@/idl
 
 @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
 
@@ -51,7 +51,9 @@ BIN_SRC =
 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@
 
index 7908d60aead9ffa91c5c1924cdf0082d586114a3..05a4afcfaace7c754b448dfc8f5ade43cf456b73 100644 (file)
@@ -33,6 +33,7 @@
 
 #include "OpUtil.hxx"
 #include "utilities.h"
+#include "Launchers.hxx"
 
 #include <ServiceUnreachable.hxx>
 
@@ -139,117 +140,52 @@ Engines::Container_var SALOME_LifeCycleCORBA::FindOrStartContainer(
                                               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();
 }
 
index 603c328148ad173597652aa19d50c879e23ce426..49e3b28b07e46be03eedeefb80b7573e1ff38ddc 100644 (file)
@@ -26,7 +26,6 @@
 //  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[])
@@ -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)
     {
index 07b0e93423de3be5914a2aa34133d8f965a79dae..ffcb52224ba305dac8533cfcfd37851d72d28286 100644 (file)
@@ -1311,3 +1311,7 @@ SALOME_NamingService::_current_directory(char** result_path,
   _current_context = _ref_context ; 
 }
 //----------------------------------------------------------------------
+
+char * SALOME_NamingService::getIORaddr(){
+   return _orb->object_to_string(_root_context);
+}
index 4504e6ec7bdd71d58d59a3a446d7e0757d791a7e..57f9e4b10cad6876919549c092eca19cd8e2e3dd 100644 (file)
@@ -93,6 +93,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;