From 69802483b4ccd7c8f13bf0cb8fb71db63fa5d37c Mon Sep 17 00:00:00 2001 From: Anthony GEAY Date: Sun, 21 Feb 2021 22:35:42 +0100 Subject: [PATCH] Make the helper KERNEL::getNamingService used by Study to retrieve Session SSL ready --- src/KernelHelpers/KernelHelpersUseCases.cxx | 2 +- src/KernelHelpers/SALOME_KernelServices.cxx | 37 ++++++++++++++----- src/KernelHelpers/SALOME_KernelServices.hxx | 3 +- .../Test/KernelHelpersUnitTests.cxx | 2 +- src/SALOMEDS/SALOMEDS_Study_i.cxx | 6 +-- 5 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/KernelHelpers/KernelHelpersUseCases.cxx b/src/KernelHelpers/KernelHelpersUseCases.cxx index 7c41260ad..6fa36b98e 100644 --- a/src/KernelHelpers/KernelHelpersUseCases.cxx +++ b/src/KernelHelpers/KernelHelpersUseCases.cxx @@ -31,7 +31,7 @@ bool TEST_corba() { LOG("TEST_Corba: orb ERROR"); return false; } - SALOME_NamingService * ns = KERNEL::getNamingService(); + SALOME_NamingService_Abstract * ns = KERNEL::getNamingService(); if ( ns == NULL ) { LOG("TEST_Corba: ns ERROR"); return false; diff --git a/src/KernelHelpers/SALOME_KernelServices.cxx b/src/KernelHelpers/SALOME_KernelServices.cxx index 4ca01ee7a..516aeb4fa 100644 --- a/src/KernelHelpers/SALOME_KernelServices.cxx +++ b/src/KernelHelpers/SALOME_KernelServices.cxx @@ -20,11 +20,15 @@ // Author: Guillaume Boulant (EDF/R&D) #include "SALOME_KernelServices.hxx" +#include "SALOME_Fake_NamingService.hxx" #include +#include std::map _compo_map; +std::unique_ptr _naming_service; + namespace KERNEL { /** @@ -41,15 +45,28 @@ namespace KERNEL { return orb; } + void assignNamingServiceSL() + { + if ( !_naming_service.get() ) + { + _naming_service.reset( new SALOME_Fake_NamingService ); + } + else + { + THROW_SALOME_EXCEPTION("assignNamingServiceSL : NS SALOME Wrapper is already set !"); + } + } + /** * This function returns a static reference to the SALOME naming service. */ - SALOME_NamingService * getNamingService() { - static SALOME_NamingService * namingService; - if ( namingService == NULL ) { - namingService = new SALOME_NamingService(getORB()); + SALOME_NamingService_Abstract *getNamingService() + { + if ( !_naming_service.get() ) + { + _naming_service.reset( new SALOME_NamingService(getORB()) ); } - return namingService; + return _naming_service.get(); } /** @@ -58,7 +75,7 @@ namespace KERNEL { SALOME_LifeCycleCORBA * getLifeCycleCORBA() { static SALOME_LifeCycleCORBA * lifeCycleCORBA; if ( lifeCycleCORBA == NULL ) { - SALOME_NamingService *aNamingService = getNamingService(); + SALOME_NamingService_Abstract *aNamingService = getNamingService(); lifeCycleCORBA = new SALOME_LifeCycleCORBA(aNamingService); } return lifeCycleCORBA; @@ -73,7 +90,7 @@ namespace KERNEL { SALOMEDS::Study_ptr getStudyServant() { static SALOMEDS::Study_ptr aStudy; if(CORBA::is_nil(aStudy)){ - SALOME_NamingService *aNamingService = getNamingService(); + SALOME_NamingService_Abstract *aNamingService = getNamingService(); CORBA::Object_ptr anObject = aNamingService->Resolve("/Study"); aStudy = SALOMEDS::Study::_narrow(anObject); } @@ -88,7 +105,7 @@ namespace KERNEL { SALOME::Session_ptr getSalomeSession() { static SALOME::Session_ptr salomeSession; if(CORBA::is_nil(salomeSession)){ - SALOME_NamingService *aNamingService = getNamingService(); + SALOME_NamingService_Abstract *aNamingService = getNamingService(); CORBA::Object_ptr obj = aNamingService->Resolve("/Kernel/Session"); salomeSession = SALOME::Session::_narrow(obj); } @@ -105,7 +122,7 @@ namespace KERNEL { static Engines::SalomeLauncher_ptr salomeLauncher; if(CORBA::is_nil(salomeLauncher)){ //LOG("KERNEL_services::getSalomeLauncher(): creating the static instance"); - SALOME_NamingService *aNamingService = getNamingService(); + SALOME_NamingService_Abstract *aNamingService = getNamingService(); CORBA::Object_ptr obj = aNamingService->Resolve("/SalomeLauncher"); salomeLauncher = Engines::SalomeLauncher::_narrow(obj); } @@ -115,7 +132,7 @@ namespace KERNEL { Engines::ResourcesManager_ptr getResourcesManager() { static Engines::ResourcesManager_ptr resourcesManager; if(CORBA::is_nil(resourcesManager)){ - SALOME_NamingService *aNamingService = getNamingService(); + SALOME_NamingService_Abstract *aNamingService = getNamingService(); CORBA::Object_ptr obj = aNamingService->Resolve("/ResourcesManager"); resourcesManager = Engines::ResourcesManager::_narrow(obj); } diff --git a/src/KernelHelpers/SALOME_KernelServices.hxx b/src/KernelHelpers/SALOME_KernelServices.hxx index 0568d5567..0651bda94 100644 --- a/src/KernelHelpers/SALOME_KernelServices.hxx +++ b/src/KernelHelpers/SALOME_KernelServices.hxx @@ -39,7 +39,8 @@ namespace KERNEL { // --------------------------------------------- // SALOME KERNEL main services KERNELHELPERS_EXPORT CORBA::ORB_ptr getORB(); - KERNELHELPERS_EXPORT SALOME_NamingService * getNamingService(); + KERNELHELPERS_EXPORT SALOME_NamingService_Abstract *getNamingService(); + KERNELHELPERS_EXPORT void assignNamingServiceSL(); KERNELHELPERS_EXPORT SALOME_LifeCycleCORBA * getLifeCycleCORBA(); KERNELHELPERS_EXPORT SALOME::Session_ptr getSalomeSession(); KERNELHELPERS_EXPORT SALOMEDS::Study_ptr getStudyServant(); diff --git a/src/KernelHelpers/Test/KernelHelpersUnitTests.cxx b/src/KernelHelpers/Test/KernelHelpersUnitTests.cxx index 390ebb658..c1220bc6c 100644 --- a/src/KernelHelpers/Test/KernelHelpersUnitTests.cxx +++ b/src/KernelHelpers/Test/KernelHelpersUnitTests.cxx @@ -59,7 +59,7 @@ void KernelHelpersUnitTests::TEST_corba() CPPUNIT_ASSERT(!CORBA::is_nil(orb)); - SALOME_NamingService * ns = KERNEL::getNamingService(); + SALOME_NamingService_Abstract * ns = KERNEL::getNamingService(); CPPUNIT_ASSERT(ns!=NULL); SALOME_LifeCycleCORBA * lcc = KERNEL::getLifeCycleCORBA(); diff --git a/src/SALOMEDS/SALOMEDS_Study_i.cxx b/src/SALOMEDS/SALOMEDS_Study_i.cxx index 4da4f01f3..79ad8c553 100644 --- a/src/SALOMEDS/SALOMEDS_Study_i.cxx +++ b/src/SALOMEDS/SALOMEDS_Study_i.cxx @@ -268,7 +268,7 @@ namespace SALOMEDS void sendMessageToGUI(const char* msg ) { - SALOME_NamingService *aNamingService = KERNEL::getNamingService(); + SALOME_NamingService_Abstract *aNamingService = KERNEL::getNamingService(); CORBA::Object_var obj = aNamingService->Resolve("/Kernel/Session"); SALOME::Session_var aSession = SALOME::Session::_narrow(obj); sendMessageToGUIGivenSession(aSession,msg); @@ -317,7 +317,7 @@ SALOMEDS_Study_i::~SALOMEDS_Study_i() void SALOMEDS_Study_i::Init() { - SALOME_NamingService *aNamingService = KERNEL::getNamingService(); + SALOME_NamingService_Abstract *aNamingService = KERNEL::getNamingService(); CORBA::Object_var obj = aNamingService->Resolve("/Kernel/Session"); SALOME::Session_var aSession = SALOME::Session::_narrow(obj); Init(aSession); @@ -1027,7 +1027,7 @@ void SALOMEDS_Study_i::URL(const wchar_t* wurl) _impl->URL(Kernel_Utils::encode_s(wurl)); // update desktop title with new study name - SALOME_NamingService *aNamingService = KERNEL::getNamingService(); + SALOME_NamingService_Abstract *aNamingService = KERNEL::getNamingService(); CORBA::Object_var obj = aNamingService->Resolve("/Kernel/Session"); SALOME::Session_var aSession = SALOME::Session::_narrow(obj); NameChanged(aSession); -- 2.39.2