From 623bdcced66bff335cc1e4873c8bc440705a7901 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Mon, 23 Aug 2021 11:43:47 +0200 Subject: [PATCH] allow salome_init to point to origin cm,rm,dsm and esm in salome.salome_init() launched in the SALOME_Container_No_NS_Serv SSL context --- src/Basics/KernelBasis.cxx | 13 +++++ src/Basics/KernelBasis.hxx | 5 ++ src/Basics/KernelBasis.i | 5 ++ src/Container/SALOME_Container_No_NS_Serv.cxx | 5 +- src/KERNEL_PY/__init__.py | 54 ++++++++++++++----- 5 files changed, 69 insertions(+), 13 deletions(-) diff --git a/src/Basics/KernelBasis.cxx b/src/Basics/KernelBasis.cxx index b634f7265..73612dc6f 100644 --- a/src/Basics/KernelBasis.cxx +++ b/src/Basics/KernelBasis.cxx @@ -21,6 +21,9 @@ static bool DEFAULT_SSL_MODE = false; +// IOR of SALOME_Embedded_NamingService servant +static std::string IOR_OF_EMBEDDED_NS; + bool getSSLMode() { return DEFAULT_SSL_MODE; @@ -30,3 +33,13 @@ void setSSLMode(bool sslMode) { DEFAULT_SSL_MODE = sslMode; } + +std::string BASICS_EXPORT getIOROfEmbeddedNS() +{ + return IOR_OF_EMBEDDED_NS; +} + +void BASICS_EXPORT setIOROfEmbeddedNS(const std::string& ior) +{ + IOR_OF_EMBEDDED_NS = ior; +} diff --git a/src/Basics/KernelBasis.hxx b/src/Basics/KernelBasis.hxx index 184fb9987..710106ff3 100644 --- a/src/Basics/KernelBasis.hxx +++ b/src/Basics/KernelBasis.hxx @@ -21,5 +21,10 @@ #include "SALOME_Basics.hxx" +#include + bool BASICS_EXPORT getSSLMode(); void BASICS_EXPORT setSSLMode(bool sslMode); + +std::string BASICS_EXPORT getIOROfEmbeddedNS(); +void BASICS_EXPORT setIOROfEmbeddedNS(const std::string& ior); diff --git a/src/Basics/KernelBasis.i b/src/Basics/KernelBasis.i index 44b2e221a..d2cdbfc13 100644 --- a/src/Basics/KernelBasis.i +++ b/src/Basics/KernelBasis.i @@ -23,5 +23,10 @@ #include "KernelBasis.hxx" %} +%include "std_string.i" + bool getSSLMode(); void setSSLMode(bool sslMode); + +std::string getIOROfEmbeddedNS(); +void setIOROfEmbeddedNS(const std::string& ior); diff --git a/src/Container/SALOME_Container_No_NS_Serv.cxx b/src/Container/SALOME_Container_No_NS_Serv.cxx index 6d8018450..37818df89 100644 --- a/src/Container/SALOME_Container_No_NS_Serv.cxx +++ b/src/Container/SALOME_Container_No_NS_Serv.cxx @@ -21,13 +21,16 @@ #include "SALOME_Embedded_NamingService_Client.hxx" #include "Utils_SALOME_Exception.hxx" #include "SALOME_KernelORB.hxx" +#include "KernelBasis.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]); + std::string IOROfEmbeddedNamingService(argv[2]); + setIOROfEmbeddedNS(IOROfEmbeddedNamingService); + CORBA::Object_var ns_serv_obj_base = orb->string_to_object(IOROfEmbeddedNamingService.c_str()); 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); diff --git a/src/KERNEL_PY/__init__.py b/src/KERNEL_PY/__init__.py index 0c06b1cfd..d0d611d8e 100644 --- a/src/KERNEL_PY/__init__.py +++ b/src/KERNEL_PY/__init__.py @@ -171,17 +171,22 @@ __EMB_SERVANT_ENV_VAR_NAME = "SALOME_EMB_SERVANT" def standalone(): import os os.environ[__EMB_SERVANT_ENV_VAR_NAME] = "1" + import KernelBasis + KernelBasis.setSSLMode(True) def salome_init(path=None, embedded=False): import os + import KernelBasis if __EMB_SERVANT_ENV_VAR_NAME in os.environ: - salome_init_without_session() - else: - import KernelBasis - if KernelBasis.getSSLMode(): + KernelBasis.setSSLMode(True) + # + if KernelBasis.getSSLMode(): + if KernelBasis.getIOROfEmbeddedNS() == "": salome_init_without_session() else: - salome_init_with_session(path, embedded) + salome_init_without_session_attached() + else: + salome_init_with_session(path, embedded) class StandAloneLifecyle: def __init__(self, containerManager, resourcesManager): @@ -203,8 +208,8 @@ class StandAloneLifecyle: def getResourcesManager(self): return self._rm -def salome_init_without_session(): - global lcc,naming_service,myStudy,orb,modulcat,sg,cm,dsm,esm +def salome_init_without_session_common(): + global lcc,naming_service,myStudy,orb,modulcat,sg import KernelBasis KernelBasis.setSSLMode(True) import KernelDS @@ -215,23 +220,48 @@ 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 - from NamingService import NamingService - cm = KernelLauncher.myContainerManager() - lcc = StandAloneLifecyle(cm, KernelLauncher.myResourcesManager()) - # activate poaManager to accept co-localized CORBA calls. + # poa = orb.resolve_initial_references("RootPOA") poaManager = poa._get_the_POAManager() poaManager.activate() sg = SalomeOutsideGUI() salome_study_init_without_session() + # + from NamingService import NamingService naming_service = NamingService() + +def salome_init_without_session(): + salome_init_without_session_common() + global lcc,cm,dsm,esm + import KernelLauncher + cm = KernelLauncher.myContainerManager() + lcc = StandAloneLifecyle(cm, KernelLauncher.myResourcesManager()) + # activate poaManager to accept co-localized CORBA calls. from KernelSDS import GetDSMInstance import sys dsm = GetDSMInstance(sys.argv) # esm inherits from SALOME_CPythonHelper singleton already initialized by GetDSMInstance # esm inherits also from SALOME_ResourcesManager creation/initialization (concerning SingleThreadPOA POA) when KernelLauncher.GetContainerManager() has been called esm = KernelLauncher.GetExternalServer() + +def salome_init_without_session_attached(): + """ + Configuration SSL inside a python interpretor launched in the SALOME_Container_No_NS_Serv. + In this configuration, + """ + salome_init_without_session_common() + global lcc,cm,dsm,esm + import CORBA + orb=CORBA.ORB_init(['']) + import Engines + import KernelBasis + nsAbroad = orb.string_to_object( KernelBasis.getIOROfEmbeddedNS() ) + import SALOME + cm = orb.string_to_object( nsAbroad.Resolve("/ContainerManager").decode() ) + rm = orb.string_to_object( nsAbroad.Resolve("/ResourcesManager").decode() ) + lcc = StandAloneLifecyle(cm,rm) + dsm = orb.string_to_object( nsAbroad.Resolve("/DataServerManager").decode() ) + esm = orb.string_to_object( nsAbroad.Resolve("/ExternalServers").decode() ) def salome_init_with_session(path=None, embedded=False): """ -- 2.39.2