From: abn Date: Mon, 29 Jun 2015 11:35:12 +0000 (+0200) Subject: Added create_python_service_instance() method to Container. X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=cdbdf1494c3d9e542cc0b14b3280483b73385b10;p=modules%2Fyacs.git Added create_python_service_instance() method to Container. Allows to load a simple Python servant in a given container, not inheriting from the EngineComponent hierarchy. --- diff --git a/idl/SALOME_Component.idl b/idl/SALOME_Component.idl index ce76cda16..57063c9dc 100644 --- a/idl/SALOME_Component.idl +++ b/idl/SALOME_Component.idl @@ -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. diff --git a/src/Container/Container_i.cxx b/src/Container/Container_i.cxx index b1db97262..18e51ac20 100644 --- a/src/Container/Container_i.cxx +++ b/src/Container/Container_i.cxx @@ -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) /*! diff --git a/src/Container/SALOME_Container_i.hxx b/src/Container/SALOME_Container_i.hxx index e07ed20a9..1e437c1c1 100644 --- a/src/Container/SALOME_Container_i.hxx +++ b/src/Container/SALOME_Container_i.hxx @@ -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