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)
committervsr <vsr@opencascade.com>
Tue, 29 Mar 2016 16:54:36 +0000 (19:54 +0300)
src/PVServerService/ServiceLoader/CMakeLists.txt
src/PVServerService/ServiceLoader/PVServer_ServiceLoader.cxx
src/PVServerService/ServiceLoader/PVServer_ServiceLoader.h
src/PVServerService/ServiceLoader/PVServer_ServiceLoader.i

index a9a6a5b23bfc15e88c56aac6d7dfbb2ad3ea1ff6..ee65c52375d812ab1e1fdc276b7291f46d459152 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 80582dbfe4d5c5ecbc27af45fb45500328f623f6..02790ee8ec29ffa51c3940ec63a599f8ab46ba8f 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 d48dccf15ddfdd34b544adb5d2597a229b061dc5..b274d44892cba2479112d8a25e3fc35f34aa76f0 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 8546c3453184d81fe92c9f22369c4b2afa3af13a..f8e4389a2fcf713be8599875c542676b128d71ea 100644 (file)
@@ -29,5 +29,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);
 };