X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FKernelHelpers%2FSALOME_KernelServices.cxx;h=b0f8776601d45230afb5b56a0702af0688e61d0e;hb=a1536f1c29281b62d827361ae4a441f82dedefc6;hp=71f9456602d0cfa5e80b761f1f9f6c12d295a389;hpb=3f048e2513c4a1053a84a98ebd708921c831fa23;p=modules%2Fkernel.git diff --git a/src/KernelHelpers/SALOME_KernelServices.cxx b/src/KernelHelpers/SALOME_KernelServices.cxx index 71f945660..b0f877660 100644 --- a/src/KernelHelpers/SALOME_KernelServices.cxx +++ b/src/KernelHelpers/SALOME_KernelServices.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2023 CEA, EDF, OPEN CASCADE // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -16,35 +16,48 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + // Author: Guillaume Boulant (EDF/R&D) #include "SALOME_KernelServices.hxx" +#include "SALOME_Fake_NamingService.hxx" +#include "Utils_SALOME_Exception.hxx" +#include "KernelBasis.hxx" + +#include +#include + +std::map _compo_map; + +std::unique_ptr _naming_service; namespace KERNEL { - /** - * This function returns a static reference to the orb. The orb can - * be used for example to initialize CORBA variables or to serialize - * and unserialize the CORBA objet to/from an IOR string. - */ - CORBA::ORB_ptr getORB() { - static CORBA::ORB_ptr orb; - if(CORBA::is_nil(orb)){ - int argc=0; - orb = CORBA::ORB_init(argc,0); + void assignNamingServiceSL() + { + if ( !_naming_service.get() ) + { + _naming_service.reset( new SALOME_Fake_NamingService ); + } + else + { + THROW_SALOME_EXCEPTION("assignNamingServiceSL : NS SALOME Wrapper is already set !"); } - return orb; } - + /** * 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() ) + { + if(getSSLMode()) + _naming_service.reset( new SALOME_Fake_NamingService ); + else + _naming_service.reset( new SALOME_NamingService(getORB()) ); } - return namingService; + return _naming_service.get(); } /** @@ -53,7 +66,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; @@ -63,15 +76,16 @@ namespace KERNEL { /** * This returns a static reference to the SALOME study. The * study can be used to get informations about it. + * \sa getStudyServantSA */ 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); } - return aStudy; + return SALOMEDS::Study::_duplicate(aStudy); // we duplicate it here to allow using it with the var client instances. } /** @@ -82,7 +96,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); } @@ -99,7 +113,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); } @@ -109,7 +123,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); } @@ -135,7 +149,7 @@ namespace KERNEL { anObject = anORB->string_to_object(aValue); } }catch(...){ - INFOS("SObjectToObject - Unknown exception was occured!!!"); + INFOS("SObjectToObject - Unknown exception has occurred!!!"); } return anObject._retn(); } @@ -159,5 +173,26 @@ namespace KERNEL { es.text = CORBA::string_dup(text); return SALOME::SALOME_Exception(es); } - + + void RegisterCompo(const std::string& compoName, CORBA::Object_var compoPtr) + { + _compo_map[compoName] = compoPtr; + } + + CORBA::Object_var RetrieveCompo(const std::string& compoName) + { + CORBA::Object_var ret; + auto it = _compo_map.find(compoName); + if( it != _compo_map.end() ) + { + ret = (*it).second; + } + else + { + Engines::EngineComponent_var compo = getLifeCycleCORBA()->FindOrLoad_Component( "FactoryServer", compoName.c_str() ); + ret = CORBA::Object::_narrow(compo); + _compo_map[compoName] = ret; + } + return ret._retn(); + } }