From: vsr Date: Tue, 29 Mar 2016 16:54:36 +0000 (+0300) Subject: Fix pb with duplication of PVSERVER service - attempt 2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=98cdbe972a5ba275cb76725abe09b64d44d1699c;p=modules%2Fgui.git Fix pb with duplication of PVSERVER service - attempt 2 --- diff --git a/src/PVServerService/ServiceLoader/CMakeLists.txt b/src/PVServerService/ServiceLoader/CMakeLists.txt index 15c1090c8..843761a2a 100644 --- a/src/PVServerService/ServiceLoader/CMakeLists.txt +++ b/src/PVServerService/ServiceLoader/CMakeLists.txt @@ -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}) diff --git a/src/PVServerService/ServiceLoader/PVServer_ServiceLoader.cxx b/src/PVServerService/ServiceLoader/PVServer_ServiceLoader.cxx index c36695f7c..d97f55b15 100644 --- a/src/PVServerService/ServiceLoader/PVServer_ServiceLoader.cxx +++ b/src/PVServerService/ServiceLoader/PVServer_ServiceLoader.cxx @@ -19,88 +19,119 @@ // Author: Adrien Bruneton (CEA) #include "PVServer_ServiceLoader.h" -#include "PVServer_ServiceWrapper.h" #include #include #include // MESSAGE() macro +#include +#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(); +} diff --git a/src/PVServerService/ServiceLoader/PVServer_ServiceLoader.h b/src/PVServerService/ServiceLoader/PVServer_ServiceLoader.h index 2d364b043..e32160798 100644 --- a/src/PVServerService/ServiceLoader/PVServer_ServiceLoader.h +++ b/src/PVServerService/ServiceLoader/PVServer_ServiceLoader.h @@ -22,11 +22,11 @@ #define PVSERVERSERVICELOADER_H_ #include "PVServerServiceLoader.h" - -#include +#include +#include CORBA_CLIENT_HEADER(SALOME_Component) +#include 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_ */ diff --git a/src/PVServerService/ServiceLoader/PVServer_ServiceLoader.i b/src/PVServerService/ServiceLoader/PVServer_ServiceLoader.i index 244962d13..2e81d58a0 100644 --- a/src/PVServerService/ServiceLoader/PVServer_ServiceLoader.i +++ b/src/PVServerService/ServiceLoader/PVServer_ServiceLoader.i @@ -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); };