Salome HOME
updated copyright message
[modules/kernel.git] / src / MPIContainer / MPIContainer_i.cxx
index 0d1ff06baa8438317c65405121408b0a8cff8d5f..b2f30116dce03f2283fcca8dfa1e378c35e7256a 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -6,7 +6,7 @@
 // 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.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -19,8 +19,6 @@
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
-//  File   : MPIContainer_i.cxx
-//  Module : SALOME
 
 #include <iostream>
 #include <dlfcn.h>
@@ -48,7 +46,7 @@ Engines_MPIContainer_i::Engines_MPIContainer_i(CORBA::ORB_ptr orb,
                                                PortableServer::POA_ptr poa,
                                                char * containerName,
                                                int argc, char *argv[]) 
-  : Engines_Container_i(orb,poa,containerName,argc,argv,false)
+  : Engines_Container_i(orb,poa,containerName,argc,argv,nullptr,false)
 {
 
   _id = _poa->activate_object(this);
@@ -62,7 +60,7 @@ Engines_MPIContainer_i::Engines_MPIContainer_i(CORBA::ORB_ptr orb,
     _NS->init_orb( CORBA::ORB::_duplicate(_orb) ) ;
 
     std::string hostname = Kernel_Utils::GetHostname();
-    _containerName = _NS->BuildContainerNameForNS(containerName,hostname.c_str());
+    _containerName = SALOME_NamingService_Abstract::BuildContainerNameForNS(containerName,hostname.c_str());
     SCRUTE(_containerName);
     _NS->Register(pCont, _containerName.c_str());
 
@@ -121,7 +119,7 @@ bool Engines_MPIContainer_i::load_component_Library(const char* componentName, C
 {
   reason=CORBA::string_dup("");
 
-  pthread_t *th;
+  pthread_t *th = 0;
   if(_numproc == 0){
     th = new pthread_t[_nbproc];
     for(int ip=1;ip<_nbproc;ip++){
@@ -149,7 +147,11 @@ bool Engines_MPIContainer_i::Lload_component_Library(const char* componentName)
 
   // --- try dlopen C++ component
 
+#ifdef __APPLE__
+  std::string impl_name = std::string ("lib") + aCompName + std::string("Engine.dylib");
+#else
   std::string impl_name = std::string ("lib") + aCompName + std::string("Engine.so");
+#endif
   
   _numInstanceMutex.lock(); // lock to be alone 
   // (see decInstanceCnt, finalize_removal))
@@ -162,7 +164,7 @@ bool Engines_MPIContainer_i::Lload_component_Library(const char* componentName)
     }
   
   void* handle;
-  handle = dlopen( impl_name.c_str() , RTLD_LAZY ) ;
+  handle = dlopen( impl_name.c_str() , RTLD_LAZY | RTLD_GLOBAL ) ;
   if ( handle )
     {
       _library_map[impl_name] = handle;
@@ -198,7 +200,7 @@ bool Engines_MPIContainer_i::Lload_component_Library(const char* componentName)
       PyObject *result = PyObject_CallMethod(pyCont,
                                              (char*)"import_component",
                                              (char*)"s",componentName);
-      std::string ret= PyString_AsString(result);
+      std::string ret= PyUnicode_AsUTF8(result);
       SCRUTE(ret);
       Py_RELEASE_NEW_THREAD;
   
@@ -215,13 +217,12 @@ bool Engines_MPIContainer_i::Lload_component_Library(const char* componentName)
 // Create an instance of component
 Engines::EngineComponent_ptr
 Engines_MPIContainer_i::create_component_instance_env( const char* componentName,
-                                                       CORBA::Long studyId,
-                                                       const Engines::FieldsDict& env,
+                                                       const Engines::FieldsDict& /*env*/,
                                                        CORBA::String_out reason)
 {
   reason=CORBA::string_dup("");
 
-  pthread_t *th;
+  pthread_t *th = 0;
   if(_numproc == 0){
     th = new pthread_t[_nbproc];
     for(int ip=1;ip<_nbproc;ip++){
@@ -229,12 +230,11 @@ Engines_MPIContainer_i::create_component_instance_env( const char* componentName
       st->ip = ip;
       st->tior = _tior;
       st->compoName = componentName;
-      st->studyId = studyId;
       pthread_create(&(th[ip]),NULL,th_createcomponentinstance,(void*)st);
     }
   }
 
-  Engines::EngineComponent_ptr cptr = Lcreate_component_instance(componentName,studyId);
+  Engines::EngineComponent_ptr cptr = Lcreate_component_instance(componentName);
 
   if(_numproc == 0){
     for(int ip=1;ip<_nbproc;ip++)
@@ -246,13 +246,8 @@ Engines_MPIContainer_i::create_component_instance_env( const char* componentName
 }
 
 Engines::EngineComponent_ptr
-Engines_MPIContainer_i::Lcreate_component_instance( const char* genericRegisterName, CORBA::Long studyId)
+Engines_MPIContainer_i::Lcreate_component_instance( const char* genericRegisterName )
 {
-  if (studyId < 0) {
-    INFOS("studyId must be > 0 for mono study instance, =0 for multiStudy");
-    return Engines::EngineComponent::_nil() ;
-  }
-
   Engines::EngineComponent_var iobject = Engines::EngineComponent::_nil() ;
   Engines::MPIObject_var pobj;
 
@@ -279,10 +274,9 @@ Engines_MPIContainer_i::Lcreate_component_instance( const char* genericRegisterN
     PyObject *pyCont = PyDict_GetItemString(globals, "pyCont");
     PyObject *result = PyObject_CallMethod(pyCont,
                                            (char*)"create_component_instance",
-                                           (char*)"ssl",
+                                           (char*)"ss",
                                            aCompName.c_str(),
-                                           instanceName.c_str(),
-                                           studyId);
+                                           instanceName.c_str());
     const char *ior;
     const char *error;
     PyArg_ParseTuple(result,"ss", &ior, &error);
@@ -303,13 +297,16 @@ Engines_MPIContainer_i::Lcreate_component_instance( const char* genericRegisterN
   
   //--- try C++
 
+#ifdef __APPLE__
+  std::string impl_name = std::string ("lib") + genericRegisterName +std::string("Engine.dylib");
+#else
   std::string impl_name = std::string ("lib") + genericRegisterName +std::string("Engine.so");
+#endif
   if (_library_map.count(impl_name) != 0) // C++ component
     {
       void* handle = _library_map[impl_name];
       iobject = createMPIInstance(genericRegisterName,
-                                    handle,
-                                    studyId);
+                                  handle);
       return iobject._retn();
     }
 
@@ -318,8 +315,7 @@ Engines_MPIContainer_i::Lcreate_component_instance( const char* genericRegisterN
 
 Engines::EngineComponent_ptr
 Engines_MPIContainer_i::createMPIInstance(std::string genericRegisterName,
-                                          void *handle,
-                                          int studyId)
+                                          void *handle)
 {
   Engines::EngineComponent_var iobject;
   Engines::MPIObject_var pobj;
@@ -364,32 +360,19 @@ Engines_MPIContainer_i::createMPIInstance(std::string genericRegisterName,
       std::string component_registerName =
         _containerName + "/" + instanceName;
 
-      // --- Instanciate required CORBA object
+      // --- Instantiate required CORBA object
 
       PortableServer::ObjectId *id ; //not owner, do not delete (nore use var)
       id = (MPIComponent_factory) ( _orb, _poa, _id, instanceName.c_str(), aGenRegisterName.c_str() ) ;
 
-      // --- get reference & servant from id
+      // --- get reference from id
 
       CORBA::Object_var obj = _poa->id_to_reference(*id);
       iobject = Engines::EngineComponent::_narrow( obj ) ;
       pobj = Engines::MPIObject::_narrow(obj) ;
 
-      Engines_Component_i *servant =
-        dynamic_cast<Engines_Component_i*>(_poa->reference_to_servant(iobject));
-      ASSERT(servant);
-      //SCRUTE(servant->pd_refCount);
-      servant->_remove_ref(); // compensate previous id_to_reference 
-      //SCRUTE(servant->pd_refCount);
       _listInstances_map[instanceName] = iobject;
       _cntInstances_map[aGenRegisterName] += 1;
-      //SCRUTE(servant->pd_refCount);
-#ifndef _DEBUG_
-      servant->setStudyId(studyId);
-#else
-      bool ret_studyId = servant->setStudyId(studyId);
-      ASSERT(ret_studyId);
-#endif
 
       // --- register the engine under the name
       //     containerName(.dir)/instanceName(.object)
@@ -413,7 +396,7 @@ Engines_MPIContainer_i::createMPIInstance(std::string genericRegisterName,
 Engines::EngineComponent_ptr Engines_MPIContainer_i::load_impl(const char* nameToRegister,
                                                  const char* componentName)
 {
-  pthread_t *th;
+  pthread_t *th = 0;
   if(_numproc == 0){
     th = new pthread_t[_nbproc];
     for(int ip=1;ip<_nbproc;ip++){
@@ -462,7 +445,7 @@ Engines::EngineComponent_ptr Engines_MPIContainer_i::Lload_impl(
 
   std::string absolute_impl_name(_impl_name);
   MESSAGE("[" << _numproc << "] absolute_impl_name=" << absolute_impl_name);
-  void * handle = dlopen(absolute_impl_name.c_str(), RTLD_LAZY);
+  void * handle = dlopen(absolute_impl_name.c_str(), RTLD_LAZY | RTLD_GLOBAL);
   if(!handle){
     INFOS("[" << _numproc << "] Can't load shared library : " << absolute_impl_name);
     INFOS("[" << _numproc << "] error dlopen: " << dlerror());
@@ -526,7 +509,7 @@ void Engines_MPIContainer_i::remove_impl(Engines::EngineComponent_ptr component_
   Engines::MPIObject_ptr pcptr;
   Engines::MPIObject_ptr spcptr;
 
-  pthread_t *th;
+  pthread_t *th = 0;
   if(_numproc == 0){
     pcptr = (Engines::MPIObject_ptr)component_i;
     th = new pthread_t[_nbproc];
@@ -560,7 +543,7 @@ void Engines_MPIContainer_i::remove_impl(Engines::EngineComponent_ptr component_
 
 void Engines_MPIContainer_i::finalize_removal()
 {
-  pthread_t *th;
+  pthread_t *th = 0;
   if(_numproc == 0){
     th = new pthread_t[_nbproc];
     for(int ip=1;ip<_nbproc;ip++){
@@ -608,7 +591,7 @@ void *th_loadcomponentlibrary(void *s)
 void *th_createcomponentinstance(void *s)
 {
   thread_st *st = (thread_st*)s;
-  (Engines::MPIContainer::_narrow((*(st->tior))[st->ip]))->create_component_instance(st->compoName.c_str(),st->studyId);
+  (Engines::MPIContainer::_narrow((*(st->tior))[st->ip]))->create_component_instance(st->compoName.c_str());
   return NULL;
 }