]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Added create_python_service_instance() method to Container. abn/pvserver_service
authorabn <adrien.bruneton@cea.fr>
Mon, 29 Jun 2015 11:35:12 +0000 (13:35 +0200)
committerabn <adrien.bruneton@cea.fr>
Mon, 29 Jun 2015 11:35:12 +0000 (13:35 +0200)
Allows to load a simple Python servant in a given container, not inheriting
from the EngineComponent hierarchy.

idl/SALOME_Component.idl
src/Container/Container_i.cxx
src/Container/SALOME_Container_i.hxx

index ce76cda16aea8a34791a59cbb950f96487bb7275..57063c9dcb12b4cef9448ae832b220e78e93869f 100644 (file)
@@ -102,6 +102,21 @@ module Engines
     Engines::EngineComponent create_component_instance(in string componentName,
                                                        in long studyId);
 
+    //! Create a new Python servant instance of a generic service.
+        /*!
+          This simply loads the service in the current container by importing the
+          corresponding Python module. 
+          Warning: no internal registration is done, so it is up to the caller to 
+          manage the various instanciation.  
+          \param serviceName Name of the service
+           
+                                >0 otherwise (== study id)
+          \param reason  in case of error (return void string) a string explaining the error
+          \return the IOR of the loaded service.
+        */
+    string create_python_service_instance(in string serviceName,
+                                          out string reason);
+    
     //! Create a new servant instance of a component with environment variables specified.
     /*!
       Component library must be loaded.
index b1db972620f75a605d0d20f8a02894340800832e..18e51ac2081f67943448d1a19d428b9603770140 100644 (file)
@@ -958,6 +958,40 @@ Engines_Container_i::createPythonInstance(std::string CompName, int studyId,
   return iobject._retn();
 }
 
+char *
+Engines_Container_i::create_python_service_instance(const char * CompName,
+                                                    CORBA::String_out reason)
+{
+  CORBA::Object_var object = CORBA::Object::_nil();
+
+  _numInstanceMutex.lock() ; // lock on the instance number
+  _numInstance++ ;
+  int numInstance = _numInstance ;
+  _numInstanceMutex.unlock() ;
+
+  char aNumI[12];
+  sprintf( aNumI , "%d" , numInstance ) ;
+  std::string instanceName = std::string(CompName) + "_inst_" + aNumI ;
+  std::string component_registerName = _containerName + "/" + instanceName;
+
+  PyGILState_STATE gstate = PyGILState_Ensure();
+  PyObject *result = PyObject_CallMethod(_pyCont,
+                                         (char*)"create_component_instance",
+                                         (char*)"ssl",
+                                         CompName,
+                                         instanceName.c_str(),
+                                         0);
+  const char *ior;
+  const char *error;
+  PyArg_ParseTuple(result,"ss", &ior, &error);
+  reason = CORBA::string_dup(error);
+  Py_DECREF(result);
+  PyGILState_Release(gstate);
+
+  return CORBA::string_dup(ior);
+}
+
+
 //=============================================================================
 //! Create a new component instance (C++ implementation)
 /*! 
index e07ed20a98cabe62ed460986bfb750dc54e8f8e5..1e437c1c16d9e789e01c342982d38a86ee91f1ad 100644 (file)
@@ -75,7 +75,12 @@ public:
   create_component_instance_env( const char* componentName,
                                  CORBA::Long studyId,          // 0 for multiStudy
                                  const Engines::FieldsDict& env,
-                                 CORBA::String_out reason); 
+                                 CORBA::String_out reason);
+
+  virtual char *
+  create_python_service_instance(const char* CompName,
+                                 CORBA::String_out reason);
+
   Engines::EngineComponent_ptr
   find_component_instance( const char* registeredName,
                            CORBA::Long studyId); // 0 for multiStudy