-// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
//
-// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-// SALOME_ParallelContainer : implementation of container and engine for ParallelKernel
// File : SALOME_ParallelContainer_i.cxx
// Author : André RIBES, EDF
#include <Python.h>
#include "Container_init_python.hxx"
-using namespace std;
bool _Sleeping = false ;
//=============================================================================
Engines_Parallel_Container_i::Engines_Parallel_Container_i (CORBA::ORB_ptr orb,
- char * ior,
- int rank,
- PortableServer::POA_ptr poa,
- std::string containerName,
- bool isServantAloneInProcess) :
+ char * ior,
+ int rank,
+ PortableServer::POA_ptr poa,
+ std::string containerName,
+ bool isServantAloneInProcess) :
InterfaceParallel_impl(orb,ior,rank),
Engines::PACO_Container_serv(orb,ior,rank),
Engines::PACO_Container_base_serv(orb,ior,rank),
/* For each seq component contained in this container
* tell it to self-destroy
*/
- std::map<std::string, Engines::Component_var>::iterator itm;
+ std::map<std::string, Engines::EngineComponent_var>::iterator itm;
for (itm = _listInstances_map.begin(); itm != _listInstances_map.end(); itm++)
{
try
//=============================================================================
bool
-Engines_Parallel_Container_i::load_component_Library(const char* componentName)
+Engines_Parallel_Container_i::load_component_Library(const char* componentName, CORBA::String_out reason)
{
+ reason=CORBA::string_dup("");
+
MESSAGE("Begin of load_component_Library : " << componentName)
bool ret = false;
std::string aCompName = componentName;
#ifndef WIN32
- string impl_name = string ("lib") + aCompName + string("Engine.so");
+ std::string impl_name = string ("lib") + aCompName + string("Engine.so");
#else
- string impl_name = aCompName + string("Engine.dll");
+ std::string impl_name = aCompName + string("Engine.dll");
#endif
_numInstanceMutex.lock(); // lock to be alone
PyObject *globals = PyModule_GetDict(mainmod);
PyObject *pyCont = PyDict_GetItemString(globals, "pyCont");
PyObject *result = PyObject_CallMethod(pyCont,
- (char*)"import_component",
- (char*)"s",componentName);
+ (char*)"import_component",
+ (char*)"s",componentName);
std::string ret_p= PyString_AsString(result);
Py_XDECREF(result);
Py_RELEASE_NEW_THREAD;
* \return a loaded component
*/
//=============================================================================
-
-Engines::Component_ptr
+Engines::EngineComponent_ptr
Engines_Parallel_Container_i::create_component_instance(const char*genericRegisterName,
- CORBA::Long studyId)
+ CORBA::Long studyId)
+{
+ Engines::FieldsDict_var env = new Engines::FieldsDict;
+ char* reason;
+ Engines::EngineComponent_ptr compo = create_component_instance_env(genericRegisterName,studyId,env, reason);
+ CORBA::string_free(reason);
+ return compo;
+}
+
+//=============================================================================
+//! Create a new component instance
+/*!
+ * CORBA method: Creates a new servant instance of a component.
+ * The servant registers itself to naming service and Registry.
+ * \param genericRegisterName Name of the component instance to register
+ * in Registry & Name Service (without _inst_n suffix)
+ * \param studyId 0 for multiStudy instance,
+ * study Id (>0) otherwise
+ * \param env dict of environment variables
+ * \return a loaded component
+ */
+//=============================================================================
+
+Engines::EngineComponent_ptr
+Engines_Parallel_Container_i::create_component_instance_env(const char*genericRegisterName,
+ CORBA::Long studyId,
+ const Engines::FieldsDict& env,
+ CORBA::String_out reason)
{
MESSAGE("Begin of create_component_instance in node : " << getMyRank());
+ reason=CORBA::string_dup("");
if (studyId < 0)
{
INFOS("studyId must be > 0 for mono study instance, =0 for multiStudy");
- return Engines::Component::_nil() ;
+ return Engines::EngineComponent::_nil() ;
}
std::string aCompName = genericRegisterName;
#ifndef WIN32
- string impl_name = string ("lib") + aCompName +string("Engine.so");
+ std::string impl_name = string ("lib") + aCompName +string("Engine.so");
#else
- string impl_name = aCompName +string("Engine.dll");
+ std::string impl_name = aCompName +string("Engine.dll");
#endif
_numInstanceMutex.lock();
{
std::cerr << "Component library is not loaded or imported ! lib was : " << aCompName << std::endl;
_numInstanceMutex.unlock();
- return Engines::Component::_nil();
+ return Engines::EngineComponent::_nil();
}
- Engines::Component_var iobject = Engines::Component::_nil();
+ Engines::EngineComponent_var iobject = Engines::EngineComponent::_nil();
if (type_of_lib == "cpp")
iobject = createCPPInstance(aCompName, handle, studyId);
else
*/
//=============================================================================
-Engines::Component_ptr Engines_Parallel_Container_i::find_component_instance( const char* registeredName,
- CORBA::Long studyId)
+Engines::EngineComponent_ptr Engines_Parallel_Container_i::find_component_instance( const char* registeredName,
+ CORBA::Long studyId)
{
- Engines::Component_var anEngine = Engines::Component::_nil();
- map<string,Engines::Component_var>::iterator itm =_listInstances_map.begin();
+ Engines::EngineComponent_var anEngine = Engines::EngineComponent::_nil();
+ std::map<std::string,Engines::EngineComponent_var>::iterator itm =_listInstances_map.begin();
while (itm != _listInstances_map.end())
{
- string instance = (*itm).first;
+ std::string instance = (*itm).first;
SCRUTE(instance);
if (instance.find(registeredName) == 0)
{
anEngine = (*itm).second;
if (studyId == anEngine->getStudyId())
{
- return anEngine._retn();
+ return anEngine._retn();
}
}
itm++;
*/
//=============================================================================
-Engines::Component_ptr Engines_Parallel_Container_i::load_impl( const char* genericRegisterName,
- const char* componentName )
+Engines::EngineComponent_ptr Engines_Parallel_Container_i::load_impl( const char* genericRegisterName,
+ const char* componentName )
{
- Engines::Component_var iobject = Engines::Component::_nil();
- if (load_component_Library(genericRegisterName))
+ Engines::EngineComponent_var iobject = Engines::EngineComponent::_nil();
+ char* reason;
+ if (load_component_Library(genericRegisterName,reason))
iobject = find_or_create_instance(genericRegisterName);
+ CORBA::string_free(reason);
return iobject._retn();
}
*/
//=============================================================================
-void Engines_Parallel_Container_i::remove_impl(Engines::Component_ptr component_i)
+void Engines_Parallel_Container_i::remove_impl(Engines::EngineComponent_ptr component_i)
{
ASSERT(!CORBA::is_nil(component_i));
- string instanceName = component_i->instanceName();
+ std::string instanceName = component_i->instanceName();
_numInstanceMutex.lock() ; // lock to be alone (stl container write)
// Test if the component is in this container
- std::map<std::string, Engines::Component_var>::iterator itm;
+ std::map<std::string, Engines::EngineComponent_var>::iterator itm;
itm = _listInstances_map.find(instanceName);
if (itm != _listInstances_map.end())
{
MESSAGE("WARNING FINALIZE DOES CURRENTLY NOTHING !!!");
// (see decInstanceCnt, load_component_Library)
- //map<string, void *>::iterator ith;
+ //std::map<std::string, void *>::iterator ith;
//for (ith = _toRemove_map.begin(); ith != _toRemove_map.end(); ith++)
//{
// void *handle = (*ith).second;
- // string impl_name= (*ith).first;
+ // std::string impl_name= (*ith).first;
// if (handle)
// {
// SCRUTE(handle);
bool Engines_Parallel_Container_i::Kill_impl()
{
MESSAGE("Engines_Parallel_Container_i::Kill() my pid is "<< _pid
- << " my containerName is " << _containerName.c_str()
- << " my machineName is " << _hostname.c_str());
+ << " my containerName is " << _containerName.c_str()
+ << " my machineName is " << _hostname.c_str());
INFOS("===============================================================");
INFOS("= REMOVE calls to Kill_impl in C++ container =");
INFOS("===============================================================");
Engines::fileRef_ptr
Engines_Parallel_Container_i::createFileRef(const char* origFileName)
{
- string origName(origFileName);
+ std::string origName(origFileName);
Engines::fileRef_var theFileRef = Engines::fileRef::_nil();
if (origName[0] != '/')
*/
//=============================================================================
-Engines::Component_ptr
-Engines_Parallel_Container_i::find_or_create_instance(string genericRegisterName)
+Engines::EngineComponent_ptr
+Engines_Parallel_Container_i::find_or_create_instance(std::string genericRegisterName)
{
- Engines::Component_var iobject = Engines::Component::_nil();
+ Engines::EngineComponent_var iobject = Engines::EngineComponent::_nil();
try
{
- string aGenRegisterName = genericRegisterName;
+ std::string aGenRegisterName = genericRegisterName;
// --- find a registered instance in naming service, or create
- string component_registerBase = _containerName + "/" + aGenRegisterName;
+ std::string component_registerBase = _containerName + "/" + aGenRegisterName;
CORBA::Object_var obj = _NS->ResolveFirst(component_registerBase.c_str());
if (CORBA::is_nil( obj ))
{
iobject = create_component_instance(genericRegisterName.c_str(),
- 0); // force multiStudy instance here !
+ 0); // force multiStudy instance here !
}
else
{
- iobject = Engines::Component::_narrow(obj) ;
+ iobject = Engines::EngineComponent::_narrow(obj) ;
Engines_Component_i *servant = dynamic_cast<Engines_Component_i*>(_poa->reference_to_servant(iobject));
ASSERT(servant)
int studyId = servant->getStudyId();
ASSERT (studyId >= 0);
if (studyId != 0) // monoStudy instance: NOK
{
- iobject = Engines::Component::_nil();
- INFOS("load_impl & find_component_instance methods "
- << "NOT SUITABLE for mono study components");
+ iobject = Engines::EngineComponent::_nil();
+ INFOS("load_impl & find_component_instance methods "
+ << "NOT SUITABLE for mono study components");
}
}
}
* component_registerName = /Containers/cli76ce/FactoryServer/COMPONENT_inst_1
*/
//=============================================================================
-Engines::Component_ptr
-Engines_Parallel_Container_i::createPythonInstance(string genericRegisterName, int studyId)
+Engines::EngineComponent_ptr
+Engines_Parallel_Container_i::createPythonInstance(std::string genericRegisterName, int studyId)
{
- Engines::Component_var iobject = Engines::Component::_nil();
+ Engines::EngineComponent_var iobject = Engines::EngineComponent::_nil();
int numInstance = _numInstance;
char aNumI[12];
sprintf( aNumI , "%d" , numInstance ) ;
- string instanceName = genericRegisterName + "_inst_" + aNumI ;
- string component_registerName = _containerName + "/" + instanceName;
+ std::string instanceName = genericRegisterName + "_inst_" + aNumI ;
+ std::string component_registerName = _containerName + "/" + instanceName;
Py_ACQUIRE_NEW_THREAD;
PyObject *mainmod = PyImport_AddModule("__main__");
PyObject *globals = PyModule_GetDict(mainmod);
PyObject *pyCont = PyDict_GetItemString(globals, "pyCont");
PyObject *result = PyObject_CallMethod(pyCont,
- (char*)"create_component_instance",
- (char*)"ssl",
- genericRegisterName.c_str(),
- instanceName.c_str(),
- studyId);
- std::string iors = PyString_AsString(result);
+ (char*)"create_component_instance",
+ (char*)"ssl",
+ genericRegisterName.c_str(),
+ instanceName.c_str(),
+ studyId);
+ const char *ior;
+ const char *error;
+ PyArg_ParseTuple(result,"ss", &ior, &error);
+ string iors = ior;
Py_DECREF(result);
Py_RELEASE_NEW_THREAD;
if( iors!="" )
{
CORBA::Object_var obj = _orb->string_to_object(iors.c_str());
- iobject = Engines::Component::_narrow(obj);
+ iobject = Engines::EngineComponent::_narrow(obj);
_listInstances_map[instanceName] = iobject;
}
else
* component_registerName = /Containers/cli76ce/FactoryServer/COMPONENT_inst_1
*/
//=============================================================================
-Engines::Component_ptr
-Engines_Parallel_Container_i::createCPPInstance(string genericRegisterName,
- void *handle,
- int studyId)
+Engines::EngineComponent_ptr
+Engines_Parallel_Container_i::createCPPInstance(std::string genericRegisterName,
+ void *handle,
+ int studyId)
{
MESSAGE("Entering Engines_Parallel_Container_i::createCPPInstance");
// --- find the factory
- string aGenRegisterName = genericRegisterName;
- string factory_name = aGenRegisterName + string("Engine_factory");
+ std::string aGenRegisterName = genericRegisterName;
+ std::string factory_name = aGenRegisterName + string("Engine_factory");
typedef PortableServer::ObjectId * (*FACTORY_FUNCTION_2)
(CORBA::ORB_ptr,
#ifndef WIN32
INFOS("dlerror() result is : " << dlerror());
#endif
- return Engines::Component::_nil() ;
+ return Engines::EngineComponent::_nil() ;
}
// --- create instance
- Engines::Component_var iobject = Engines::Component::_nil() ;
+ Engines::EngineComponent_var iobject = Engines::EngineComponent::_nil() ;
try
{
int numInstance = _numInstance;
char aNumI[12];
sprintf( aNumI , "%d" , numInstance );
- string instanceName = aGenRegisterName + "_inst_" + aNumI;
- string component_registerName =
+ std::string instanceName = aGenRegisterName + "_inst_" + aNumI;
+ std::string component_registerName =
_containerName + "/" + instanceName;
// --- Instanciate required CORBA object
PortableServer::ObjectId *id; //not owner, do not delete (nore use var)
id = (Component_factory) ( _orb, _poa, _id, instanceName.c_str(),
- aGenRegisterName.c_str() );
+ aGenRegisterName.c_str() );
if (id == NULL)
{
INFOS("Factory function returns NULL !");
// --- get reference & servant from id
CORBA::Object_var obj = _poa->id_to_reference(*id);
- iobject = Engines::Component::_narrow(obj);
+ iobject = Engines::EngineComponent::_narrow(obj);
Engines_Component_i *servant =
dynamic_cast<Engines_Component_i*>(_poa->reference_to_servant(iobject));
void
Engines_Parallel_Container_i::create_paco_component_node_instance(const char* componentName,
- const char* proxy_containerName,
- CORBA::Long studyId)
+ const char* proxy_containerName,
+ CORBA::Long studyId)
{
// Init de la méthode
char * proxy_ior;
- Engines::Component_PaCO_var work_node;
+ Engines::EngineComponent_PaCO_var work_node;
std::string aCompName = componentName;
std::string _proxy_containerName = proxy_containerName;
// Step 1 : Get proxy !
string component_registerName = _proxy_containerName + "/" + instanceName;
CORBA::Object_var temp = _NS->Resolve(component_registerName.c_str());
- Engines::Component_var obj_proxy = Engines::Component::_narrow(temp);
+ Engines::EngineComponent_var obj_proxy = Engines::EngineComponent::_narrow(temp);
if (CORBA::is_nil(obj_proxy))
{
INFOS("Proxy reference from NamingService is nil !");
{
char aNumI2[12];
sprintf(aNumI2 , "%d" , getMyRank()) ;
- string instanceName = aCompName + "_inst_" + aNumI + "_work_node_" + aNumI2;
- string component_registerName = _containerName + "/" + instanceName;
+ std::string instanceName = aCompName + "_inst_" + aNumI + "_work_node_" + aNumI2;
+ std::string component_registerName = _containerName + "/" + instanceName;
// --- Instanciate work node
PortableServer::ObjectId *id ; //not owner, do not delete (nore use var)
// --- get reference & servant from id
CORBA::Object_var obj = _poa->id_to_reference(*id);
- work_node = Engines::Component_PaCO::_narrow(obj) ;
+ work_node = Engines::EngineComponent_PaCO::_narrow(obj) ;
if (CORBA::is_nil(work_node))
{
INFOS("work_node reference from factory is nil !");
*/
//=============================================================================
-void Engines_Parallel_Container_i::decInstanceCnt(string genericRegisterName)
+void Engines_Parallel_Container_i::decInstanceCnt(std::string genericRegisterName)
{
if(_cntInstances_map.count(genericRegisterName) !=0 )
{
- string aGenRegisterName =genericRegisterName;
+ std::string aGenRegisterName =genericRegisterName;
MESSAGE("Engines_Parallel_Container_i::decInstanceCnt " << aGenRegisterName);
ASSERT(_cntInstances_map[aGenRegisterName] > 0);
_numInstanceMutex.lock(); // lock to be alone
SCRUTE(_cntInstances_map[aGenRegisterName]);
if (_cntInstances_map[aGenRegisterName] == 0)
{
- string impl_name =
- Engines_Component_i::GetDynLibraryName(aGenRegisterName.c_str());
+ std::string impl_name =
+ Engines_Component_i::GetDynLibraryName(aGenRegisterName.c_str());
SCRUTE(impl_name);
void* handle = _library_map[impl_name];
ASSERT(handle);
}
}
+/*! \brief create a PyNode object to execute remote python code
+ * \param nodeName the name of the node
+ * \param code the python code to load
+ * \return the PyNode
+ */
+Engines::PyNode_ptr
+Engines_Parallel_Container_i::createPyNode(const char* nodeName, const char* code)
+{
+ INFOS("Python component not yet implemented");
+ Engines::PyNode_var node= Engines::PyNode::_nil();
+ return node._retn();
+}
+
+Engines::PyScriptNode_ptr
+Engines_Parallel_Container_i::createPyScriptNode(const char* nodeName, const char* cod)
+{
+ INFOS("Python script node not yet implemented");
+ Engines::PyScriptNode_var node= Engines::PyScriptNode::_nil();
+ return node._retn();
+}
+
//=============================================================================
/*!
*
#ifndef WIN32
void SigIntHandler(int what , siginfo_t * siginfo ,
- void * toto ) {
+ void * toto ) {
//PAL9042 JR : during the execution of a Signal Handler (and of methods called through Signal Handlers)
// use of streams (and so on) should never be used because :
// streams of C++ are naturally thread-safe and use pthread_mutex_lock ===>
// MESSAGE("SigIntHandler BEGIN sleeping.") ;
int count = 0 ;
while( _Sleeping ) {
- sleep( 1 ) ;
- count += 1 ;
+ sleep( 1 ) ;
+ count += 1 ;
}
// MESSAGE("SigIntHandler LEAVE sleeping after " << count << " s.") ;
}
MESSAGE("SigIntHandler BEGIN sleeping.") ;
int count = 0 ;
while( _Sleeping ) {
- Sleep( 1000 ) ;
- count += 1 ;
+ Sleep( 1000 ) ;
+ count += 1 ;
}
MESSAGE("SigIntHandler LEAVE sleeping after " << count << " s.") ;
}
}
}
#endif
-