]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Fix pb with duplication of PVSERVER service - attempt 2
authorvsr <vsr@opencascade.com>
Tue, 29 Mar 2016 16:54:36 +0000 (19:54 +0300)
committerFlorian BRUNET <florian.brunet@opencascade.com>
Thu, 12 May 2016 09:12:45 +0000 (11:12 +0200)
src/PVServerService/ServiceLoader/CMakeLists.txt
src/PVServerService/ServiceLoader/PVServer_ServiceLoader.cxx
src/PVServerService/ServiceLoader/PVServer_ServiceLoader.h
src/PVServerService/ServiceLoader/PVServer_ServiceLoader.i

index 15c1090c8007aa99b9b8a185f0ac2a06c0ecc6e5..843761a2a2d55a4db3edd1fcc9e245b8e6960a05 100644 (file)
@@ -21,7 +21,6 @@ INCLUDE(${SWIG_USE_FILE})
 
 INCLUDE_DIRECTORIES(
   ${CMAKE_CURRENT_SOURCE_DIR}
-  ${CMAKE_CURRENT_SOURCE_DIR}/..
   ${OMNIORB_INCLUDE_DIR}
   ${KERNEL_INCLUDE_DIRS}
   )
@@ -33,9 +32,9 @@ ADD_DEFINITIONS(
 
 SET(_link_LIBRARIES 
   ${KERNEL_OpUtil}        # class SALOME_Exception
-  ${KERNEL_SalomeContainer} 
   ${KERNEL_SalomeNS}
   ${KERNEL_SalomeLifeCycleCORBA}
+  ${KERNEL_SalomeIDLKernel}
   )
 
 # --- headers ---
@@ -45,12 +44,12 @@ SET(_HEADERS
 
 # --- sources ---
 SET(_SOURCES
   PVServer_ServiceLoader.cxx
-  )
+ PVServer_ServiceLoader.cxx
+)
   
 SET(_SWIG
-    PVServer_ServiceLoader.i
-   )
+  PVServer_ServiceLoader.i
+)
   
 # --- rules ---
 ADD_LIBRARY(PVServerServiceLoader ${_SOURCES})
index c36695f7cb830aac7b5f6a0dc59e176618f66cea..d97f55b15b371ff03c728f29527cf34b3b31467e 100644 (file)
 // Author: Adrien Bruneton (CEA)
 
 #include "PVServer_ServiceLoader.h"
-#include "PVServer_ServiceWrapper.h"
 
 #include <SALOME_LifeCycleCORBA.hxx>
 #include <SALOME_NamingService.hxx>
 #include <utilities.h> // MESSAGE() macro
+#include <SALOMEconfig.h>
+#include CORBA_CLIENT_HEADER(SALOME_ContainerManager)
 
 PVServer_ServiceLoader::PVServer_ServiceLoader():
-     _lcc(0)
+  myLcc( 0 )
 {
-  _lcc = new SALOME_LifeCycleCORBA();
-  _ns = _lcc->namingService();
-  _cm = _lcc->getContainerManager();
-  _orb = _lcc->orb();
-
+  myLcc = new SALOME_LifeCycleCORBA();
 }
 
 PVServer_ServiceLoader::~PVServer_ServiceLoader()
 {
-  if (_lcc)
-    delete _lcc;
-  _lcc = 0;
+  delete myLcc;
+}
+
+SALOME_LifeCycleCORBA* PVServer_ServiceLoader::lcc()
+{
+  return myLcc;
 }
 
-std::string PVServer_ServiceLoader::findOrLoadService(const char * containerName)
+std::string PVServer_ServiceLoader::findOrLoadService( const std::string& containerName )
 {
-  std::string ior = findService(containerName);
-  if (ior == "")
-    ior = loadService(containerName);
+  std::string ior = findService( containerName );
+  if ( ior == "" )
+    ior = loadService( containerName );
   return ior;
 }
 
-std::string PVServer_ServiceLoader::findService(const char * containerName)
+std::string PVServer_ServiceLoader::findService( const std::string& containerName )
 {
-  std::string path = "/Containers";
-  path += containerName;
-  path += "/PVSERVER";
-  CORBA::Object_ptr obj = _ns->Resolve(path.c_str());
-  if(!CORBA::is_nil(obj))
+  std::string ior = "";
+
+  Engines::Container_var container = getContainer( containerName, "get" );
+
+  if ( !CORBA::is_nil( container ) )
+  {
+    CORBA::String_var hName = container->getHostName();
+    CORBA::Object_var obj = lcc()->namingService()->ResolveComponent( hName.in(),
+                                                                      containerName.c_str(),
+                                                                      "PVSERVER",
+                                                                      0 );
+    if ( !CORBA::is_nil( obj ) )
     {
-      MESSAGE("PVServer_ServiceLoader::findService(): Service found! ");
-      char * ior = _orb->object_to_string(obj);
-      return std::string(ior);
+      CORBA::ORB_var orb = lcc()->orb();
+      CORBA::String_var cIor = orb->object_to_string( obj );
+      ior = cIor.in();
     }
+  }
+
+  if ( ior == "" )
+  {
+    MESSAGE( "PVServer_ServiceLoader::findService(): Service NOT found!" );
+  }
   else
-    {
-      MESSAGE("PVServer_ServiceLoader::findService(): Service NOT found! ");
-      return std::string("");
-    }
+  {
+    MESSAGE( "PVServer_ServiceLoader::findService(): Service found!" );
+  }
 
+  return ior;
 }
 
-std::string PVServer_ServiceLoader::loadService(const char * containerName)
+std::string PVServer_ServiceLoader::loadService( const std::string& containerName )
 {
-  // Get the requested container
-  Engines::ContainerParameters params;
-  params.container_name = CORBA::string_dup(containerName);
-  params.isMPI = false;
-  params.mode = "getorstart";
-  Engines::Container_ptr contain = _cm->GiveContainer(params);
+  std::string ior = "";
 
-  if (!CORBA::is_nil(contain))
+  Engines::Container_var container = getContainer( containerName, "getorstart" );
+
+  if ( !CORBA::is_nil( container ) )
+  {
+    CORBA::String_var cReason;
+    CORBA::String_var cIor = container->create_python_service_instance( "PVSERVER", cReason.out() );
+    std::string reason = cReason.in();
+
+    if ( reason != "" )
     {
-      char * reason;
-      char * ior = contain->create_python_service_instance("PVSERVER", reason);
-      std::string reas(reason);
-      CORBA::string_free(reason);
-      if (reas != "")
-        {
-          MESSAGE("PVServer_ServiceLoader::loadService(): Python service instance could not be created! ");
-          MESSAGE("PVServer_ServiceLoader::loadService(): " << reas);
-          return std::string("");
-        }
-      else
-        {
-          MESSAGE("PVServer_ServiceLoader::loadService(): Container and service loaded! ");
-          return std::string(ior);
-        }
+      MESSAGE( "PVServer_ServiceLoader::loadService(): Python service instance could not be created!" );
+      MESSAGE( "PVServer_ServiceLoader::loadService(): " << reason );
     }
-  else
+    else
     {
-      MESSAGE("PVServer_ServiceLoader::loadService(): Container could not be retrieved! ");
-      return std::string("");
+      MESSAGE( "PVServer_ServiceLoader::loadService(): Container and service loaded!" );
+      ior = cIor.in();
     }
+  }
+  else
+  {
+    MESSAGE( "PVServer_ServiceLoader::loadService(): Container could not be retrieved!" );
+  }
+  return ior;
 }
 
+Engines::Container_ptr PVServer_ServiceLoader::getContainer( const std::string& containerName,
+                                                             const std::string& mode )
+{
+  Engines::ContainerParameters params;
+  params.isMPI = false;
+  params.mode = CORBA::string_dup( mode.c_str() );
+
+  int rg = containerName.find( "/" );
+  if ( rg < 0 )
+  {
+    params.container_name = CORBA::string_dup( containerName.c_str() );
+  }
+  else
+  {
+    params.resource_params.hostname = CORBA::string_dup( containerName.substr(0, rg).c_str() );
+    params.container_name           = CORBA::string_dup( containerName.substr(rg+1).c_str() );
+  }
+
+  Engines::ContainerManager_var cm = lcc()->getContainerManager();
+  Engines::Container_var container = cm->GiveContainer( params );
+  return container._retn();
+}
index 2d364b04319c483e972b09482e0cb3dbc5b0d254..e3216079845b558ade4082a6098cc9b9798cc236 100644 (file)
 #define PVSERVERSERVICELOADER_H_
 
 #include "PVServerServiceLoader.h"
-
-#include <SALOME_ContainerManager.hxx>
+#include <SALOMEconfig.h>
+#include CORBA_CLIENT_HEADER(SALOME_Component)
+#include <string>
 
 class SALOME_LifeCycleCORBA;
-class SALOME_NamingService;
 
 class PVSERVERSERVICELOADER_EXPORT PVServer_ServiceLoader
 {
@@ -35,16 +35,16 @@ public:
   virtual ~PVServer_ServiceLoader();
 
   //! Get the IOR of the CORBA service handling the PVServer
-  std::string findOrLoadService(const char * containerName);
+  std::string findOrLoadService( const std::string& );
 
 private:
-  std::string findService(const char * containerName);
-  std::string loadService(const char * containerName);
+  SALOME_LifeCycleCORBA* lcc();
+  std::string findService( const std::string& );
+  std::string loadService( const std::string& );
+  Engines::Container_ptr getContainer( const std::string&, const std::string& );
 
-  SALOME_LifeCycleCORBA * _lcc;
-  CORBA::ORB_ptr _orb;
-  SALOME_NamingService * _ns;
-  Engines::ContainerManager_ptr _cm;
+private:
+  SALOME_LifeCycleCORBA* myLcc;
 };
 
 #endif /* PVSERVERSERVICELOADER_H_ */
index 244962d135cbcb995e9f07edff700cec6e6032e1..2e81d58a01822a083471bb71a8d27d56034a61fb 100644 (file)
@@ -10,5 +10,5 @@ class PVServer_ServiceLoader
 {
 public:
   //! Get the IOR of the CORBA service handling the PVServer
-  std::string findOrLoadService(const char * containerName);
+  std::string findOrLoadService(const std::string& containerName);
 };