From: Anthony GEAY Date: Fri, 19 Feb 2021 15:00:38 +0000 (+0100) Subject: OK for SALOME_Launcher X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2196387e31271cd75b7846f1a57c5952a304d7e8;p=modules%2Fkernel.git OK for SALOME_Launcher --- diff --git a/src/Container/SALOME_ContainerManager.cxx b/src/Container/SALOME_ContainerManager.cxx index dec227ae9..8134f28cd 100644 --- a/src/Container/SALOME_ContainerManager.cxx +++ b/src/Container/SALOME_ContainerManager.cxx @@ -99,10 +99,9 @@ SALOME_ContainerManager::SALOME_ContainerManager(CORBA::ORB_ptr orb, PortableSer threadPol->destroy(); PortableServer::ObjectId_var id = _poa->activate_object(this); CORBA::Object_var obj = _poa->id_to_reference(id); - Engines::ContainerManager_var refContMan = - Engines::ContainerManager::_narrow(obj); - - _NS->Register(refContMan,_ContainerManagerNameInNS); + Engines::ContainerManager_var refContMan = Engines::ContainerManager::_narrow(obj); + if(_NS) + _NS->Register(refContMan,_ContainerManagerNameInNS); _isAppliSalomeDefined = (GetenvThreadSafe("APPLI") != 0); #ifdef HAVE_MPI2 @@ -195,7 +194,8 @@ void SALOME_ContainerManager::Shutdown() { MESSAGE("Shutdown"); ShutdownContainers(); - _NS->Destroy_Name(_ContainerManagerNameInNS); + if(_NS) + _NS->Destroy_Name(_ContainerManagerNameInNS); PortableServer::ObjectId_var oid = _poa->servant_to_id(this); _poa->deactivate_object(oid); } @@ -209,7 +209,8 @@ void SALOME_ContainerManager::Shutdown() void SALOME_ContainerManager::ShutdownContainers() { MESSAGE("ShutdownContainers"); - + if(!_NS) + return ; SALOME::Session_var session = SALOME::Session::_nil(); CORBA::Long pid = 0; CORBA::Object_var objS = _NS->Resolve("/Kernel/Session"); diff --git a/src/Launcher/SALOME_Launcher.cxx b/src/Launcher/SALOME_Launcher.cxx index 0698b184f..2655efc7d 100644 --- a/src/Launcher/SALOME_Launcher.cxx +++ b/src/Launcher/SALOME_Launcher.cxx @@ -58,13 +58,24 @@ const char *SALOME_Launcher::_LauncherNameInNS = "/SalomeLauncher"; * \param orb */ //============================================================================= -SALOME_Launcher::SALOME_Launcher(CORBA::ORB_ptr orb, PortableServer::POA_var poa) : _l() +SALOME_Launcher::SALOME_Launcher(CORBA::ORB_ptr orb, PortableServer::POA_var poa) { MESSAGE("SALOME_Launcher constructor"); _NS = new SALOME_NamingService(orb); - _ResManager = new SALOME_ResourcesManager(orb,poa,_NS); + init(orb,poa); + MESSAGE("SALOME_Launcher constructor end"); +} + +SALOME_Launcher::SALOME_Launcher(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_NamingService_Abstract *externalNS):_NS(externalNS) +{ + init(orb,poa); +} + +void SALOME_Launcher::init(CORBA::ORB_ptr orb, PortableServer::POA_var poa) +{ + _ResManager = new SALOME_ResourcesManager(orb,poa,tradNS()); _l.SetResourcesManager(_ResManager->GetImpl()); - _ContManager = new SALOME_ContainerManager(orb,poa,_NS); + _ContManager = new SALOME_ContainerManager(orb,poa,tradNS()); _ResManager->_remove_ref(); _ContManager->_remove_ref(); @@ -73,9 +84,7 @@ SALOME_Launcher::SALOME_Launcher(CORBA::ORB_ptr orb, PortableServer::POA_var poa PortableServer::ObjectId_var id = _poa->activate_object(this); CORBA::Object_var obj = _poa->id_to_reference(id); Engines::SalomeLauncher_var refContMan = Engines::SalomeLauncher::_narrow(obj); - _NS->Register(refContMan,_LauncherNameInNS); - MESSAGE("SALOME_Launcher constructor end"); } //============================================================================= @@ -373,6 +382,8 @@ SALOME_Launcher::testBatch(const Engines::ResourceParameters& params) void SALOME_Launcher::Shutdown() { MESSAGE("Shutdown"); + if(!_NS) + return; _NS->Destroy_Name(_LauncherNameInNS); _ContManager->Shutdown(); _ResManager->Shutdown(); @@ -691,3 +702,20 @@ SALOME_Launcher::JobParameters_CPP2CORBA(const JobParameters_cpp& job_parameters result->launcher_args = CORBA::string_dup(job_parameters.launcher_args.c_str()); return result; } + +static SALOME_Launcher *_launcher_singleton_ssl = nullptr; + +#include "SALOME_Fake_NamingService.hxx" + +SALOME_Launcher *KERNEL::getLauncherSA() +{ + if(!_launcher_singleton_ssl) + { + int argc(0); + CORBA::ORB_var orb = CORBA::ORB_init(argc,nullptr); + PortableServer::POA_var root_poa=PortableServer::POA::_the_root_poa(); + SALOME_Fake_NamingService *ns=new SALOME_Fake_NamingService(orb); + _launcher_singleton_ssl = new SALOME_Launcher(orb,root_poa,ns);//3rd arg is important to skip NS ! + } + return _launcher_singleton_ssl; +} diff --git a/src/Launcher/SALOME_Launcher.hxx b/src/Launcher/SALOME_Launcher.hxx index 963799d47..eb0e6a618 100644 --- a/src/Launcher/SALOME_Launcher.hxx +++ b/src/Launcher/SALOME_Launcher.hxx @@ -25,14 +25,14 @@ #include "SALOME_Launcher_defs.hxx" -#include +#include "SALOME_NamingService.hxx" +#include "SALOMEconfig.h" #include CORBA_CLIENT_HEADER(SALOME_Launcher) #include "Launcher.hxx" #include #include -class SALOME_NamingService; class SALOME_ContainerManager; class SALOME_ResourcesManager; @@ -43,8 +43,8 @@ class SALOMELAUNCHER_EXPORT SALOME_Launcher: public: SALOME_Launcher(CORBA::ORB_ptr orb, PortableServer::POA_var poa); + SALOME_Launcher(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_NamingService_Abstract *externalNS); virtual ~SALOME_Launcher(); - // Main methods CORBA::Long createJob (const Engines::JobParameters & job_parameters); void launchJob (CORBA::Long job_id); @@ -86,20 +86,30 @@ 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); - + void init(CORBA::ORB_ptr orb, PortableServer::POA_var poa); protected: CORBA::ORB_var _orb; PortableServer::POA_var _poa; SALOME_ContainerManager *_ContManager; SALOME_ResourcesManager *_ResManager; - SALOME_NamingService *_NS; + SALOME_NamingService_Abstract *_NS = nullptr; std::list _observers; Launcher_cpp _l; }; +/*! + * Methods to be used in SSL mode to skip NS. + */ +namespace KERNEL +{ + SALOMELAUNCHER_EXPORT SALOME_Launcher *getLauncherSA(); +} + #endif diff --git a/src/NamingService/SALOME_Fake_NamingService.cxx b/src/NamingService/SALOME_Fake_NamingService.cxx index 026c22493..7babdc7bf 100644 --- a/src/NamingService/SALOME_Fake_NamingService.cxx +++ b/src/NamingService/SALOME_Fake_NamingService.cxx @@ -20,7 +20,10 @@ #include "SALOME_Fake_NamingService.hxx" #include "Utils_SALOME_Exception.hxx" -SALOME_Fake_NamingService::SALOME_Fake_NamingService(CORBA::ORB_ptr orb):_orb(CORBA::ORB::_duplicate(orb)) +std::mutex SALOME_Fake_NamingService::_mutex; +std::map SALOME_Fake_NamingService::_map; + +SALOME_Fake_NamingService::SALOME_Fake_NamingService(CORBA::ORB_ptr orb) { } @@ -31,6 +34,10 @@ void SALOME_Fake_NamingService::Register(CORBA::Object_ptr ObjRef, const char* P _map[Path] = ObjRefAuto; } +void SALOME_Fake_NamingService::Destroy_Name(const char* Path) +{ +} + CORBA::Object_ptr SALOME_Fake_NamingService::Resolve(const char* Path) { std::string pathCpp(Path); diff --git a/src/NamingService/SALOME_Fake_NamingService.hxx b/src/NamingService/SALOME_Fake_NamingService.hxx index 9f7fc28bd..6393b2042 100644 --- a/src/NamingService/SALOME_Fake_NamingService.hxx +++ b/src/NamingService/SALOME_Fake_NamingService.hxx @@ -21,18 +21,20 @@ #include "omniORB4/CORBA.h" +#include "SALOME_NamingService_Abstract.hxx" + #include #include #include -class SALOME_Fake_NamingService +class NAMINGSERVICE_EXPORT SALOME_Fake_NamingService : public SALOME_NamingService_Abstract { public: SALOME_Fake_NamingService(CORBA::ORB_ptr orb); - void Register(CORBA::Object_ptr ObjRef, const char* Path); - CORBA::Object_ptr Resolve(const char* Path); -private: - CORBA::ORB_var _orb; - std::mutex _mutex; - std::map _map; + void Register(CORBA::Object_ptr ObjRef, const char* Path) override; + CORBA::Object_ptr Resolve(const char* Path) override; + void Destroy_Name(const char* Path) override; +private: + static std::mutex _mutex; + static std::map _map; }; diff --git a/src/NamingService/SALOME_NamingService.cxx b/src/NamingService/SALOME_NamingService.cxx index 7dc133b02..e5601f327 100644 --- a/src/NamingService/SALOME_NamingService.cxx +++ b/src/NamingService/SALOME_NamingService.cxx @@ -87,6 +87,12 @@ SALOME_NamingService::~SALOME_NamingService() //MESSAGE("SALOME_NamingService destruction"); } +SALOME_NamingService *SALOME_NamingService::GetTraditionalNS(SALOME_NamingService_Abstract *ns) +{ + SALOME_NamingService *nsc(dynamic_cast(ns)); + return nsc; +} + // ============================================================================ /*! \brief initializes ORB reference and naming service root context. * diff --git a/src/NamingService/SALOME_NamingService.hxx b/src/NamingService/SALOME_NamingService.hxx index 879c37566..d7bc3cd00 100644 --- a/src/NamingService/SALOME_NamingService.hxx +++ b/src/NamingService/SALOME_NamingService.hxx @@ -38,23 +38,25 @@ #include "Utils_Mutex.hxx" #include "ServiceUnreachable.hxx" -#include "SALOME_NamingService_defs.hxx" +#include "SALOME_NamingService_Abstract.hxx" #ifdef WIN32 //#pragma warning(disable:4290) // Warning Exception ... #endif -class NAMINGSERVICE_EXPORT SALOME_NamingService +class NAMINGSERVICE_EXPORT SALOME_NamingService : public SALOME_NamingService_Abstract { public: SALOME_NamingService(); SALOME_NamingService(CORBA::ORB_ptr orb); virtual ~SALOME_NamingService(); + + static SALOME_NamingService *GetTraditionalNS(SALOME_NamingService_Abstract *ns); void init_orb(CORBA::ORB_ptr orb=0); - void Register(CORBA::Object_ptr ObjRef, const char* Path) ; - CORBA::Object_ptr Resolve(const char* Path) ; + 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) ; CORBA::Object_ptr ResolveComponent(const char* hostname, const char* containerName, @@ -73,7 +75,7 @@ public: std::vector list_directory() ; std::vector list_subdirs() ; std::vector list_directory_recurs() ; - void Destroy_Name(const char* Path) ; + void Destroy_Name(const char* Path) override; virtual void Destroy_Directory(const char* Path) ; virtual void Destroy_FullDirectory(const char* Path) ; char *getIORaddr(); diff --git a/src/NamingService/SALOME_NamingService_Abstract.hxx b/src/NamingService/SALOME_NamingService_Abstract.hxx new file mode 100644 index 000000000..ea6b37305 --- /dev/null +++ b/src/NamingService/SALOME_NamingService_Abstract.hxx @@ -0,0 +1,33 @@ +// Copyright (C) 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 +// + +#pragma once + +#include "SALOME_NamingService_defs.hxx" + +#include "omniORB4/CORBA.h" + +class NAMINGSERVICE_EXPORT SALOME_NamingService_Abstract +{ +public: + virtual void Register(CORBA::Object_ptr ObjRef, const char* Path) = 0; + virtual CORBA::Object_ptr Resolve(const char* Path) = 0; + virtual void Destroy_Name(const char* Path) = 0; + virtual ~SALOME_NamingService_Abstract() { } +}; diff --git a/src/ResourcesManager/SALOME_ResourcesManager.cxx b/src/ResourcesManager/SALOME_ResourcesManager.cxx index 6562acac5..db1e53731 100644 --- a/src/ResourcesManager/SALOME_ResourcesManager.cxx +++ b/src/ResourcesManager/SALOME_ResourcesManager.cxx @@ -111,7 +111,8 @@ SALOME_ResourcesManager::SALOME_ResourcesManager(CORBA::ORB_ptr orb, PortableServer::ObjectId_var id = _poa->activate_object(this); CORBA::Object_var obj = _poa->id_to_reference(id); Engines::ResourcesManager_var refContMan = Engines::ResourcesManager::_narrow(obj); - _NS->Register(refContMan,_ResourcesManagerNameInNS); + if(_NS) + _NS->Register(refContMan,_ResourcesManagerNameInNS); MESSAGE("SALOME_ResourcesManager constructor end"); } @@ -137,6 +138,8 @@ SALOME_ResourcesManager::~SALOME_ResourcesManager() void SALOME_ResourcesManager::Shutdown() { MESSAGE("Shutdown"); + if(!_NS) + return ; _NS->Destroy_Name(_ResourcesManagerNameInNS); PortableServer::ObjectId_var oid = _poa->servant_to_id(this); _poa->deactivate_object(oid);