]> SALOME platform Git repositories - modules/yacs.git/commitdiff
Salome HOME
PR: merge from tag mergeto_HEAD_25Jan05
authorprascle <prascle>
Thu, 27 Jan 2005 14:07:02 +0000 (14:07 +0000)
committerprascle <prascle>
Thu, 27 Jan 2005 14:07:02 +0000 (14:07 +0000)
25 files changed:
Makefile.in
bin/envSalome.py [new file with mode: 0755]
bin/launchConfigureParser.py
bin/runSalome.py
bin/salomeConsole.py [new file with mode: 0755]
idl/SALOME_Component.idl
resources/KERNELCatalog.xml
salome_adm/unix/config_files/check_sip.m4
salome_adm/unix/make_commence.in
src/Container/Container_i.cxx
src/Container/SALOME_ContainerPy.py
src/Container/SALOME_Container_i.hxx
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/SALOME_LifeCycleCORBA.hxx
src/LifeCycleCORBA/TestLifeCycleCORBA.cxx
src/Logger/SALOME_Trace.hxx
src/NamingService/SALOME_NamingService.cxx
src/NamingService/SALOME_NamingService.hxx
src/SALOME_PYQT/Makefile.in
src/Utils/Utils_Identity.py

index ab8870626c6973b823d9a0c6502fd9497bf28f91..5c92e402e779095989ee492e830ebc35c5d90c73 100644 (file)
@@ -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 (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)
index 71781540164a504094444c0075af96fb1a22137b..b61515d1981e987c0269af4e6e16e8b0342145e3 100755 (executable)
@@ -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 <modulen>_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 <modulen>_ROOT_DIR must be set.
+    The module name (<modulen>) must be uppercase.
+    KERNEL_ROOT_DIR is mandatory.
     """
     sys.exit(1)
     pass
index 5fb5c006d8e5800c463e3afcae4451219aea7249..75a0cc9ae2f08d984f5afc20c636dfbb7620b510 100755 (executable)
@@ -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 (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 8760ae9dffd1616088d30ab04e39a05a4eb1ee53..f60922c42005cc289f2c19b486e948863700cfdc 100644 (file)
@@ -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
index 1208eb26ffa20b95f67d00b82d5064a39befa9fd..4bad252ff01031cbb83d0cdea0c5c8ce6b82c44a 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>
index 48a025918c32991048b7c7714351e774a0ed44a8..84c2beaf73829cdb40eff8f552fb44e7bd698962 100644 (file)
@@ -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)
 
index 7e5122adbc32a661ab6f7d2d315dd0f8df839258..620cfd9fffdf394f9c6c0ae1bdcf71609ab3fb71 100644 (file)
@@ -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@
index 301b56719d2ad9983d49eedec06f75c0e21d8bea..649a29b5e9cb6a9d47f1ff2c8275b84bc2926ffa 100644 (file)
@@ -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);
+}
+
index 417599eb98239f851e815c623d3e94ab777f72d2..dbaa9f65ecb3adf9d5fa81ff9d5317cd357ac930 100755 (executable)
@@ -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
 
     #-------------------------------------------------------------------------
 
index 249f806574ac41fe79d104ae10b24c6540c97782..0aa0658ae969cba2c41af7363e790ab0adb9a994 100644 (file)
@@ -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 (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 82c3649368b57350d234e7dee3cbe816f6850800..5c9c3796ab829676d2882ed5ee2c636f73353e02 100644 (file)
@@ -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"
index 64daf70e88ce3d675a31478afc25be604fda4df9..3b825582f7d785653852de912d71719af4d8c3d5 100644 (file)
@@ -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@
 
index 466fa70d6e92e6f17cfd4a879c339dc661fee479..af5848155456dab9d351cc21659f2bee223306c6 100644 (file)
@@ -33,6 +33,7 @@
 
 #include "OpUtil.hxx"
 #include "utilities.h"
+#include "Launchers.hxx"
 
 #include <ServiceUnreachable.hxx>
 
@@ -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();
+}
index a7a145c275a62210785d33b4b8bea543b758967b..ca91a238ffaf2f72756a930a699929b543d6ee1e 100644 (file)
@@ -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
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 e0019a1f5c57023376268c5bc35e99e692743b30..4652aeaa4aa8b3e127b6eed9e2c27ad4c90ee38f 100644 (file)
@@ -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 <strstream.h>
+#include <strstream>
 #include "Logger.hh"
 
 //these declarations for files don't using OCC includes (for example HDF)
index 2db7a59b5e9c2f4ed207c8f9f910adb928fae569..e939d53418a1be1bff596f676c1f5d4aea076a68 100644 (file)
@@ -1382,3 +1382,7 @@ void SALOME_NamingService::_list_directory_recurs(vector<string>& myList, const
 }
 
 //----------------------------------------------------------------------
+
+char * SALOME_NamingService::getIORaddr(){
+   return _orb->object_to_string(_root_context);
+}
index e6ee8921324155cb07583994ae3606e1e2844a91..db9c39e17865a0a55a776342536b465ec57bfac2 100644 (file)
@@ -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;
index 6797d4dbf28384b5ed16f8f555535438e688bc03..a72114d917e12718b6412d09952bad9ff588f50c 100644 (file)
@@ -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@
index 4f4cc4520cf7d2febefa83ab9acaefad102dba09..e73a5f59661901e271494db6c8ca2ec04055873a 100644 (file)
@@ -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