From 888f04cad3e3fa57bf92c96789959fc87bfdd555 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Wed, 14 Apr 2021 21:56:39 +0200 Subject: [PATCH] YACS in SSL mode --- CMakeLists.txt | 2 +- SalomeKERNELConfig.cmake.in | 1 + idl/CMakeLists.txt | 1 + idl/SALOME_Component.idl | 4 + idl/SALOME_Embedded_NamingService.idl | 37 +++ src/Basics/CMakeLists.txt | 24 +- src/Basics/KernelBasis.cxx | 32 +++ src/Basics/KernelBasis.hxx | 25 ++ src/Basics/KernelBasis.i | 27 ++ src/Container/CMakeLists.txt | 14 +- src/Container/Container_i.cxx | 43 +++- src/Container/SALOME_ComponentPy.py | 11 +- src/Container/SALOME_Container.cxx | 217 +--------------- src/Container/SALOME_ContainerManager.cxx | 35 ++- src/Container/SALOME_ContainerManager.hxx | 13 +- src/Container/SALOME_Container_Common.cxx | 237 ++++++++++++++++++ src/Container/SALOME_Container_Common.hxx | 27 ++ src/Container/SALOME_Container_No_NS_Serv.cxx | 38 +++ src/Container/SALOME_Container_i.hxx | 7 +- src/KERNEL_PY/__init__.py | 15 +- src/KernelHelpers/CMakeLists.txt | 10 +- src/KernelHelpers/SALOME_KernelORB.cxx | 36 +++ src/KernelHelpers/SALOME_KernelORB.hxx | 31 +++ src/KernelHelpers/SALOME_KernelServices.cxx | 14 -- src/KernelHelpers/SALOME_KernelServices.hxx | 3 +- src/Launcher/CMakeLists.txt | 23 ++ src/Launcher/KernelLauncher.cxx | 37 +++ src/Launcher/KernelLauncher.hxx | 24 ++ src/Launcher/KernelLauncher.i | 39 +++ src/Launcher/SALOME_Launcher.cxx | 9 +- src/Launcher/SALOME_Launcher.hxx | 4 +- src/Launcher/SALOME_LauncherServer.cxx | 1 + src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx | 2 +- src/ModuleCatalog/KernelModuleCatalog.cxx | 4 +- .../SALOME_ModuleCatalog_Server.cxx | 2 +- .../SALOME_ModuleCatalog_impl.cxx | 6 + .../SALOME_ModuleCatalog_impl.hxx | 2 + src/NamingService/CMakeLists.txt | 29 ++- src/NamingService/NamingService.i | 138 ++++++++++ .../SALOME_Embedded_NamingService.cxx | 71 ++++++ .../SALOME_Embedded_NamingService.hxx | 37 +++ .../SALOME_Embedded_NamingService_Client.cxx | 62 +++++ .../SALOME_Embedded_NamingService_Client.hxx | 45 ++++ .../SALOME_Embedded_NamingService_ClientPy.py | 43 ++++ .../SALOME_Embedded_NamingService_Common.cxx | 48 ++++ .../SALOME_Embedded_NamingService_Common.hxx | 30 +++ .../SALOME_Fake_NamingService.cxx | 99 +++++++- .../SALOME_Fake_NamingService.hxx | 45 ++-- src/NamingService/SALOME_NamingService.cxx | 63 +---- src/NamingService/SALOME_NamingService.hxx | 8 +- src/NamingService/SALOME_NamingService.i | 98 -------- .../SALOME_NamingService_Abstract.cxx | 72 ++++++ .../SALOME_NamingService_Abstract.hxx | 25 +- .../SALOME_ResourcesManager.cxx | 4 +- .../SALOME_ResourcesManager.hxx | 8 +- .../SALOME_ResourcesManager_Client.cxx | 3 +- .../SALOME_ResourcesManager_Client.hxx | 4 +- src/SALOMEDS/SALOMEDS_Driver_i.cxx | 2 +- 58 files changed, 1517 insertions(+), 474 deletions(-) create mode 100644 idl/SALOME_Embedded_NamingService.idl create mode 100644 src/Basics/KernelBasis.cxx create mode 100644 src/Basics/KernelBasis.hxx create mode 100644 src/Basics/KernelBasis.i create mode 100644 src/Container/SALOME_Container_Common.cxx create mode 100644 src/Container/SALOME_Container_Common.hxx create mode 100644 src/Container/SALOME_Container_No_NS_Serv.cxx create mode 100644 src/KernelHelpers/SALOME_KernelORB.cxx create mode 100644 src/KernelHelpers/SALOME_KernelORB.hxx create mode 100644 src/Launcher/KernelLauncher.cxx create mode 100644 src/Launcher/KernelLauncher.hxx create mode 100644 src/Launcher/KernelLauncher.i create mode 100644 src/NamingService/NamingService.i create mode 100644 src/NamingService/SALOME_Embedded_NamingService.cxx create mode 100644 src/NamingService/SALOME_Embedded_NamingService.hxx create mode 100644 src/NamingService/SALOME_Embedded_NamingService_Client.cxx create mode 100644 src/NamingService/SALOME_Embedded_NamingService_Client.hxx create mode 100644 src/NamingService/SALOME_Embedded_NamingService_ClientPy.py create mode 100644 src/NamingService/SALOME_Embedded_NamingService_Common.cxx create mode 100644 src/NamingService/SALOME_Embedded_NamingService_Common.hxx delete mode 100644 src/NamingService/SALOME_NamingService.i diff --git a/CMakeLists.txt b/CMakeLists.txt index 473aab701..de9326142 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -218,7 +218,7 @@ IF(NOT SALOME_LIGHT_ONLY) DF SalomeLoggerServer with_loggerTraceCollector SalomeNS SalomeGenericObj Registry SalomeCatalog ResourcesManager SalomeResourcesManager SalomeNotification SalomeContainer SalomeSDS Launcher SalomeLauncher - SalomeLifeCycleCORBA SalomeDSClient TOOLSDS SalomeKernelHelpers + SalomeLifeCycleCORBA SalomeDSClient TOOLSDS SalomeKernelHelpers SalomeORB SalomeDSImpl SalomeDS SalomeCommunication SalomeDSCContainer) # Temporary solution for package src\DSC on windows IF(NOT WIN32) diff --git a/SalomeKERNELConfig.cmake.in b/SalomeKERNELConfig.cmake.in index 587517353..2e2c0b9d0 100644 --- a/SalomeKERNELConfig.cmake.in +++ b/SalomeKERNELConfig.cmake.in @@ -187,3 +187,4 @@ SET(KERNEL_TOOLSDS TOOLSDS) SET(KERNEL_UtilsTest UtilsTest) SET(KERNEL_with_loggerTraceCollector with_loggerTraceCollector) SET(KERNEL_SalomeKernelHelpers SalomeKernelHelpers) +SET(KERNEL_SalomeORB SalomeORB) diff --git a/idl/CMakeLists.txt b/idl/CMakeLists.txt index 2ca550e40..de7f9d9ee 100644 --- a/idl/CMakeLists.txt +++ b/idl/CMakeLists.txt @@ -55,6 +55,7 @@ SET(SalomeIDLKernel_IDLSOURCES SALOME_TestModuleCatalog.idl SALOME_CommonTypes.idl SALOME_ExternalServerLauncher.idl + SALOME_Embedded_NamingService.idl ${CMAKE_CURRENT_BINARY_DIR}/Calcium_Ports.idl ) diff --git a/idl/SALOME_Component.idl b/idl/SALOME_Component.idl index 9767490ac..89b97011b 100644 --- a/idl/SALOME_Component.idl +++ b/idl/SALOME_Component.idl @@ -30,6 +30,7 @@ #include "SALOMEDS.idl" #include "SALOME_Exception.idl" #include "SALOME_PyNode.idl" +#include "SALOME_Embedded_NamingService.idl" /*! \file SALOME_Component.idl \brief interfaces for EngineComponent and Container */ @@ -147,6 +148,9 @@ module Engines \param component_i Component to be removed */ void remove_impl(in EngineComponent component_i); + + //! In case of SSL mode Returns entry to Embedded NS + EmbeddedNamingService get_embedded_NS_if_ssl(); //! Unload component libraries from the container. void finalize_removal() ; diff --git a/idl/SALOME_Embedded_NamingService.idl b/idl/SALOME_Embedded_NamingService.idl new file mode 100644 index 000000000..c8c40207f --- /dev/null +++ b/idl/SALOME_Embedded_NamingService.idl @@ -0,0 +1,37 @@ +// Copyright (C) 2007-2021 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef _SALOME_EMBEDDED_NAMINGSERVICE_IDL_ +#define _SALOME_EMBEDDED_NAMINGSERVICE_IDL_ + +module Engines +{ + typedef sequence IORType; + + interface EmbeddedNamingService + { + void Register(in IORType ObjRef, in string Path); + void Destroy_FullDirectory(in string Path); + void Destroy_Name(in string Path); + IORType Resolve(in string Path); + IORType ResolveFirst(in string Path); + }; +}; + +#endif diff --git a/src/Basics/CMakeLists.txt b/src/Basics/CMakeLists.txt index e3d855096..9bffcca3f 100644 --- a/src/Basics/CMakeLists.txt +++ b/src/Basics/CMakeLists.txt @@ -17,8 +17,12 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # +include(${SWIG_USE_FILE}) + INCLUDE_DIRECTORIES( ${PTHREAD_INCLUDE_DIR} + ${PYTHON_INCLUDE_DIRS} + ${CMAKE_CURRENT_SOURCE_DIR} ) SET(SALOMEBasics_SOURCES @@ -29,6 +33,7 @@ SET(SALOMEBasics_SOURCES BasicsGenericDestructor.hxx Basics_Utils.hxx Basics_DirUtils.hxx + KernelBasis.cxx ) ADD_LIBRARY(SALOMEBasics ${SALOMEBasics_SOURCES}) @@ -39,4 +44,21 @@ TARGET_LINK_LIBRARIES(SALOMEBasics ${PLATFORM_LIBS} ${PTHREAD_LIBRARIES}) FILE(GLOB SALOMEBasics_HEADERS_HXX "${CMAKE_CURRENT_SOURCE_DIR}/*.hxx") INSTALL(FILES ${SALOMEBasics_HEADERS_HXX} DESTINATION ${SALOME_INSTALL_HEADERS}) -SALOME_CONFIGURE_FILE(smIdType.hxx.in smIdType.hxx INSTALL ${SALOME_INSTALL_HEADERS}) \ No newline at end of file +SET(KernelBasis_HEADERS KernelBasis.hxx KernelBasis.i) +SET(KernelBasis_SOURCES ${KernelBasis_HEADERS}) +SET_SOURCE_FILES_PROPERTIES(KernelBasis.i PROPERTIES CPLUSPLUS ON) +SET_SOURCE_FILES_PROPERTIES(KernelBasis.i PROPERTIES SWIG_FLAGS "-py3") +SET_SOURCE_FILES_PROPERTIES(KernelBasis_wrap.cpp PROPERTIES COMPILE_FLAGS "-DHAVE_CONFIG_H") +SET(_swig_SCRIPTS ${CMAKE_CURRENT_BINARY_DIR}/KernelBasis.py ) +IF(${CMAKE_VERSION} VERSION_LESS "3.8.0") + SWIG_ADD_MODULE(KernelBasis python ${KernelBasis_SOURCES}) +ELSE() + SWIG_ADD_LIBRARY(KernelBasis LANGUAGE python SOURCES ${KernelBasis_SOURCES}) +ENDIF() +SWIG_LINK_LIBRARIES(KernelBasis ${PYTHON_LIBRARIES} ${PLATFORM_LIBS} SALOMEBasics) +install(TARGETS _KernelBasis DESTINATION ${SALOME_INSTALL_LIBS}) +install(FILES ${KernelBasis_HEADERS} DESTINATION ${SALOME_INSTALL_HEADERS}) +SALOME_INSTALL_SCRIPTS("${_swig_SCRIPTS}" ${SALOME_INSTALL_BINS} EXTRA_DPYS "${SWIG_MODULE_KernelBasis_REAL_NAME}") + +SALOME_CONFIGURE_FILE(smIdType.hxx.in smIdType.hxx INSTALL ${SALOME_INSTALL_HEADERS}) + diff --git a/src/Basics/KernelBasis.cxx b/src/Basics/KernelBasis.cxx new file mode 100644 index 000000000..b634f7265 --- /dev/null +++ b/src/Basics/KernelBasis.cxx @@ -0,0 +1,32 @@ +// Copyright (C) 2021 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "KernelBasis.hxx" + +static bool DEFAULT_SSL_MODE = false; + +bool getSSLMode() +{ + return DEFAULT_SSL_MODE; +} + +void setSSLMode(bool sslMode) +{ + DEFAULT_SSL_MODE = sslMode; +} diff --git a/src/Basics/KernelBasis.hxx b/src/Basics/KernelBasis.hxx new file mode 100644 index 000000000..184fb9987 --- /dev/null +++ b/src/Basics/KernelBasis.hxx @@ -0,0 +1,25 @@ +// Copyright (C) 2021 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#pragma once + +#include "SALOME_Basics.hxx" + +bool BASICS_EXPORT getSSLMode(); +void BASICS_EXPORT setSSLMode(bool sslMode); diff --git a/src/Basics/KernelBasis.i b/src/Basics/KernelBasis.i new file mode 100644 index 000000000..44b2e221a --- /dev/null +++ b/src/Basics/KernelBasis.i @@ -0,0 +1,27 @@ +// Copyright (C) 2021 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +%module KernelBasis + +%{ +#include "KernelBasis.hxx" +%} + +bool getSSLMode(); +void setSSLMode(bool sslMode); diff --git a/src/Container/CMakeLists.txt b/src/Container/CMakeLists.txt index 01a46f711..7ff7cf0da 100644 --- a/src/Container/CMakeLists.txt +++ b/src/Container/CMakeLists.txt @@ -33,6 +33,7 @@ INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/../HDFPersist ${CMAKE_CURRENT_SOURCE_DIR}/../GenericObj ${CMAKE_CURRENT_SOURCE_DIR}/../SALOMETraceCollector/Test + ${CMAKE_CURRENT_SOURCE_DIR}/../KernelHelpers ${PROJECT_BINARY_DIR}/idl ) @@ -96,14 +97,21 @@ SET(SALOME_Container_LIBS ${MPI_LIBRARIES} ) -ADD_EXECUTABLE(SALOME_Container SALOME_Container.cxx SALOME_Container_SignalsHandler.cxx) -TARGET_LINK_LIBRARIES(SALOME_Container ${SALOME_Container_LIBS}) +ADD_LIBRARY(SalomeContainerServer SALOME_Container_Common.cxx SALOME_Container_SignalsHandler.cxx) +TARGET_LINK_LIBRARIES(SalomeContainerServer ${SALOME_Container_LIBS}) +INSTALL(TARGETS SalomeContainerServer EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS}) + +ADD_EXECUTABLE(SALOME_Container SALOME_Container.cxx) +TARGET_LINK_LIBRARIES(SALOME_Container SalomeContainerServer) + +ADD_EXECUTABLE(SALOME_Container_No_NS_Serv SALOME_Container_No_NS_Serv.cxx) +TARGET_LINK_LIBRARIES(SALOME_Container_No_NS_Serv SalomeContainerServer) IF(SALOME_BUILD_TESTS) ADD_EXECUTABLE(TestSalome_file TestSalome_file.cxx) TARGET_LINK_LIBRARIES(TestSalome_file SALOMETraceCollectorTest ${SALOME_Container_LIBS}) ENDIF() -INSTALL(TARGETS SALOME_Container DESTINATION ${SALOME_INSTALL_BINS}) +INSTALL(TARGETS SALOME_Container SALOME_Container_No_NS_Serv DESTINATION ${SALOME_INSTALL_BINS}) # Executable scripts to be installed SALOME_INSTALL_SCRIPTS("${SCRIPTS}" ${SALOME_INSTALL_SCRIPT_PYTHON}) diff --git a/src/Container/Container_i.cxx b/src/Container/Container_i.cxx index fe54aa0b4..315f7cee6 100644 --- a/src/Container/Container_i.cxx +++ b/src/Container/Container_i.cxx @@ -55,6 +55,7 @@ int SIGUSR1 = 1000; #include "Salome_file_i.hxx" #include "SALOME_NamingService.hxx" #include "SALOME_Fake_NamingService.hxx" +#include "SALOME_Embedded_NamingService_Client.hxx" #include "Basics_Utils.hxx" #ifdef _XOPEN_SOURCE @@ -134,10 +135,10 @@ Engines_Container_i::Engines_Container_i (CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, char *containerName , int argc , char* argv[], - SALOME_NamingService_Abstract *ns, + SALOME_NamingService_Container_Abstract *ns, bool isServantAloneInProcess ) : - _NS(0),_id(0),_numInstance(0),_isServantAloneInProcess(isServantAloneInProcess) + _NS(nullptr),_id(0),_numInstance(0),_isServantAloneInProcess(isServantAloneInProcess) { _pid = (long)getpid(); @@ -180,19 +181,18 @@ Engines_Container_i::Engines_Container_i (CORBA::ORB_ptr orb, { _id = _poa->activate_object(this); + // key point : if ns is nullptr : this servant is alone in its process + // if ns is not null : this servant embedded into single process. _NS = ns==nullptr ? new SALOME_NamingService : ns->clone(); _NS->init_orb( _orb ) ; CORBA::Object_var obj=_poa->id_to_reference(*_id); - Engines::Container_var pCont - = Engines::Container::_narrow(obj); + Engines::Container_var pCont = Engines::Container::_narrow(obj); _remove_ref(); - _containerName = _NS->BuildContainerNameForNS(containerName, - hostname.c_str()); + _containerName = SALOME_NamingService_Abstract::BuildContainerNameForNS(containerName, hostname.c_str()); SCRUTE(_containerName); _NS->Register(pCont, _containerName.c_str()); - MESSAGE("Engines_Container_i::Engines_Container_i : Container name " - << _containerName); + MESSAGE("Engines_Container_i::Engines_Container_i : Container name " << _containerName); // Python: // import SALOME_Container @@ -379,8 +379,17 @@ void Engines_Container_i::Shutdown() } _listInstances_map.clear(); - _NS->Destroy_FullDirectory(_containerName.c_str()); - _NS->Destroy_Name(_containerName.c_str()); + // NS unregistering may throw in SSL mode if master process hosting SALOME_Embedded_NamingService servant has vanished + // In this case it's skip it and still continue. + try + { + _NS->Destroy_FullDirectory(_containerName.c_str()); + _NS->Destroy_Name(_containerName.c_str()); + } + catch(...) + { + } + // if(_isServantAloneInProcess) { MESSAGE("Effective Shutdown of container Begins..."); @@ -1228,6 +1237,20 @@ Engines_Container_i::load_impl( const char* genericRegisterName, return iobject._retn(); } +Engines::EmbeddedNamingService_ptr Engines_Container_i::get_embedded_NS_if_ssl() +{ + SALOME_Embedded_NamingService_Client *nsc(dynamic_cast(this->_NS)); + if(nsc) + { + Engines::EmbeddedNamingService_var obj = nsc->GetObject(); + return Engines::EmbeddedNamingService::_duplicate(obj); + } + else + { + return Engines::EmbeddedNamingService::_nil(); + } +} + //============================================================================= //! Finds an already existing component instance or create a new instance /*! diff --git a/src/Container/SALOME_ComponentPy.py b/src/Container/SALOME_ComponentPy.py index 2ddb033d7..635f7e87e 100644 --- a/src/Container/SALOME_ComponentPy.py +++ b/src/Container/SALOME_ComponentPy.py @@ -41,6 +41,7 @@ import Engines, Engines__POA import Registry from Utils_Identity import * from SALOME_NamingServicePy import * +from SALOME_Embedded_NamingService_ClientPy import SALOME_Embedded_NamingService_ClientPy from libNOTIFICATION import * from SALOME_utilities import * @@ -296,12 +297,16 @@ class SALOME_ComponentPy_i(SALOME_ComponentPy_Gen_i): """ def __init__ (self, orb, poa, contID, containerName, instanceName, interfaceName, notif=False): SALOME_ComponentPy_Gen_i.__init__(self, orb, poa, contID, containerName, instanceName, interfaceName, notif) - naming_service = SALOME_NamingServicePy_i(self._orb) + emb_ns = self._contId.get_embedded_NS_if_ssl() + if CORBA.is_nil(emb_ns): + self._naming_service = SALOME_NamingServicePy_i(self._orb) + else: + self._naming_service = SALOME_Embedded_NamingService_ClientPy(emb_ns) Component_path = self._containerName + "/" + self._instanceName MESSAGE( 'SALOME_ComponentPy_i Register' + str( Component_path ) ) - naming_service.Register(self._compo_o, Component_path) + self._naming_service.Register(self._compo_o, Component_path) # Add componentinstance to registry - obj = naming_service.Resolve('/Registry') + obj = self._naming_service.Resolve('/Registry') if obj is None: MESSAGE( "Registry Reference is invalid" ) else: diff --git a/src/Container/SALOME_Container.cxx b/src/Container/SALOME_Container.cxx index 7c9c937c8..aee7f06dd 100644 --- a/src/Container/SALOME_Container.cxx +++ b/src/Container/SALOME_Container.cxx @@ -1,7 +1,4 @@ -// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// Copyright (C) 2021 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -20,215 +17,11 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// SALOME Container : implementation of container and engine for Kernel -// File : SALOME_Container.cxx -// Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA -// Module : SALOME -// $Header$ -// -#ifdef _MPI_SEQ_CONTAINER_ - #ifdef HAVE_MPI2 -#include - #endif -#endif - -#include -#include -#include -#include -#include -#ifndef WIN32 -# include -# include -#endif - - -#ifndef WIN32 -#include -#else -#include -#endif -#include "SALOME_Container_i.hxx" -#include "utilities.h" -#include "Utils_ORB_INIT.hxx" -#include "Utils_SINGLETON.hxx" -#include "OpUtil.hxx" - -#ifdef CHECKTIME -#include -#endif - -#include "Container_init_python.hxx" - -extern "C" void HandleServerSideSignals(CORBA::ORB_ptr theORB); - -#include -#include -#include -#ifndef WIN32 -# include -#endif - -void AttachDebugger(); -void Handler(int); -void terminateHandler(); -void unexpectedHandler(); - -#ifndef WIN32 -void (* setsig(int, void (*)(int)))(int); - -typedef void (*sighandler_t)(int); -sighandler_t setsig(int sig, sighandler_t handler) -{ - struct sigaction context, ocontext; - context.sa_handler = handler; - sigemptyset(&context.sa_mask); - context.sa_flags = 0; - if (sigaction(sig, &context, &ocontext) == -1) - return SIG_ERR; - return ocontext.sa_handler; -} -#endif //WIN32 - -void AttachDebugger() -{ -#ifndef WIN32 - if(getenv ("DEBUGGER")) - { - std::stringstream exec; - exec << "$DEBUGGER SALOME_Container " << getpid() << "&"; - std::cerr << exec.str() << std::endl; - system(exec.str().c_str()); - while(1); - } -#endif -} - -void Handler(int theSigId) -{ - std::cerr << "Signal= "<< theSigId << std::endl; - AttachDebugger(); - //to exit or not to exit - _exit(1); -} - -void terminateHandler(void) -{ - std::cerr << "Terminate: not managed exception !" << std::endl; - AttachDebugger(); -} - -void unexpectedHandler(void) -{ - std::cerr << "Unexpected: unexpected exception !" << std::endl; - AttachDebugger(); -} +#include "SALOME_Container_Common.hxx" +#include "SALOME_NamingService.hxx" int main(int argc, char* argv[]) { -#ifdef _MPI_SEQ_CONTAINER_ - #ifdef HAVE_MPI2 - MPI_Init(&argc,&argv); - #endif -#endif - -#ifndef WIN32 - if(getenv ("DEBUGGER")) - { - setsig(SIGSEGV,&Handler); - setsig(SIGFPE,&Handler); - std::set_terminate(&terminateHandler); - std::set_unexpected(&unexpectedHandler); - } -#endif - - // Initialise the ORB. - //SRN: BugID: IPAL9541, it's necessary to set a size of one message to be at least 100Mb - //CORBA::ORB_var orb = CORBA::ORB_init( argc , argv ) ; - ORB_INIT &init = *SINGLETON_::Instance() ; - ASSERT(SINGLETON_::IsAlreadyExisting()); - CORBA::ORB_ptr orb = init(argc , argv ) ; - - // LocalTraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb); - INFOS_COMPILATION; - BEGIN_OF(argv[0]); - - ASSERT(argc > 1); - SCRUTE(argv[1]); - - KERNEL_PYTHON::init_python(argc,argv); - - char *containerName = (char *)""; - if(argc > 1) - { - containerName = argv[1] ; - } - - try - { - CORBA::Object_var obj = orb->resolve_initial_references("RootPOA"); - ASSERT(!CORBA::is_nil(obj)); - PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj); - - PortableServer::POAManager_var pman = root_poa->the_POAManager(); - - // add new container to the kill list -#ifndef WIN32 - std::stringstream aCommand ; - aCommand << "addToKillList.py " << getpid() << " SALOME_Container" << std::ends ; - system(aCommand.str().c_str()); -#endif - - new Engines_Container_i(orb, root_poa, containerName , argc , argv ); - - pman->activate(); - -#ifdef CHECKTIME - Utils_Timer timer; - timer.Start(); - timer.Stop(); - timer.ShowAbsolute(); -#endif - - HandleServerSideSignals(orb); - -//#define MEMORYLEAKS -#ifdef MEMORYLEAKS - PyGILState_Ensure(); - //Destroy orb from python (for chasing memory leaks) - PyRun_SimpleString("from omniORB import CORBA"); - PyRun_SimpleString("orb=CORBA.ORB_init([''], CORBA.ORB_ID)"); - PyRun_SimpleString("orb.destroy()"); - Py_Finalize(); -#endif - } - catch(CORBA::SystemException&) - { - INFOS("Caught CORBA::SystemException."); - } - catch(PortableServer::POA::ServantAlreadyActive&) - { - INFOS("Caught CORBA::ServantAlreadyActiveException"); - } - catch(CORBA::Exception&) - { - INFOS("Caught CORBA::Exception."); - } - catch(std::exception& exc) - { - INFOS("Caught std::exception - "< ns; + return container_common_main(argc,argv,std::move(ns)); } - diff --git a/src/Container/SALOME_ContainerManager.cxx b/src/Container/SALOME_ContainerManager.cxx index 4129ea512..f709319f2 100644 --- a/src/Container/SALOME_ContainerManager.cxx +++ b/src/Container/SALOME_ContainerManager.cxx @@ -25,6 +25,7 @@ #include "SALOME_LoadRateManager.hxx" #include "SALOME_NamingService.hxx" #include "SALOME_ResourcesManager_Client.hxx" +#include "SALOME_Embedded_NamingService.hxx" #include "SALOME_ModuleCatalog.hh" #include "Basics_Utils.hxx" #include "Basics_DirUtils.hxx" @@ -81,7 +82,7 @@ Utils_Mutex SALOME_ContainerManager::_systemMutex; */ //============================================================================= -SALOME_ContainerManager::SALOME_ContainerManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_NamingService *ns) +SALOME_ContainerManager::SALOME_ContainerManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_NamingService_Abstract *ns) : _nbprocUsed(1) { MESSAGE("constructor"); @@ -469,7 +470,7 @@ SALOME_ContainerManager::LaunchContainer(const Engines::ContainerParameters& par // Mpi already tested in step 5, specific code on BuildCommandToLaunch Local/Remote Container methods // TODO -> separates Mpi from Classic/Exe // Classic or Exe ? - std::string container_exe = "SALOME_Container"; // Classic container + std::string container_exe = this->_isSSL ? "SALOME_Container_No_NS_Serv" : "SALOME_Container"; // Classic container Engines::ContainerParameters local_params(params); int found=0; try @@ -864,11 +865,21 @@ std::string SALOME_ContainerManager::BuildCommandToLaunchLocalContainer(const En o << container_exe + " "; } + + o << _NS->ContainerName(params) << " "; - o << _NS->ContainerName(params); - o << " -"; - AddOmninamesParams(o); - + if( this->_isSSL ) + { + Engines::EmbeddedNamingService_var ns = GetEmbeddedNamingService(); + CORBA::String_var iorNS = _orb->object_to_string(ns); + o << iorNS; + } + else + { + o << "-"; + AddOmninamesParams(o); + } + std::ofstream command_file( tmpFileName.c_str() ); command_file << o.str(); command_file.close(); @@ -951,11 +962,15 @@ void SALOME_ContainerManager::AddOmninamesParams(std::ostream& fileStream) const */ //============================================================================= -void SALOME_ContainerManager::AddOmninamesParams(std::ostream& fileStream, SALOME_NamingService *ns) +void SALOME_ContainerManager::AddOmninamesParams(std::ostream& fileStream, SALOME_NamingService_Abstract *ns) { - CORBA::String_var iorstr(ns->getIORaddr()); - fileStream << "ORBInitRef NameService="; - fileStream << iorstr; + SALOME_NamingService *nsTrad(dynamic_cast(ns)); + if(nsTrad) + { + CORBA::String_var iorstr(nsTrad->getIORaddr()); + fileStream << "ORBInitRef NameService="; + fileStream << iorstr; + } } void SALOME_ContainerManager::MakeTheCommandToBeLaunchedASync(std::string& command) diff --git a/src/Container/SALOME_ContainerManager.hxx b/src/Container/SALOME_ContainerManager.hxx index 946b6c8d4..bc8587ce3 100644 --- a/src/Container/SALOME_ContainerManager.hxx +++ b/src/Container/SALOME_ContainerManager.hxx @@ -35,14 +35,14 @@ #include #include -class SALOME_NamingService; +class SALOME_NamingService_Abstract; class SALOME_ResourcesManager_Client; class CONTAINER_EXPORT SALOME_ContainerManager : public POA_Engines::ContainerManager { public: - SALOME_ContainerManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_NamingService *ns); + SALOME_ContainerManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_NamingService_Abstract *ns); ~SALOME_ContainerManager(); // Corba Methods @@ -53,6 +53,8 @@ public: // C++ Methods void Shutdown(); + void DeclareUsingSalomeSession() { _isSSL = false; } + static const char *_ContainerManagerNameInNS; protected: @@ -106,7 +108,7 @@ protected: PortableServer::POA_var _poa; SALOME_ResourcesManager_Client *_resManager; - SALOME_NamingService *_NS; + SALOME_NamingService_Abstract *_NS; //! different behaviour if $APPLI exists (SALOME Application) bool _isAppliSalomeDefined; @@ -114,6 +116,9 @@ protected: //! attribute that contains the number of processes used in batch mode by MPI containers int _nbprocUsed; + //! attribute that specifies the launch mode. + bool _isSSL = true; + static omni_mutex _numInstanceMutex ; // lib and instance protection //! attributes to allow concurrency for // GiveContainer @@ -163,7 +168,7 @@ public: static std::string GetenvThreadSafeAsString(const char *name); static int SystemThreadSafe(const char *command); static long SystemWithPIDThreadSafe(const std::vector& command); - static void AddOmninamesParams(std::ostream& fileStream, SALOME_NamingService *ns); + static void AddOmninamesParams(std::ostream& fileStream, SALOME_NamingService_Abstract *ns); static void MakeTheCommandToBeLaunchedASync(std::string& command); static int GetTimeOutToLoaunchServer(); static void SleepInSecond(int ellapseTimeInSecond); diff --git a/src/Container/SALOME_Container_Common.cxx b/src/Container/SALOME_Container_Common.cxx new file mode 100644 index 000000000..be0512aea --- /dev/null +++ b/src/Container/SALOME_Container_Common.cxx @@ -0,0 +1,237 @@ +// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// SALOME Container : implementation of container and engine for Kernel +// File : SALOME_Container.cxx +// Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA +// Module : SALOME +// $Header$ +// +#ifdef _MPI_SEQ_CONTAINER_ + #ifdef HAVE_MPI2 +#include + #endif +#endif + +#include +#include +#include +#include +#include +#ifndef WIN32 +# include +# include +#endif + + +#ifndef WIN32 +#include +#else +#include +#endif +#include "SALOME_Container_i.hxx" +#include "utilities.h" +#include "Utils_ORB_INIT.hxx" +#include "Utils_SINGLETON.hxx" +#include "OpUtil.hxx" + +#ifdef CHECKTIME +#include +#endif + +#include "Container_init_python.hxx" + +extern "C" void HandleServerSideSignals(CORBA::ORB_ptr theORB); + +#include +#include +#include +#ifndef WIN32 +# include +#endif + +#include + +void AttachDebugger(); +void Handler(int); +void terminateHandler(); +void unexpectedHandler(); + +#ifndef WIN32 +void (* setsig(int, void (*)(int)))(int); + +typedef void (*sighandler_t)(int); +sighandler_t setsig(int sig, sighandler_t handler) +{ + struct sigaction context, ocontext; + context.sa_handler = handler; + sigemptyset(&context.sa_mask); + context.sa_flags = 0; + if (sigaction(sig, &context, &ocontext) == -1) + return SIG_ERR; + return ocontext.sa_handler; +} +#endif //WIN32 + +void AttachDebugger() +{ +#ifndef WIN32 + if(getenv ("DEBUGGER")) + { + std::stringstream exec; + exec << "$DEBUGGER SALOME_Container " << getpid() << "&"; + std::cerr << exec.str() << std::endl; + system(exec.str().c_str()); + while(1); + } +#endif +} + +void Handler(int theSigId) +{ + std::cerr << "Signal= "<< theSigId << std::endl; + AttachDebugger(); + //to exit or not to exit + _exit(1); +} + +void terminateHandler(void) +{ + std::cerr << "Terminate: not managed exception !" << std::endl; + AttachDebugger(); +} + +void unexpectedHandler(void) +{ + std::cerr << "Unexpected: unexpected exception !" << std::endl; + AttachDebugger(); +} + +int container_common_main(int argc, char* argv[], std::unique_ptr ns) +{ +#ifdef _MPI_SEQ_CONTAINER_ + #ifdef HAVE_MPI2 + MPI_Init(&argc,&argv); + #endif +#endif + +#ifndef WIN32 + if(getenv ("DEBUGGER")) + { + setsig(SIGSEGV,&Handler); + setsig(SIGFPE,&Handler); + std::set_terminate(&terminateHandler); + std::set_unexpected(&unexpectedHandler); + } +#endif + + // Initialise the ORB. + //SRN: BugID: IPAL9541, it's necessary to set a size of one message to be at least 100Mb + //CORBA::ORB_var orb = CORBA::ORB_init( argc , argv ) ; + ORB_INIT &init = *SINGLETON_::Instance() ; + ASSERT(SINGLETON_::IsAlreadyExisting()); + CORBA::ORB_ptr orb = init(argc , argv ) ; + + // LocalTraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb); + INFOS_COMPILATION; + BEGIN_OF(argv[0]); + + ASSERT(argc > 1); + SCRUTE(argv[1]); + + KERNEL_PYTHON::init_python(argc,argv); + + char *containerName = (char *)""; + if(argc > 1) + { + containerName = argv[1] ; + } + + try + { + CORBA::Object_var obj = orb->resolve_initial_references("RootPOA"); + ASSERT(!CORBA::is_nil(obj)); + PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj); + + PortableServer::POAManager_var pman = root_poa->the_POAManager(); + + // add new container to the kill list +#ifndef WIN32 + std::stringstream aCommand ; + aCommand << "addToKillList.py " << getpid() << " SALOME_Container" << std::ends ; + system(aCommand.str().c_str()); +#endif + + new Engines_Container_i(orb, root_poa, containerName , argc , argv, ns.get() ); + ns.release(); + + pman->activate(); + +#ifdef CHECKTIME + Utils_Timer timer; + timer.Start(); + timer.Stop(); + timer.ShowAbsolute(); +#endif + + HandleServerSideSignals(orb); + +//#define MEMORYLEAKS +#ifdef MEMORYLEAKS + PyGILState_Ensure(); + //Destroy orb from python (for chasing memory leaks) + PyRun_SimpleString("from omniORB import CORBA"); + PyRun_SimpleString("orb=CORBA.ORB_init([''], CORBA.ORB_ID)"); + PyRun_SimpleString("orb.destroy()"); + Py_Finalize(); +#endif + } + catch(CORBA::SystemException&) + { + INFOS("Caught CORBA::SystemException."); + } + catch(PortableServer::POA::ServantAlreadyActive&) + { + INFOS("Caught CORBA::ServantAlreadyActiveException"); + } + catch(CORBA::Exception&) + { + INFOS("Caught CORBA::Exception."); + } + catch(std::exception& exc) + { + INFOS("Caught std::exception - "< + +int CONTAINER_EXPORT container_common_main(int argc, char* argv[], std::unique_ptr ns); diff --git a/src/Container/SALOME_Container_No_NS_Serv.cxx b/src/Container/SALOME_Container_No_NS_Serv.cxx new file mode 100644 index 000000000..6d8018450 --- /dev/null +++ b/src/Container/SALOME_Container_No_NS_Serv.cxx @@ -0,0 +1,38 @@ +// Copyright (C) 2021 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "SALOME_Container_Common.hxx" +#include "SALOME_Embedded_NamingService_Client.hxx" +#include "Utils_SALOME_Exception.hxx" +#include "SALOME_KernelORB.hxx" + +int main(int argc, char* argv[]) +{ + if(argc<3) + THROW_SALOME_EXCEPTION( "SALOME_Container_No_NS_Serv : requires 2 input arguments " ); + CORBA::ORB_ptr orb(KERNEL::getORB()); + CORBA::Object_var ns_serv_obj_base = orb->string_to_object(argv[2]); + if( CORBA::is_nil(ns_serv_obj_base) ) + THROW_SALOME_EXCEPTION( "SALOME_Container_No_NS_Serv : argument 2 is NOT a valid IOR" ); + Engines::EmbeddedNamingService_var ns_serv_obj = Engines::EmbeddedNamingService::_narrow(ns_serv_obj_base); + if( CORBA::is_nil(ns_serv_obj) ) + THROW_SALOME_EXCEPTION( "SALOME_Container_No_NS_Serv : argument 2 is NOT a valid IOR of Engines::EmbeddedNamingService" ); + std::unique_ptr ns( new SALOME_Embedded_NamingService_Client(ns_serv_obj) ); + return container_common_main(argc,argv,std::move(ns)); +} diff --git a/src/Container/SALOME_Container_i.hxx b/src/Container/SALOME_Container_i.hxx index 244221993..f0a8e4e76 100644 --- a/src/Container/SALOME_Container_i.hxx +++ b/src/Container/SALOME_Container_i.hxx @@ -48,7 +48,7 @@ #include #include -class SALOME_NamingService_Abstract; +class SALOME_NamingService_Container_Abstract; class CONTAINER_EXPORT Engines_Container_i: public virtual POA_Engines::Container, @@ -60,7 +60,7 @@ public: PortableServer::POA_ptr poa, char * containerName , int argc, char* argv[], - SALOME_NamingService_Abstract *ns = nullptr, + SALOME_NamingService_Container_Abstract *ns = nullptr, bool isServantAloneInProcess = true); virtual ~Engines_Container_i(); @@ -87,6 +87,7 @@ public: load_impl(const char* nameToRegister, const char* componentName); + Engines::EmbeddedNamingService_ptr get_embedded_NS_if_ssl() override; void remove_impl(Engines::EngineComponent_ptr component_i); void finalize_removal(); @@ -151,7 +152,7 @@ protected: bool _isSupervContainer; - SALOME_NamingService_Abstract *_NS ; + SALOME_NamingService_Container_Abstract *_NS ; std::string _library_path; std::string _containerName; std::string _logfilename; diff --git a/src/KERNEL_PY/__init__.py b/src/KERNEL_PY/__init__.py index 5952cc924..cbe51e8e0 100644 --- a/src/KERNEL_PY/__init__.py +++ b/src/KERNEL_PY/__init__.py @@ -177,7 +177,11 @@ def salome_init(path=None, embedded=False): if __EMB_SERVANT_ENV_VAR_NAME in os.environ: salome_init_without_session() else: - salome_init_with_session(path, embedded) + import KernelBasis + if KernelBasis.getSSLMode(): + salome_init_without_session() + else: + salome_init_with_session(path, embedded) class StandAloneLifecyle: def FindOrLoadComponent(self,contName,moduleName): @@ -190,8 +194,10 @@ class StandAloneLifecyle: #raise RuntimeError("Undealed situation cont = {} module = {}".format(contName,moduleName)) def salome_init_without_session(): - global lcc,myStudy,orb,modulcat,sg + global lcc,myStudy,orb,modulcat,sg,cm lcc = StandAloneLifecyle() + import KernelBasis + KernelBasis.setSSLMode(True) import KernelDS myStudy = KernelDS.myStudy() import CORBA @@ -200,6 +206,8 @@ def salome_init_without_session(): import SALOME_ModuleCatalog from salome_kernel import list_of_catalogs_regarding_environement modulcat = KernelModuleCatalog.myModuleCatalog( list_of_catalogs_regarding_environement() ) + import KernelLauncher + cm = KernelLauncher.myContainerManager() # activate poaManager to accept co-localized CORBA calls. poa = orb.resolve_initial_references("RootPOA") poaManager = poa._get_the_POAManager() @@ -226,7 +234,8 @@ def salome_init_with_session(path=None, embedded=False): global orb, lcc, naming_service, cm, esm, dsm, modulcat global sg global myStudy, myStudyName - + import KernelBasis + KernelBasis.setSSLMode(False) try: if salome_initial: salome_initial=False diff --git a/src/KernelHelpers/CMakeLists.txt b/src/KernelHelpers/CMakeLists.txt index 9c8ce0461..f03b04cd7 100644 --- a/src/KernelHelpers/CMakeLists.txt +++ b/src/KernelHelpers/CMakeLists.txt @@ -36,8 +36,16 @@ INCLUDE_DIRECTORIES( ${PROJECT_BINARY_DIR}/idl ) +SET(SalomeORB_SOURCES + SALOME_KernelORB.cxx +) + +ADD_LIBRARY(SalomeORB ${SalomeORB_SOURCES}) +TARGET_LINK_LIBRARIES(SalomeORB ${OMNIORB_LIBRARIES}) +INSTALL(TARGETS SalomeORB EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS}) + SET(SalomeKernelHelpers_LIBS - ${OMNIORB_LIBRARIES} + SalomeORB SalomeNS SALOMELocalTrace SALOMEBasics diff --git a/src/KernelHelpers/SALOME_KernelORB.cxx b/src/KernelHelpers/SALOME_KernelORB.cxx new file mode 100644 index 000000000..ed8b9da78 --- /dev/null +++ b/src/KernelHelpers/SALOME_KernelORB.cxx @@ -0,0 +1,36 @@ +// Copyright (C) 2021 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "SALOME_KernelORB.hxx" + +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); + } + return orb; + } +} diff --git a/src/KernelHelpers/SALOME_KernelORB.hxx b/src/KernelHelpers/SALOME_KernelORB.hxx new file mode 100644 index 000000000..4c0980959 --- /dev/null +++ b/src/KernelHelpers/SALOME_KernelORB.hxx @@ -0,0 +1,31 @@ +// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// Author: Guillaume Boulant (EDF/R&D) + +#pragma once + +#include "KernelHelpers.hxx" + +#include + +namespace KERNEL +{ + KERNELHELPERS_EXPORT CORBA::ORB_ptr getORB(); +} diff --git a/src/KernelHelpers/SALOME_KernelServices.cxx b/src/KernelHelpers/SALOME_KernelServices.cxx index 61e59350b..efc9bf85e 100644 --- a/src/KernelHelpers/SALOME_KernelServices.cxx +++ b/src/KernelHelpers/SALOME_KernelServices.cxx @@ -31,20 +31,6 @@ 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); - } - return orb; - } - void assignNamingServiceSL() { if ( !_naming_service.get() ) diff --git a/src/KernelHelpers/SALOME_KernelServices.hxx b/src/KernelHelpers/SALOME_KernelServices.hxx index decc6fd17..42f8dc638 100644 --- a/src/KernelHelpers/SALOME_KernelServices.hxx +++ b/src/KernelHelpers/SALOME_KernelServices.hxx @@ -34,11 +34,12 @@ #include "SALOME_NamingService.hxx" #include "SALOME_LifeCycleCORBA.hxx" +#include "SALOME_KernelORB.hxx" + namespace KERNEL { // --------------------------------------------- // SALOME KERNEL main services - KERNELHELPERS_EXPORT CORBA::ORB_ptr getORB(); KERNELHELPERS_EXPORT SALOME_NamingService_Abstract *getNamingService(); KERNELHELPERS_EXPORT void assignNamingServiceSL(); KERNELHELPERS_EXPORT SALOME_LifeCycleCORBA * getLifeCycleCORBA(); diff --git a/src/Launcher/CMakeLists.txt b/src/Launcher/CMakeLists.txt index 47ee394cf..f1460e472 100644 --- a/src/Launcher/CMakeLists.txt +++ b/src/Launcher/CMakeLists.txt @@ -17,6 +17,8 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # +include(${SWIG_USE_FILE}) + IF(SALOME_BUILD_TESTS) ADD_SUBDIRECTORY(Test) ENDIF(SALOME_BUILD_TESTS) @@ -38,7 +40,10 @@ INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/../Container ${CMAKE_CURRENT_SOURCE_DIR}/../ResourcesManager ${CMAKE_CURRENT_SOURCE_DIR}/../SALOMESDS + ${CMAKE_CURRENT_SOURCE_DIR}/../LifeCycleCORBA + ${CMAKE_CURRENT_SOURCE_DIR}/../KernelHelpers ${PROJECT_BINARY_DIR}/idl + ${CMAKE_CURRENT_SOURCE_DIR} ) ADD_DEFINITIONS(${LIBXML2_DEFINITIONS} ${BOOST_DEFINITIONS} ${OMNIORB_DEFINITIONS}) @@ -131,12 +136,30 @@ SET(COMMON_HEADERS_HXX SALOME_Launcher_defs.hxx SALOME_ExternalServerLauncher.hxx SALOME_LauncherException.hxx + KernelLauncher.hxx ) SET(LAUNCHER_PYTHON_SCRIPTS launcher_proxy.py ) +SET(KernelLauncher_HEADERS KernelLauncher.hxx KernelLauncher.i) +SET(KernelLauncher_SOURCES KernelLauncher.cxx ${KernelLauncher_HEADERS}) +SET_SOURCE_FILES_PROPERTIES(KernelLauncher.i PROPERTIES CPLUSPLUS ON) +SET_SOURCE_FILES_PROPERTIES(KernelLauncher.i PROPERTIES SWIG_FLAGS "-py3") +SET_SOURCE_FILES_PROPERTIES(KernelLauncher_wrap.cpp PROPERTIES COMPILE_FLAGS "-DHAVE_CONFIG_H") +SET(_swig_SCRIPTS ${CMAKE_CURRENT_BINARY_DIR}/KernelLauncher.py ) +IF(${CMAKE_VERSION} VERSION_LESS "3.8.0") + SWIG_ADD_MODULE(KernelLauncher python ${KernelLauncher_SOURCES}) +ELSE() + SWIG_ADD_LIBRARY(KernelLauncher LANGUAGE python SOURCES ${KernelLauncher_SOURCES}) +ENDIF() +SWIG_LINK_LIBRARIES(KernelLauncher ${PYTHON_LIBRARIES} ${PLATFORM_LIBS} SalomeDS SalomeKernelHelpers) +install(TARGETS _KernelLauncher DESTINATION ${SALOME_INSTALL_LIBS}) +install(FILES ${KernelLauncher_HEADERS} DESTINATION ${SALOME_INSTALL_HEADERS}) +SALOME_INSTALL_SCRIPTS("${_swig_SCRIPTS}" ${SALOME_INSTALL_BINS} EXTRA_DPYS "${SWIG_MODULE_KernelLauncher_REAL_NAME}") + + INSTALL(FILES ${COMMON_HEADERS_HXX} DESTINATION ${SALOME_INSTALL_HEADERS}) INSTALL(FILES testLauncher.xml DESTINATION ${SALOME_KERNEL_INSTALL_RES_DATA}) SALOME_INSTALL_SCRIPTS("${LAUNCHER_PYTHON_SCRIPTS}" ${SALOME_INSTALL_PYTHON}) diff --git a/src/Launcher/KernelLauncher.cxx b/src/Launcher/KernelLauncher.cxx new file mode 100644 index 000000000..05213a884 --- /dev/null +++ b/src/Launcher/KernelLauncher.cxx @@ -0,0 +1,37 @@ +// Copyright (C) 2021 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "KernelLauncher.hxx" + +#include "SALOME_Launcher.hxx" +#include "SALOME_ContainerManager.hxx" +#include "SALOME_Fake_NamingService.hxx" +#include "SALOME_KernelServices.hxx" + +#include + +std::string GetContainerManagerInstance() +{ + SALOME_Launcher *launcher = KERNEL::getLauncherSA(); + SALOME_Fake_NamingService ns; + CORBA::Object_var cm = ns.Resolve(SALOME_ContainerManager::_ContainerManagerNameInNS); + CORBA::ORB_ptr orb = KERNEL::getORB(); + CORBA::String_var ior = orb->object_to_string(cm); + return std::string(ior.in()); +} diff --git a/src/Launcher/KernelLauncher.hxx b/src/Launcher/KernelLauncher.hxx new file mode 100644 index 000000000..378843b99 --- /dev/null +++ b/src/Launcher/KernelLauncher.hxx @@ -0,0 +1,24 @@ +// Copyright (C) 2021 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#pragma once + +#include + +std::string GetContainerManagerInstance(); diff --git a/src/Launcher/KernelLauncher.i b/src/Launcher/KernelLauncher.i new file mode 100644 index 000000000..013758ca5 --- /dev/null +++ b/src/Launcher/KernelLauncher.i @@ -0,0 +1,39 @@ +// Copyright (C) 2021 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +%module KernelLauncher + +%include "std_string.i" + +%{ +#include "KernelLauncher.hxx" +%} + +%inline +{ + std::string GetContainerManagerInstance(); +} + +%pythoncode %{ +def myContainerManager(): + import Engines + import CORBA + orb=CORBA.ORB_init(['']) + return orb.string_to_object(GetContainerManagerInstance()) +%} diff --git a/src/Launcher/SALOME_Launcher.cxx b/src/Launcher/SALOME_Launcher.cxx index 6001ca944..11d16abac 100644 --- a/src/Launcher/SALOME_Launcher.cxx +++ b/src/Launcher/SALOME_Launcher.cxx @@ -73,9 +73,9 @@ SALOME_Launcher::SALOME_Launcher(CORBA::ORB_ptr orb, PortableServer::POA_var poa void SALOME_Launcher::init(CORBA::ORB_ptr orb, PortableServer::POA_var poa) { - _ResManager = new SALOME_ResourcesManager(orb,poa,tradNS()); + _ResManager = new SALOME_ResourcesManager(orb,poa,_NS); _l.SetResourcesManager(_ResManager->GetImpl()); - _ContManager = new SALOME_ContainerManager(orb,poa,tradNS()); + _ContManager = new SALOME_ContainerManager(orb,poa,_NS); _ResManager->_remove_ref(); _ContManager->_remove_ref(); @@ -241,6 +241,11 @@ SALOME_Launcher::getJobWorkFile(CORBA::Long job_id, const char * work_file, cons return rtn; } +void SALOME_Launcher::DeclareUsingSalomeSession() +{ + this->_ContManager->DeclareUsingSalomeSession(); +} + void SALOME_Launcher::removeJob(CORBA::Long job_id) { diff --git a/src/Launcher/SALOME_Launcher.hxx b/src/Launcher/SALOME_Launcher.hxx index cd72c7a16..9fcbc2023 100644 --- a/src/Launcher/SALOME_Launcher.hxx +++ b/src/Launcher/SALOME_Launcher.hxx @@ -77,6 +77,8 @@ public: // Save and load methods virtual void loadJobs(const char* jobs_file); virtual void saveJobs(const char* jobs_file); + + void DeclareUsingSalomeSession(); static const char *_LauncherNameInNS; @@ -86,8 +88,6 @@ public: static Engines::JobParameters_var JobParameters_CPP2CORBA(const JobParameters_cpp& job_parameters); - SALOME_NamingService *tradNS() { return SALOME_NamingService::GetTraditionalNS(_NS); } - protected: // Internal methods virtual void notifyObservers(const std::string & event_name, const std::string & event_data); diff --git a/src/Launcher/SALOME_LauncherServer.cxx b/src/Launcher/SALOME_LauncherServer.cxx index 34d6e5541..4692f5e2b 100644 --- a/src/Launcher/SALOME_LauncherServer.cxx +++ b/src/Launcher/SALOME_LauncherServer.cxx @@ -118,6 +118,7 @@ int main(int argc, char* argv[]) SALOME_CPythonHelper cPyh; cPyh.initializePython(argc,argv); SALOME_Launcher *lServ(new SALOME_Launcher(orb,safePOA)); + lServ->DeclareUsingSalomeSession(); lServ->_remove_ref(); // SALOMESDS::DataServerManager *dsm(new SALOMESDS::DataServerManager(&cPyh,orb,root_poa)); diff --git a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx index aa7ed4480..08223ade7 100644 --- a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx +++ b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx @@ -104,7 +104,7 @@ SALOME_LifeCycleCORBA::SALOME_LifeCycleCORBA(SALOME_NamingService_Abstract *ns) // not enough: set a current directory in naming service is not thread safe // if naming service instance is shared among several threads... // ==> always use absolute path and don't rely on current directory! - if( dynamic_cast(_NS) ) + //if( dynamic_cast(_NS) ) { CORBA::Object_var obj = _NS->Resolve(SALOME_ContainerManager::_ContainerManagerNameInNS); diff --git a/src/ModuleCatalog/KernelModuleCatalog.cxx b/src/ModuleCatalog/KernelModuleCatalog.cxx index bc9237306..4677773f1 100644 --- a/src/ModuleCatalog/KernelModuleCatalog.cxx +++ b/src/ModuleCatalog/KernelModuleCatalog.cxx @@ -22,8 +22,8 @@ std::string GetModuleCatalogInstance(const std::string& listOfCatalogsGrouped) { - SALOME_ModuleCatalog::ModuleCatalog_var study = KERNEL::getModuleComponentServantSA(listOfCatalogsGrouped.c_str()); + SALOME_ModuleCatalog::ModuleCatalog_var cata = KERNEL::getModuleComponentServantSA(listOfCatalogsGrouped.c_str()); CORBA::ORB_ptr orb = KERNEL::getORB(); - CORBA::String_var ior = orb->object_to_string(study); + CORBA::String_var ior = orb->object_to_string(cata); return std::string(ior.in()); } diff --git a/src/ModuleCatalog/SALOME_ModuleCatalog_Server.cxx b/src/ModuleCatalog/SALOME_ModuleCatalog_Server.cxx index d60f9f0fc..01819c8bf 100644 --- a/src/ModuleCatalog/SALOME_ModuleCatalog_Server.cxx +++ b/src/ModuleCatalog/SALOME_ModuleCatalog_Server.cxx @@ -147,7 +147,7 @@ int main(int argc,char **argv) // initialise Naming Service SALOME_NamingService _NS(orb); // register Catalog in Naming Service - _NS.Register(myCata ,"/Kernel/ModulCatalog"); + _NS.Register(myCata ,SALOME_ModuleCatalogImpl::ENTRY_IN_NS); MESSAGE("Running CatalogServer."); diff --git a/src/ModuleCatalog/SALOME_ModuleCatalog_impl.cxx b/src/ModuleCatalog/SALOME_ModuleCatalog_impl.cxx index f6877ae35..112d0a12e 100644 --- a/src/ModuleCatalog/SALOME_ModuleCatalog_impl.cxx +++ b/src/ModuleCatalog/SALOME_ModuleCatalog_impl.cxx @@ -29,6 +29,8 @@ #include "SALOME_ModuleCatalog_impl.hxx" #include "SALOME_ModuleCatalog_Acomponent_impl.hxx" #include "SALOME_ModuleCatalog_Handler.hxx" +#include "SALOME_Fake_NamingService.hxx" + #include #include #include @@ -60,6 +62,8 @@ static int MYDEBUG = 0; static const char* SEPARATOR = "::"; static const char* OLD_SEPARATOR = ":"; +const char SALOME_ModuleCatalogImpl::ENTRY_IN_NS[] = "/Kernel/ModulCatalog"; + SALOME_ModuleCatalog::ModuleCatalog_ptr KERNEL::getModuleComponentServantSA(const char *listOfCatalogs) { static SALOME_ModuleCatalog::ModuleCatalog_var moduleCata; @@ -72,6 +76,8 @@ SALOME_ModuleCatalog::ModuleCatalog_ptr KERNEL::getModuleComponentServantSA(cons argv[2] = const_cast(listOfCatalogs); SALOME_ModuleCatalogImpl *servant = new SALOME_ModuleCatalogImpl(NB_OF_ELT_IN_CMD,argv,orb); moduleCata = servant->_this(); + SALOME_Fake_NamingService NS; + NS.Register(moduleCata,SALOME_ModuleCatalogImpl::ENTRY_IN_NS); } return SALOME_ModuleCatalog::ModuleCatalog::_duplicate(moduleCata); } diff --git a/src/ModuleCatalog/SALOME_ModuleCatalog_impl.hxx b/src/ModuleCatalog/SALOME_ModuleCatalog_impl.hxx index 05ccfd864..88f9118fa 100644 --- a/src/ModuleCatalog/SALOME_ModuleCatalog_impl.hxx +++ b/src/ModuleCatalog/SALOME_ModuleCatalog_impl.hxx @@ -132,6 +132,8 @@ public: //! shutdown server void shutdown(); + static const char ENTRY_IN_NS[]; + private: //! method to parse arguments to get general and personal catalog files /*! diff --git a/src/NamingService/CMakeLists.txt b/src/NamingService/CMakeLists.txt index 7009bac9a..051bfb4bb 100644 --- a/src/NamingService/CMakeLists.txt +++ b/src/NamingService/CMakeLists.txt @@ -17,6 +17,8 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # +include(${SWIG_USE_FILE}) + INCLUDE_DIRECTORIES( ${OMNIORB_INCLUDE_DIR} ${PTHREAD_INCLUDE_DIR} @@ -24,7 +26,11 @@ INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/../Basics ${CMAKE_CURRENT_SOURCE_DIR}/../SALOMELocalTrace ${CMAKE_CURRENT_SOURCE_DIR}/../Utils + ${CMAKE_CURRENT_SOURCE_DIR}/../KernelHelpers + ${CMAKE_CURRENT_SOURCE_DIR}/../LifeCycleCORBA + ${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_BINARY_DIR}/idl + ${PYTHON_INCLUDE_DIRS} ) SET(SalomeNS_SOURCES @@ -33,18 +39,37 @@ SET(SalomeNS_SOURCES NamingService_WaitForServerReadiness.cxx SALOME_Fake_NamingService.cxx SALOME_NamingService_Abstract.cxx + SALOME_Embedded_NamingService.cxx + SALOME_Embedded_NamingService_Common.cxx + SALOME_Embedded_NamingService_Client.cxx ) - ADD_DEFINITIONS(${OMNIORB_DEFINITIONS}) ADD_LIBRARY(SalomeNS ${SalomeNS_SOURCES}) ADD_DEPENDENCIES(SalomeNS SalomeIDLKernel) -TARGET_LINK_LIBRARIES(SalomeNS OpUtil) +TARGET_LINK_LIBRARIES(SalomeNS OpUtil SalomeORB) INSTALL(TARGETS SalomeNS EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS}) # Executable scripts to be installed SALOME_INSTALL_SCRIPTS(SALOME_NamingServicePy.py ${SALOME_INSTALL_SCRIPT_PYTHON}) +SALOME_INSTALL_SCRIPTS(SALOME_Embedded_NamingService_ClientPy.py ${SALOME_INSTALL_SCRIPT_PYTHON}) FILE(GLOB COMMON_HEADERS_HXX "${CMAKE_CURRENT_SOURCE_DIR}/*.hxx") INSTALL(FILES ${COMMON_HEADERS_HXX} DESTINATION ${SALOME_INSTALL_HEADERS}) + +SET(NamingService_HEADERS NamingService.i) +SET(NamingService_SOURCES ${NamingService_HEADERS}) +SET_SOURCE_FILES_PROPERTIES(NamingService.i PROPERTIES CPLUSPLUS ON) +SET_SOURCE_FILES_PROPERTIES(NamingService.i PROPERTIES SWIG_FLAGS "-py3") +SET_SOURCE_FILES_PROPERTIES(NamingService_wrap.cpp PROPERTIES COMPILE_FLAGS "-DHAVE_CONFIG_H") +SET(_swig_SCRIPTS ${CMAKE_CURRENT_BINARY_DIR}/NamingService.py ) +IF(${CMAKE_VERSION} VERSION_LESS "3.8.0") + SWIG_ADD_MODULE(NamingService python ${NamingService_SOURCES}) +ELSE() + SWIG_ADD_LIBRARY(NamingService LANGUAGE python SOURCES ${NamingService_SOURCES}) +ENDIF() +SWIG_LINK_LIBRARIES(NamingService ${PYTHON_LIBRARIES} ${PLATFORM_LIBS} SalomeNS) +install(TARGETS _NamingService DESTINATION ${SALOME_INSTALL_LIBS}) +install(FILES ${NamingService_HEADERS} DESTINATION ${SALOME_INSTALL_HEADERS}) +SALOME_INSTALL_SCRIPTS("${_swig_SCRIPTS}" ${SALOME_INSTALL_BINS} EXTRA_DPYS "${SWIG_MODULE_NamingService_REAL_NAME}") diff --git a/src/NamingService/NamingService.i b/src/NamingService/NamingService.i new file mode 100644 index 000000000..08b58d996 --- /dev/null +++ b/src/NamingService/NamingService.i @@ -0,0 +1,138 @@ +// Copyright (C) 2021 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +%module NamingService + +%{ +#include "SALOME_Fake_NamingService.hxx" +#include "SALOME_Embedded_NamingService.hxx" +#include "SALOME_KernelORB.hxx" +#include "Utils_SALOME_Exception.hxx" +%} + +%include "std_string.i" +%include "std_vector.i" + +%rename(NamingService) SALOME_Fake_NamingService ; + +%template(svec) std::vector; + +%exceptionclass SALOME_Exception; + +class SALOME_Exception +{ +public: + SALOME_Exception(const std::string& text); + ~SALOME_Exception() noexcept; + const char *what() const noexcept; + %extend + { + std::string __str__() const + { + return std::string(self->what()); + } + } +}; + +%exception { + try { + $action + } + catch (SALOME_Exception& _e) { + // Reraise with SWIG_Python_Raise + SWIG_Python_Raise(SWIG_NewPointerObj((new SALOME_Exception(static_cast< const SALOME_Exception& >(_e))),SWIGTYPE_p_SALOME_Exception,SWIG_POINTER_OWN), "SALOME_Exception", SWIGTYPE_p_SALOME_Exception); + SWIG_fail; + } +} + +class SALOME_Fake_NamingService +{ +public: + SALOME_Fake_NamingService(); + std::vector< std::string > repr(); + static std::string GetLogContainersFile(); + static void FlushLogContainersFile(); + %extend { + static void SetLogContainersFileInternal(const std::string& logFileName) + { + SALOME_Fake_NamingService::SetLogContainersFile(logFileName); + } + std::string _ResolveInternal(const char *Path) + { + CORBA::Object_var obj = self->Resolve(Path); + CORBA::ORB_ptr orb = KERNEL::getORB(); + CORBA::String_var ior = orb->object_to_string(obj); + return std::string(ior); + } + void _RegisterInternal(const char *ior, const char* Path) + { + CORBA::ORB_ptr orb = KERNEL::getORB(); + CORBA::Object_var obj = orb->string_to_object(ior); + self->Register(obj,Path); + } + static std::string IOROfNS() + { + CORBA::ORB_ptr orb = KERNEL::getORB(); + Engines::EmbeddedNamingService_var ns = GetEmbeddedNamingService(); + CORBA::String_var ior = orb->object_to_string(ns); + return std::string(ior); + } + } +}; + +%pythoncode %{ +def NamingService_Resolve(self,Path): + ret = self._ResolveInternal(Path) + import CORBA + orb=CORBA.ORB_init(['']) + return orb.string_to_object(ret) +def NamingService_Register(self,obj,Path): + import CORBA + orb=CORBA.ORB_init(['']) + self._RegisterInternal( orb.object_to_string(obj) , Path) +NamingService.Resolve = NamingService_Resolve +NamingService.Register = NamingService_Register +def NamingService_SetLogContainersFile(cls,logFileName = None): + if logFileName is None: + import tempfile + with tempfile.NamedTemporaryFile() as f: + logFileName = f.name + cls.SetLogContainersFileInternal(logFileName) +NamingService.SetLogContainersFile = classmethod(NamingService_SetLogContainersFile) +def NamingService_RefOfNS(cls): + ret = cls.IOROfNS() + import Engines + import CORBA + orb=CORBA.ORB_init(['']) + return orb.string_to_object(ret) +NamingService.RefOfNS = classmethod(NamingService_RefOfNS) +def NamingService_KillContainersInFile(cls,logFileName): + import Engines + import CORBA + orb=CORBA.ORB_init(['']) + with open(logFileName) as f: + cont_to_kill = [elt.split(" : ") for elt in f] + for name,ior in cont_to_kill: + try: + ref = orb.string_to_object(ior) + ref.Shutdown() + except Exception as e: + print("Failed to kill container remotely \"{}\"".format(name)) +NamingService.KillContainersInFile = classmethod(NamingService_KillContainersInFile) +%} diff --git a/src/NamingService/SALOME_Embedded_NamingService.cxx b/src/NamingService/SALOME_Embedded_NamingService.cxx new file mode 100644 index 000000000..ed4066ce7 --- /dev/null +++ b/src/NamingService/SALOME_Embedded_NamingService.cxx @@ -0,0 +1,71 @@ +// Copyright (C) 2021 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "SALOME_Embedded_NamingService.hxx" +#include "SALOME_Embedded_NamingService_Common.hxx" +#include "SALOME_Fake_NamingService.hxx" + +#include +#include + +static Engines::EmbeddedNamingService_var _embedded_ns_singleton; + +Engines::EmbeddedNamingService_var GetEmbeddedNamingService() +{ + if( CORBA::is_nil(_embedded_ns_singleton) ) + { + std::unique_ptr servant(new SALOME_Embedded_NamingService); + _embedded_ns_singleton = servant->_this(); + servant->_remove_ref(); + servant.release(); + } + return _embedded_ns_singleton; +} + +void SALOME_Embedded_NamingService::Register(const Engines::IORType& ObjRef, const char *Path) +{ + SALOME_Fake_NamingService ns; + ns.Register(IORToObject(ObjRef),Path); +} + +void SALOME_Embedded_NamingService::Destroy_FullDirectory(const char *Path) +{ + SALOME_Fake_NamingService ns; + ns.Destroy_FullDirectory(Path); +} + +void SALOME_Embedded_NamingService::Destroy_Name(const char *Path) +{ + SALOME_Fake_NamingService ns; + ns.Destroy_Name(Path); +} + +Engines::IORType *SALOME_Embedded_NamingService::Resolve(const char *Path) +{ + SALOME_Fake_NamingService ns; + CORBA::Object_var obj = ns.Resolve(Path); + return ObjectToIOR(obj); +} + +Engines::IORType *SALOME_Embedded_NamingService::ResolveFirst(const char *Path) +{ + SALOME_Fake_NamingService ns; + CORBA::Object_var obj = ns.ResolveFirst(Path); + return ObjectToIOR(obj); +} diff --git a/src/NamingService/SALOME_Embedded_NamingService.hxx b/src/NamingService/SALOME_Embedded_NamingService.hxx new file mode 100644 index 000000000..1fde6b39a --- /dev/null +++ b/src/NamingService/SALOME_Embedded_NamingService.hxx @@ -0,0 +1,37 @@ +// Copyright (C) 2021 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#pragma once + +#include "SALOME_NamingService_defs.hxx" + +#include +#include CORBA_CLIENT_HEADER(SALOME_Embedded_NamingService) + +Engines::EmbeddedNamingService_var NAMINGSERVICE_EXPORT GetEmbeddedNamingService(); + +class NAMINGSERVICE_EXPORT SALOME_Embedded_NamingService : public virtual POA_Engines::EmbeddedNamingService +{ +public: + void Register(const Engines::IORType& ObjRef, const char *Path) override; + void Destroy_FullDirectory(const char *Path) override; + void Destroy_Name(const char *Path) override; + Engines::IORType *Resolve(const char *Path) override; + Engines::IORType *ResolveFirst(const char *Path) override; +}; diff --git a/src/NamingService/SALOME_Embedded_NamingService_Client.cxx b/src/NamingService/SALOME_Embedded_NamingService_Client.cxx new file mode 100644 index 000000000..9ec02a73b --- /dev/null +++ b/src/NamingService/SALOME_Embedded_NamingService_Client.cxx @@ -0,0 +1,62 @@ +// Copyright (C) 2021 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "SALOME_Embedded_NamingService_Client.hxx" +#include "SALOME_Embedded_NamingService_Common.hxx" + +#include + +void SALOME_Embedded_NamingService_Client::init_orb(CORBA::ORB_ptr orb) +{ +} + +SALOME_NamingService_Container_Abstract *SALOME_Embedded_NamingService_Client::clone() +{ + return new SALOME_Embedded_NamingService_Client(*this); +} + +void SALOME_Embedded_NamingService_Client::Register(CORBA::Object_ptr ObjRef, const char* Path) +{ + std::unique_ptr ior( ObjectToIOR(ObjRef) ); + this->_remote_ns_serv->Register( *(ior.get()), Path); +} + +void SALOME_Embedded_NamingService_Client::Destroy_FullDirectory(const char* Path) +{ + this->_remote_ns_serv->Destroy_FullDirectory(Path); +} + +void SALOME_Embedded_NamingService_Client::Destroy_Name(const char* Path) +{ + this->_remote_ns_serv->Destroy_Name(Path); +} + +CORBA::Object_ptr SALOME_Embedded_NamingService_Client::Resolve(const char* Path) +{ + std::unique_ptr ior( this->_remote_ns_serv->Resolve(Path) ); + CORBA::Object_var ret( IORToObject( *(ior.get()) ) ); + return CORBA::Object::_duplicate(ret); +} + +CORBA::Object_ptr SALOME_Embedded_NamingService_Client::ResolveFirst(const char* Path) +{ + std::unique_ptr ior( this->_remote_ns_serv->ResolveFirst(Path) ); + CORBA::Object_var ret( IORToObject( *(ior.get()) ) ); + return CORBA::Object::_duplicate(ret); +} diff --git a/src/NamingService/SALOME_Embedded_NamingService_Client.hxx b/src/NamingService/SALOME_Embedded_NamingService_Client.hxx new file mode 100644 index 000000000..e493e13f3 --- /dev/null +++ b/src/NamingService/SALOME_Embedded_NamingService_Client.hxx @@ -0,0 +1,45 @@ +// Copyright (C) 2021 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#pragma once + +#include "SALOME_NamingService_defs.hxx" +#include "SALOME_NamingService_Abstract.hxx" + +#include +#include CORBA_CLIENT_HEADER(SALOME_Embedded_NamingService) + +class NAMINGSERVICE_EXPORT SALOME_Embedded_NamingService_Client : public SALOME_NamingService_Container_Abstract +{ +public: + SALOME_Embedded_NamingService_Client(Engines::EmbeddedNamingService_var remoteNSServ):_remote_ns_serv(remoteNSServ) { } + void init_orb(CORBA::ORB_ptr orb=0) override; + SALOME_NamingService_Container_Abstract *clone() override; + void Register(CORBA::Object_ptr ObjRef, const char* Path) override; + void Destroy_FullDirectory(const char* Path) override; + void Destroy_Name(const char* Path) override; + CORBA::Object_ptr Resolve(const char* Path) override; + CORBA::Object_ptr ResolveFirst(const char* Path) override; +public: + Engines::EmbeddedNamingService_var GetObject() const { return _remote_ns_serv; } +private: + SALOME_Embedded_NamingService_Client(const SALOME_Embedded_NamingService_Client& other) = default; +private: + Engines::EmbeddedNamingService_var _remote_ns_serv; +}; diff --git a/src/NamingService/SALOME_Embedded_NamingService_ClientPy.py b/src/NamingService/SALOME_Embedded_NamingService_ClientPy.py new file mode 100644 index 000000000..8e53810d7 --- /dev/null +++ b/src/NamingService/SALOME_Embedded_NamingService_ClientPy.py @@ -0,0 +1,43 @@ +#! /usr/bin/env python3 +# -*- coding: iso-8859-1 -*- +# Copyright (C) 2021 CEA/DEN, EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +from omniORB import CORBA + +class SALOME_Embedded_NamingService_ClientPy: + """ + A python client class to handle remote servant of SALOME_Embedded_NamingService + """ + #------------------------------------------------------------------------- + + def __init__(self, serv): + self._orb=CORBA.ORB_init([''], CORBA.ORB_ID) + self._obj = serv + #------------------------------------------------------------------------- + + def Register(self,ObjRef, Path): + ior = bytes(self._orb.object_to_string(ObjRef),encoding="utf-8") + self._obj.Register(ior,Path) + + #------------------------------------------------------------------------- + + def Resolve(self, Path): + ret = self._obj.Resolve(Path) + return self._orb.string_to_object(ret.decode()) diff --git a/src/NamingService/SALOME_Embedded_NamingService_Common.cxx b/src/NamingService/SALOME_Embedded_NamingService_Common.cxx new file mode 100644 index 000000000..46675b433 --- /dev/null +++ b/src/NamingService/SALOME_Embedded_NamingService_Common.cxx @@ -0,0 +1,48 @@ +// Copyright (C) 2021 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "SALOME_Embedded_NamingService_Common.hxx" +#include "SALOME_KernelORB.hxx" + +#include +#include + +CORBA::Object_var IORToObject(const Engines::IORType& ObjRef) +{ + CORBA::ORB_ptr orb(KERNEL::getORB()); + CORBA::ULong size(ObjRef.length()); + std::unique_ptr pt(new char[size+1]); + pt[size] = '\0'; + for(CORBA::ULong i = 0 ; i < size ; ++i) + pt[i] = ObjRef[i]; + CORBA::Object_var obj = orb->string_to_object(pt.get()); + return obj; +} + +Engines::IORType *ObjectToIOR(CORBA::Object_ptr obj) +{ + std::unique_ptr ret(new Engines::IORType); + CORBA::ORB_ptr orb(KERNEL::getORB()); + CORBA::String_var ior = orb->object_to_string(obj); + auto len( strlen(ior) ); + ret->length( len ); + for(std::size_t i = 0 ; i < len ; ++i) + (*ret)[i] = ior[i]; + return ret.release(); +} diff --git a/src/NamingService/SALOME_Embedded_NamingService_Common.hxx b/src/NamingService/SALOME_Embedded_NamingService_Common.hxx new file mode 100644 index 000000000..3707cdd8c --- /dev/null +++ b/src/NamingService/SALOME_Embedded_NamingService_Common.hxx @@ -0,0 +1,30 @@ +// Copyright (C) 2021 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#pragma once + +#include "SALOME_NamingService_defs.hxx" + +#include + +#include CORBA_CLIENT_HEADER(SALOME_Embedded_NamingService) + +CORBA::Object_var IORToObject(const Engines::IORType& ObjRef); + +Engines::IORType *ObjectToIOR(CORBA::Object_ptr obj); diff --git a/src/NamingService/SALOME_Fake_NamingService.cxx b/src/NamingService/SALOME_Fake_NamingService.cxx index f521034a2..e9e19f30d 100644 --- a/src/NamingService/SALOME_Fake_NamingService.cxx +++ b/src/NamingService/SALOME_Fake_NamingService.cxx @@ -19,14 +19,33 @@ #include "SALOME_Fake_NamingService.hxx" #include "Utils_SALOME_Exception.hxx" +#include "SALOME_KernelORB.hxx" + +#include CORBA_CLIENT_HEADER(SALOME_Component) + +#include +#include std::mutex SALOME_Fake_NamingService::_mutex; std::map SALOME_Fake_NamingService::_map; +bool SALOME_Fake_NamingService::_log_container_file_thread_launched = false; +std::string SALOME_Fake_NamingService::_log_container_file_name; SALOME_Fake_NamingService::SALOME_Fake_NamingService(CORBA::ORB_ptr orb) { } +std::vector< std::string > SALOME_Fake_NamingService::repr() +{ + std::lock_guard g(_mutex); + std::vector< std::string > ret; + for(auto it : _map) + { + ret.push_back( it.first ); + } + return ret; +} + void SALOME_Fake_NamingService::init_orb(CORBA::ORB_ptr orb) { } @@ -36,6 +55,7 @@ void SALOME_Fake_NamingService::Register(CORBA::Object_ptr ObjRef, const char* P std::lock_guard g(_mutex); CORBA::Object_var ObjRefAuto = CORBA::Object::_duplicate(ObjRef); _map[Path] = ObjRefAuto; + FlushLogContainersFile_NoThreadSafe(); } void SALOME_Fake_NamingService::Destroy_Name(const char* Path) @@ -65,8 +85,14 @@ std::vector SALOME_Fake_NamingService::list_directory() return std::vector(); } +std::vector SALOME_Fake_NamingService::list_directory_recurs() +{ + return std::vector(); +} + CORBA::Object_ptr SALOME_Fake_NamingService::Resolve(const char* Path) { + std::lock_guard g(_mutex); std::string pathCpp(Path); auto it = _map.find(pathCpp); if( it != _map.end() ) @@ -86,5 +112,76 @@ SALOME_NamingService_Abstract *SALOME_Fake_NamingService::clone() CORBA::Object_ptr SALOME_Fake_NamingService::ResolveComponent(const char* hostname, const char* containerName, const char* componentName, const int nbproc) { - THROW_SALOME_EXCEPTION("SALOME_Fake_NamingService::ResolveComponent : " << hostname << " " << containerName << " " << componentName << " " << nbproc); + std::ostringstream oss; + oss << SEP << "Containers" << SEP << hostname << SEP << containerName << SEP << componentName; + std::string entryToFind(oss.str()); + return Resolve(entryToFind.c_str()); +} + +std::vector< std::pair< std::string, Engines::Container_var> > SALOME_Fake_NamingService::ListOfContainersInNS_NoThreadSafe() +{ + std::vector< std::pair< std::string, Engines::Container_var> > ret; + for(auto it : _map) + { + Engines::Container_var elt = Engines::Container::_narrow(it.second); + if(!CORBA::is_nil(elt)) + ret.push_back({it.first,elt}); + } + return ret; +} + +std::string SALOME_Fake_NamingService::ReprOfContainersIORS_NoThreadSafe() +{ + std::vector< std::pair< std::string, Engines::Container_var> > conts( ListOfContainersInNS_NoThreadSafe() ); + std::ostringstream oss; + CORBA::ORB_ptr orb = KERNEL::getORB(); + char SEP[2] = { '\0', '\0' }; + constexpr char SEP2[] = " : "; + for(auto it : conts) + { + CORBA::String_var ior(orb->object_to_string(it.second)); + oss << SEP << it.first << SEP2 << ior; + SEP[0] = '\n'; + } + return oss.str(); +} + +std::string SALOME_Fake_NamingService::ReprOfContainersIORS() +{ + std::lock_guard g(_mutex); + return ReprOfContainersIORS_NoThreadSafe(); +} + +std::string SALOME_Fake_NamingService::GetLogContainersFile() +{ + return _log_container_file_name; +} + +void SALOME_Fake_NamingService::FlushLogContainersFile() +{ + std::lock_guard g(_mutex); + FlushLogContainersFile_NoThreadSafe(); +} + +void SALOME_Fake_NamingService::FlushLogContainersFile_NoThreadSafe() +{ + if(!_log_container_file_name.empty()) + { + std::string content( ReprOfContainersIORS_NoThreadSafe() ); + std::ofstream ofs(_log_container_file_name); + ofs.write(content.c_str(),content.length()); + } +} + +void SALOME_Fake_NamingService::SetLogContainersFile(const std::string& logFileName) +{ + if(logFileName.empty()) + THROW_SALOME_EXCEPTION("SALOME_Fake_NamingService::SetLogContainersFile : empty log name !"); + constexpr char EXPT_CONTENT[] = "SALOME_Fake_NamingService::SetLogContainersFile : input logFileName write access failed ! no log file set !"; + { + std::ofstream ofs(logFileName); + if(!ofs) + THROW_SALOME_EXCEPTION(EXPT_CONTENT); + } + _log_container_file_name = logFileName; } diff --git a/src/NamingService/SALOME_Fake_NamingService.hxx b/src/NamingService/SALOME_Fake_NamingService.hxx index f60e1480e..509c3181f 100644 --- a/src/NamingService/SALOME_Fake_NamingService.hxx +++ b/src/NamingService/SALOME_Fake_NamingService.hxx @@ -24,27 +24,40 @@ #include "SALOME_NamingService_Abstract.hxx" #include +#include #include #include class NAMINGSERVICE_EXPORT SALOME_Fake_NamingService : public SALOME_NamingService_Abstract { public: - SALOME_Fake_NamingService(CORBA::ORB_ptr orb); - SALOME_Fake_NamingService() = default; - void init_orb(CORBA::ORB_ptr orb=0) override; - void Register(CORBA::Object_ptr ObjRef, const char* Path) override; - CORBA::Object_ptr Resolve(const char* Path) override; - CORBA::Object_ptr ResolveFirst(const char* Path) override; - void Destroy_Name(const char* Path) override; - void Destroy_Directory(const char* Path) override; - void Destroy_FullDirectory(const char* Path) override; - bool Change_Directory(const char* Path) override; - std::vector list_subdirs() override; - std::vector list_directory() override; - SALOME_NamingService_Abstract *clone() override; - CORBA::Object_ptr ResolveComponent(const char* hostname, const char* containerName, const char* componentName, const int nbproc=0) override; + SALOME_Fake_NamingService(CORBA::ORB_ptr orb); + SALOME_Fake_NamingService() = default; + static void SetLogContainersFile(const std::string& logFileName); + static std::string GetLogContainersFile(); + static void FlushLogContainersFile(); + std::vector< std::string > repr() override; + void init_orb(CORBA::ORB_ptr orb=0) override; + void Register(CORBA::Object_ptr ObjRef, const char* Path) override; + CORBA::Object_ptr Resolve(const char* Path) override; + CORBA::Object_ptr ResolveFirst(const char* Path) override; + void Destroy_Name(const char* Path) override; + void Destroy_Directory(const char* Path) override; + void Destroy_FullDirectory(const char* Path) override; + bool Change_Directory(const char* Path) override; + std::vector list_subdirs() override; + std::vector list_directory() override; + std::vector list_directory_recurs() override; + SALOME_NamingService_Abstract *clone() override; + CORBA::Object_ptr ResolveComponent(const char* hostname, const char* containerName, const char* componentName, const int nbproc=0) override; private: - static std::mutex _mutex; - static std::map _map; + static std::string ReprOfContainersIORS_NoThreadSafe(); + static std::string ReprOfContainersIORS(); + static std::vector< std::pair< std::string, Engines::Container_var> > ListOfContainersInNS_NoThreadSafe(); + static void FlushLogContainersFile_NoThreadSafe(); +private: + static std::mutex _mutex; + static std::map _map; + static bool _log_container_file_thread_launched; + static std::string _log_container_file_name; }; diff --git a/src/NamingService/SALOME_NamingService.cxx b/src/NamingService/SALOME_NamingService.cxx index 47be7be07..898a83c16 100644 --- a/src/NamingService/SALOME_NamingService.cxx +++ b/src/NamingService/SALOME_NamingService.cxx @@ -92,10 +92,9 @@ SALOME_NamingService::~SALOME_NamingService() //MESSAGE("SALOME_NamingService destruction"); } -SALOME_NamingService *SALOME_NamingService::GetTraditionalNS(SALOME_NamingService_Abstract *ns) +std::vector< std::string > SALOME_NamingService::repr() { - SALOME_NamingService *nsc(dynamic_cast(ns)); - return nsc; + return std::vector< std::string >(); } // ============================================================================ @@ -559,64 +558,6 @@ SALOME_NamingService::ResolveComponent(const char* hostname, } } -// ============================================================================ -/*! \brief build a container name, given a ContainerParameters struct. - * - * Build a container name with a ContainerParameters struct. In case of multi - * processor machine, container name is suffixed with number of processors. - * \param params struct from which we get container name (may be empty) and - * number of processors. - * \return a container name without the path. - * \sa BuildContainerNameForNS(const Engines::ContainerParameters& params, - * const char *hostname) - */ -// ============================================================================ - -std::string SALOME_NamingService::ContainerName(const Engines::ContainerParameters& params) -{ - int nbproc; - - if ( !params.isMPI ) - nbproc = 0; - else if ( params.nb_proc <= 0 ) - nbproc = 1; - else - nbproc = params.nb_proc; - - std::string ret(SALOME_NamingService_Abstract::ContainerName(params.container_name)); - - if ( nbproc >= 1 ) - { - std::ostringstream suffix; - suffix << "_" << nbproc; - ret += suffix.str(); - } - - return ret; -} - -// ============================================================================ -/*! \brief build a string representing a container in Naming Service. - * - * Build a string representing the absolute pathname of a container in - * SALOME_NamingService. - * \param params used as it is, or replaced by FactoryServer if empty. - * \param hostname name of the host of the container, without domain names. - * \return the path under the form /Containers/hostname/containerName - * \sa ContainerName(const char *containerName) - */ -// ============================================================================ - -std::string SALOME_NamingService::BuildContainerNameForNS(const Engines::ContainerParameters& params, const char *hostname) -{ - std::string ret("/Containers/"); - ret += hostname; - ret += "/"; - ret += ContainerName(params); - - return ret; -} - // ============================================================================ /*! \brief search a name in current directory. * diff --git a/src/NamingService/SALOME_NamingService.hxx b/src/NamingService/SALOME_NamingService.hxx index 6599e99c8..ec19bb7b7 100644 --- a/src/NamingService/SALOME_NamingService.hxx +++ b/src/NamingService/SALOME_NamingService.hxx @@ -51,9 +51,7 @@ public: SALOME_NamingService(CORBA::ORB_ptr orb); virtual ~SALOME_NamingService(); - - static SALOME_NamingService *GetTraditionalNS(SALOME_NamingService_Abstract *ns); - + std::vector< std::string > repr() override; void init_orb(CORBA::ORB_ptr orb=0) override; void Register(CORBA::Object_ptr ObjRef, const char* Path) override; CORBA::Object_ptr Resolve(const char* Path) override; @@ -62,8 +60,6 @@ public: const char* containerName, const char* componentName, const int nbproc=0) override; - std::string ContainerName(const Engines::ContainerParameters& params); - std::string BuildContainerNameForNS(const Engines::ContainerParameters& params, const char *hostname); int Find(const char* name) ; bool Create_Directory(const char* Path) ; @@ -72,7 +68,7 @@ public: void list() ; std::vector list_directory() override; std::vector list_subdirs() override; - std::vector list_directory_recurs() ; + std::vector list_directory_recurs() override ; void Destroy_Name(const char* Path) override; void Destroy_Directory(const char* Path) override; void Destroy_FullDirectory(const char* Path) override; diff --git a/src/NamingService/SALOME_NamingService.i b/src/NamingService/SALOME_NamingService.i deleted file mode 100644 index 9369d0281..000000000 --- a/src/NamingService/SALOME_NamingService.i +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -// SALOME NamingService : wrapping NamingService services -// File : SALOME_NamingService.i -// Author : Paul RASCLE, EDF -// Module : SALOME -// $Header$ -// -%{ -#include "SALOME_NamingService.hxx" -//#include -#include -#include "ServiceUnreachable.hxx" -%} - -%except(python) -{ - try - { - $function - } - catch (ServiceUnreachable) - { - PyErr_SetString(PyExc_IndexError,"Naming Service Unreacheable"); - return NULL; - } -} - -class SALOME_NamingService -{ -public: - - //! standard constructor - SALOME_NamingService(); - - //! standard destructor - virtual ~SALOME_NamingService(); - - //! initialize ORB reference after default constructor - void init_orb(CORBA::ORB_ptr orb); - - //! method to create an association in the NamingService between an object reference and a path - void Register(CORBA::Object_ptr ObjRef, const char* Path) - throw(ServiceUnreachable); - - //! method to get the ObjRef of a symbolic name - CORBA::Object_ptr Resolve(const char* Path) - throw( ServiceUnreachable); - - //! method to research a name from the naming service's current directory - int Find(const char* name) - throw(ServiceUnreachable); - - //! method to create a directory from the current directory - bool Create_Directory(const char* Path) - throw(ServiceUnreachable); - - //! method to change the current directory to the directory Path indicated in "in" Parameter - bool Change_Directory(const char* Path) - throw(ServiceUnreachable); - - //!method to get the current directory - char* Current_Directory() - throw(ServiceUnreachable); - - //!method to print all the contexts contained from the current directory - void list() - throw(ServiceUnreachable); - - //! method to destroy an association Path-Object Reference - void Destroy_Name(const char* Path) - throw(ServiceUnreachable); - - //! method to destroy a directory if it is empty - virtual void Destroy_Directory(const char* Path) - throw(ServiceUnreachable); -}; - diff --git a/src/NamingService/SALOME_NamingService_Abstract.cxx b/src/NamingService/SALOME_NamingService_Abstract.cxx index 4469dfed1..d77e2af59 100644 --- a/src/NamingService/SALOME_NamingService_Abstract.cxx +++ b/src/NamingService/SALOME_NamingService_Abstract.cxx @@ -18,6 +18,20 @@ // #include "SALOME_NamingService_Abstract.hxx" +#include "Utils_SALOME_Exception.hxx" + +#include +#include + +SALOME_NamingService_Abstract *SALOME_NamingService_Abstract::cloneCoVar() +{ + std::unique_ptr ret(this->clone()); + SALOME_NamingService_Abstract *ret2(dynamic_cast(ret.get())); + if(!ret2) + throw SALOME_Exception(std::string("SALOME_NamingService_Abstract::cloneCoVar : clone is expected to return a SALOME_NamingService_Abstract type !")); + ret.release(); + return ret2; +} // ============================================================================ /*! \brief provide a default container name if empty. @@ -65,3 +79,61 @@ std::string SALOME_NamingService_Abstract::BuildContainerNameForNS(const char *c return ret; } + +// ============================================================================ +/*! \brief build a container name, given a ContainerParameters struct. + * + * Build a container name with a ContainerParameters struct. In case of multi + * processor machine, container name is suffixed with number of processors. + * \param params struct from which we get container name (may be empty) and + * number of processors. + * \return a container name without the path. + * \sa BuildContainerNameForNS(const Engines::ContainerParameters& params, + * const char *hostname) + */ +// ============================================================================ + +std::string SALOME_NamingService_Abstract::ContainerName(const Engines::ContainerParameters& params) +{ + int nbproc; + + if ( !params.isMPI ) + nbproc = 0; + else if ( params.nb_proc <= 0 ) + nbproc = 1; + else + nbproc = params.nb_proc; + + std::string ret(SALOME_NamingService_Abstract::ContainerName(params.container_name)); + + if ( nbproc >= 1 ) + { + std::ostringstream suffix; + suffix << "_" << nbproc; + ret += suffix.str(); + } + + return ret; +} + +// ============================================================================ +/*! \brief build a string representing a container in Naming Service. + * + * Build a string representing the absolute pathname of a container in + * SALOME_NamingService. + * \param params used as it is, or replaced by FactoryServer if empty. + * \param hostname name of the host of the container, without domain names. + * \return the path under the form /Containers/hostname/containerName + * \sa ContainerName(const char *containerName) + */ +// ============================================================================ + +std::string SALOME_NamingService_Abstract::BuildContainerNameForNS(const Engines::ContainerParameters& params, const char *hostname) +{ + std::string ret("/Containers/"); + ret += hostname; + ret += "/"; + ret += ContainerName(params); + + return ret; +} diff --git a/src/NamingService/SALOME_NamingService_Abstract.hxx b/src/NamingService/SALOME_NamingService_Abstract.hxx index ce7301c79..fdd6ae0d4 100644 --- a/src/NamingService/SALOME_NamingService_Abstract.hxx +++ b/src/NamingService/SALOME_NamingService_Abstract.hxx @@ -21,27 +21,40 @@ #include "SALOME_NamingService_defs.hxx" -#include "omniORB4/CORBA.h" +#include +#include CORBA_CLIENT_HEADER(SALOME_ContainerManager) +#include CORBA_CLIENT_HEADER(SALOME_Component) #include #include -class NAMINGSERVICE_EXPORT SALOME_NamingService_Abstract +class NAMINGSERVICE_EXPORT SALOME_NamingService_Container_Abstract { public: virtual void init_orb(CORBA::ORB_ptr orb=0) = 0; + virtual SALOME_NamingService_Container_Abstract *clone() = 0; virtual void Register(CORBA::Object_ptr ObjRef, const char* Path) = 0; - virtual CORBA::Object_ptr Resolve(const char* Path) = 0; - virtual CORBA::Object_ptr ResolveFirst(const char* Path) = 0; + virtual void Destroy_FullDirectory(const char* Path) = 0; virtual void Destroy_Name(const char* Path) = 0; + virtual CORBA::Object_ptr Resolve(const char* Path) = 0; + virtual CORBA::Object_ptr ResolveFirst(const char* Path) = 0; + static constexpr char SEP = '/'; +}; + +class NAMINGSERVICE_EXPORT SALOME_NamingService_Abstract : public SALOME_NamingService_Container_Abstract +{ +public: + SALOME_NamingService_Abstract *cloneCoVar(); + virtual std::vector< std::string > repr() = 0; virtual void Destroy_Directory(const char* Path) = 0; - virtual void Destroy_FullDirectory(const char* Path) = 0; virtual bool Change_Directory(const char* Path) = 0; virtual std::vector list_subdirs() = 0; virtual std::vector list_directory() = 0; - virtual SALOME_NamingService_Abstract *clone() = 0; + virtual std::vector list_directory_recurs() = 0; virtual CORBA::Object_ptr ResolveComponent(const char* hostname, const char* containerName, const char* componentName, const int nbproc=0) = 0; virtual ~SALOME_NamingService_Abstract() { } + static std::string ContainerName(const Engines::ContainerParameters& params); static std::string ContainerName(const char *ContainerName); static std::string BuildContainerNameForNS(const char *ContainerName, const char *hostname); + static std::string BuildContainerNameForNS(const Engines::ContainerParameters& params, const char *hostname); }; diff --git a/src/ResourcesManager/SALOME_ResourcesManager.cxx b/src/ResourcesManager/SALOME_ResourcesManager.cxx index 1a57e5faf..5b168e265 100644 --- a/src/ResourcesManager/SALOME_ResourcesManager.cxx +++ b/src/ResourcesManager/SALOME_ResourcesManager.cxx @@ -58,7 +58,7 @@ const char *SALOME_ResourcesManager::_ResourcesManagerNameInNS = "/ResourcesMana SALOME_ResourcesManager::SALOME_ResourcesManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, - SALOME_NamingService *ns, + SALOME_NamingService_Abstract *ns, const char *xmlFilePath) : _rm(new ResourcesManager_cpp(xmlFilePath)) { @@ -94,7 +94,7 @@ SALOME_ResourcesManager::SALOME_ResourcesManager(CORBA::ORB_ptr orb, SALOME_ResourcesManager::SALOME_ResourcesManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, - SALOME_NamingService *ns) : _rm(new ResourcesManager_cpp()) + SALOME_NamingService_Abstract *ns) : _rm(new ResourcesManager_cpp()) { MESSAGE("SALOME_ResourcesManager constructor"); _NS = ns; diff --git a/src/ResourcesManager/SALOME_ResourcesManager.hxx b/src/ResourcesManager/SALOME_ResourcesManager.hxx index e0e362280..e309a3cbf 100644 --- a/src/ResourcesManager/SALOME_ResourcesManager.hxx +++ b/src/ResourcesManager/SALOME_ResourcesManager.hxx @@ -26,7 +26,7 @@ #include "Utils_SALOME_Exception.hxx" #include "utilities.h" #include -#include "SALOME_NamingService.hxx" +#include "SALOME_NamingService_Abstract.hxx" #include CORBA_CLIENT_HEADER(SALOME_ContainerManager) #include #include @@ -53,8 +53,8 @@ class SALOMERESOURCESMANAGER_EXPORT SALOME_ResourcesManager: public: - SALOME_ResourcesManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_NamingService *ns, const char *xmlFilePath); - SALOME_ResourcesManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_NamingService *ns); + SALOME_ResourcesManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_NamingService_Abstract *ns, const char *xmlFilePath); + SALOME_ResourcesManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_NamingService_Abstract *ns); ~SALOME_ResourcesManager(); @@ -82,7 +82,7 @@ class SALOMERESOURCESMANAGER_EXPORT SALOME_ResourcesManager: static const char *_ResourcesManagerNameInNS; protected: - SALOME_NamingService *_NS; + SALOME_NamingService_Abstract *_NS; CORBA::ORB_var _orb; PortableServer::POA_var _poa; std::shared_ptr _rm; diff --git a/src/ResourcesManager/SALOME_ResourcesManager_Client.cxx b/src/ResourcesManager/SALOME_ResourcesManager_Client.cxx index 63467c13f..e13aeb3f0 100644 --- a/src/ResourcesManager/SALOME_ResourcesManager_Client.cxx +++ b/src/ResourcesManager/SALOME_ResourcesManager_Client.cxx @@ -22,10 +22,11 @@ #include "SALOME_ResourcesManager_Client.hxx" #include "SALOME_ResourcesManager.hxx" +#include "SALOME_NamingService_Abstract.hxx" using namespace std; -SALOME_ResourcesManager_Client::SALOME_ResourcesManager_Client(SALOME_NamingService *ns) +SALOME_ResourcesManager_Client::SALOME_ResourcesManager_Client(SALOME_NamingService_Abstract *ns) : _rm(Engines::ResourcesManager::_nil()) { CORBA::Object_var objRM = ns->Resolve(SALOME_ResourcesManager::_ResourcesManagerNameInNS); diff --git a/src/ResourcesManager/SALOME_ResourcesManager_Client.hxx b/src/ResourcesManager/SALOME_ResourcesManager_Client.hxx index b81fe8b49..792709ade 100644 --- a/src/ResourcesManager/SALOME_ResourcesManager_Client.hxx +++ b/src/ResourcesManager/SALOME_ResourcesManager_Client.hxx @@ -25,7 +25,7 @@ #include "SALOME_ResourcesManager_Common.hxx" -class SALOME_NamingService; +class SALOME_NamingService_Abstract; // This class is fully thread-safe because the ResourcesManager CORBA object // runs in a single-thread POA. @@ -33,7 +33,7 @@ class SALOMERESOURCESMANAGER_EXPORT SALOME_ResourcesManager_Client { public: - SALOME_ResourcesManager_Client(SALOME_NamingService *ns); + SALOME_ResourcesManager_Client(SALOME_NamingService_Abstract *ns); ~SALOME_ResourcesManager_Client(); std::vector GetFittingResources(const resourceParams& params); diff --git a/src/SALOMEDS/SALOMEDS_Driver_i.cxx b/src/SALOMEDS/SALOMEDS_Driver_i.cxx index 693f257ff..3ea2c2761 100644 --- a/src/SALOMEDS/SALOMEDS_Driver_i.cxx +++ b/src/SALOMEDS/SALOMEDS_Driver_i.cxx @@ -356,7 +356,7 @@ SALOMEDS_DriverFactory_i::SALOMEDS_DriverFactory_i(CORBA::ORB_ptr theORB, bool i SALOMEDS_DriverFactory_i::SALOMEDS_DriverFactory_i(CORBA::ORB_ptr theORB, SALOME_NamingService_Abstract *ns):_orb( CORBA::ORB::_duplicate(theORB) ) { - _name_service = ns->clone(); + _name_service = ns->cloneCoVar(); } SALOMEDS_DriverFactory_i::~SALOMEDS_DriverFactory_i() -- 2.39.2