From: Anthony Geay Date: Thu, 18 Feb 2021 15:29:40 +0000 (+0100) Subject: Kernel evolution for salome gui without neither NS nor other servers. X-Git-Tag: V9_7_0a1~12 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b741d9021836f43ec742959b06b0941e1a1da7c9;p=modules%2Fkernel.git Kernel evolution for salome gui without neither NS nor other servers. --- diff --git a/src/Container/Container_i.cxx b/src/Container/Container_i.cxx index ec10aaedd..d782ae7cf 100644 --- a/src/Container/Container_i.cxx +++ b/src/Container/Container_i.cxx @@ -54,6 +54,7 @@ int SIGUSR1 = 1000; #include "SALOME_FileTransfer_i.hxx" #include "Salome_file_i.hxx" #include "SALOME_NamingService.hxx" +#include "SALOME_Fake_NamingService.hxx" #include "Basics_Utils.hxx" #ifdef _XOPEN_SOURCE @@ -133,14 +134,14 @@ Engines_Container_i::Engines_Container_i (CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, char *containerName , int argc , char* argv[], - bool activAndRegist, + SALOME_NamingService_Abstract *ns, bool isServantAloneInProcess ) : _NS(0),_id(0),_numInstance(0),_isServantAloneInProcess(isServantAloneInProcess) { _pid = (long)getpid(); - if(activAndRegist) + if(ns) ActSigIntHandler() ; _argc = argc ; @@ -177,10 +178,9 @@ Engines_Container_i::Engines_Container_i (CORBA::ORB_ptr orb, // Pour les containers paralleles: il ne faut pas enregistrer et activer // le container generique, mais le container specialise - if(activAndRegist) { _id = _poa->activate_object(this); - _NS = new SALOME_NamingService(); + _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 @@ -1900,42 +1900,35 @@ void Engines_Container_i::clearTemporaryFiles() _tmp_files.clear(); } -/* -std::string Engines_Container_i::AnotherMethodeToReplace_PyString_AsString(PyObject * result) +static Engines_Container_i *_container_singleton_ssl = nullptr; + +static Engines::Container_var _container_ref_singleton_ssl; + +Engines_Container_i *KERNEL::getContainerSA() { - std::string my_result = ""; - if (PyUnicode_Check(result)) { - // Convert string to bytes. - // strdup() bytes into my_result. - PyObject * temp_bytes = PyUnicode_AsEncodedString(result, "ASCII", "strict"); // Owned reference - if (temp_bytes != NULL) { - my_result = PyBytes_AS_STRING(temp_bytes); // Borrowed pointer - my_result = strdup(my_result); - Py_DECREF(temp_bytes); - } else { - // TODO PY3: Handle encoding error. - Py_DECREF(temp_bytes); - } + if(!_container_singleton_ssl) + { + int argc(0); + CORBA::ORB_var orb = CORBA::ORB_init(argc,nullptr); + CORBA::Object_var obj = orb->resolve_initial_references("RootPOA"); + PortableServer::POA_var poa = PortableServer::POA::_narrow(obj); + PortableServer::POAManager_var pman = poa->the_POAManager(); + CORBA::PolicyList policies; + policies.length(0); + // + char *argv[4] = {"Container","FactoryServer","toto",nullptr}; + SALOME_Fake_NamingService ns; + _container_singleton_ssl = new Engines_Container_i(orb,poa,"FactoryServer",2,argv,&ns,false); + PortableServer::ObjectId * cont_id = _container_singleton_ssl->getCORBAId(); + // + CORBA::Object_var zeRef = poa->id_to_reference(*cont_id); + _container_ref_singleton_ssl = Engines::Container::_narrow(zeRef); + } + return _container_singleton_ssl; +} - } else if (PyBytes_Check(result)) { - // strdup() bytes into my_result. - my_result = PyBytes_AS_STRING(result); // Borrowed pointer - my_result = strdup(my_result); - } else { - // Convert into your favorite string representation. - // Convert string to bytes if it is not already. - // strdup() bytes into my_result. - // TODO PY3: Check if only bytes is ok. - PyObject * temp_bytes = PyObject_Bytes(result); // Owned reference - if (temp_bytes != NULL) { - my_result = PyBytes_AS_STRING(temp_bytes); // Borrowed pointer - my_result = strdup(my_result); - Py_DECREF(temp_bytes); - } else { - // TODO PY3: Handle error. - Py_DECREF(temp_bytes); - } - } - return my_result; +Engines::Container_var KERNEL::getContainerRefSA() +{ + getContainerSA(); + return _container_ref_singleton_ssl; } -*/ 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/Container/SALOME_Container_i.hxx b/src/Container/SALOME_Container_i.hxx index 0aa3426b2..7115bf9aa 100644 --- a/src/Container/SALOME_Container_i.hxx +++ b/src/Container/SALOME_Container_i.hxx @@ -48,7 +48,7 @@ #include #include -class SALOME_NamingService; +class SALOME_NamingService_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[], - bool activAndRegist = true, + SALOME_NamingService_Abstract *ns = nullptr, bool isServantAloneInProcess = true); virtual ~Engines_Container_i(); @@ -140,6 +140,7 @@ public: void registerTemporaryFile( const std::string& fileName ); void unregisterTemporaryFile( const std::string& fileName ); void clearTemporaryFiles(); + PortableServer::ObjectId *getCORBAId() const { return _id; } protected: @@ -150,7 +151,7 @@ protected: bool _isSupervContainer; - SALOME_NamingService *_NS ; + SALOME_NamingService_Abstract *_NS ; std::string _library_path; std::string _containerName; std::string _logfilename; @@ -173,4 +174,13 @@ protected: bool _isServantAloneInProcess; }; +/*! + * Methods to be used in SSL mode to skip NS. + */ +namespace KERNEL +{ + CONTAINER_EXPORT Engines_Container_i *getContainerSA(); + CONTAINER_EXPORT Engines::Container_var getContainerRefSA(); +} + #endif diff --git a/src/DSC/DSC_User/DSC_Exception.hxx b/src/DSC/DSC_User/DSC_Exception.hxx index b9c498c03..b44f5c842 100644 --- a/src/DSC/DSC_User/DSC_Exception.hxx +++ b/src/DSC/DSC_User/DSC_Exception.hxx @@ -81,7 +81,7 @@ public: return oss_.str(); } - // Surtout ne pas écrire le code suivant: + // Surtout ne pas �crire le code suivant: // car oss_.str() renvoie une string temporaire // operator const char*() // { @@ -91,32 +91,25 @@ public: }; /* end class OSS */ #endif - -// Cette fonction provient de Utils_SALOME_Exception -// Solution pas très élégante mais contrainte par les manques de la classe SALOME_Exception -const char *makeText( const char *text, const char *fileName, const unsigned int lineNumber); - struct DSC_Exception : public SALOME_Exception { - // Attention, en cas de modification des paramètres par défaut + // Attention, en cas de modification des param�tres par d�faut // il est necessaire de les repporter dans la macro DSC_EXCEPTION ci-dessous // Le constructeur de la SALOME_Exception demande une chaine non vide - // Du coup on est obliger de la désallouer avant d'y mettre la notre + // Du coup on est obliger de la d�sallouer avant d'y mettre la notre // car le what n'est pas virtuel donc il faut que le contenu de SALOME_Exception::_text // soit utilisable. - // Ne pas mettre lineNumber=0 à cause du calcul log dans la SALOME_Exception si fileName est défini + // Ne pas mettre lineNumber=0 � cause du calcul log dans la SALOME_Exception si fileName est d�fini DSC_Exception( const std::string & text, const char *fileName="", const unsigned int lineNumber=0, const char *funcName="" ): - SALOME_Exception(text.c_str()) , + SALOME_Exception(text) , _dscText(text), _filefuncName(setFileFuncName(fileName?fileName:"",funcName?funcName:"")), _lineNumber(lineNumber), _exceptionName("DSC_Exception") { - // Mise en cohérence avec l'exception SALOME (à revoir) - delete [] ((char*)SALOME_Exception::_text); if (! _filefuncName.empty() ) SALOME_Exception::_text = makeText(text.c_str(),_filefuncName.c_str(),lineNumber) ; else @@ -135,10 +128,10 @@ struct DSC_Exception : public SALOME_Exception { return _what.c_str() ; } - // L'opérateur = de SALOME_Exception n'est pas défini - // problème potentiel concernant la recopie de son pointeur _text + // L'op�rateur = de SALOME_Exception n'est pas d�fini + // probl�me potentiel concernant la recopie de son pointeur _text - // Le destructeur de la SALOME_Exception devrait être virtuel + // Le destructeur de la SALOME_Exception devrait �tre virtuel // sinon pb avec nos attributs de type pointeur. virtual ~DSC_Exception(void) noexcept {}; @@ -173,8 +166,8 @@ protected: virtual ~Derived(void) noexcept;\ };\ -//Sert à eviter le problème d'identification RTTI des exceptions -//Crée un unique typeInfo pour tous les bibliothèques composants SALOME +//Sert � eviter le probl�me d'identification RTTI des exceptions +//Cr�e un unique typeInfo pour tous les biblioth�ques composants SALOME //dans un fichier cxx #define DSC_EXCEPTION_CXX(NameSpace,Derived) NameSpace::Derived::~Derived(void) noexcept {} diff --git a/src/KernelHelpers/KernelHelpersUseCases.cxx b/src/KernelHelpers/KernelHelpersUseCases.cxx index 7c41260ad..6fa36b98e 100644 --- a/src/KernelHelpers/KernelHelpersUseCases.cxx +++ b/src/KernelHelpers/KernelHelpersUseCases.cxx @@ -31,7 +31,7 @@ bool TEST_corba() { LOG("TEST_Corba: orb ERROR"); return false; } - SALOME_NamingService * ns = KERNEL::getNamingService(); + SALOME_NamingService_Abstract * ns = KERNEL::getNamingService(); if ( ns == NULL ) { LOG("TEST_Corba: ns ERROR"); return false; diff --git a/src/KernelHelpers/SALOME_KernelServices.cxx b/src/KernelHelpers/SALOME_KernelServices.cxx index 4ca01ee7a..516aeb4fa 100644 --- a/src/KernelHelpers/SALOME_KernelServices.cxx +++ b/src/KernelHelpers/SALOME_KernelServices.cxx @@ -20,11 +20,15 @@ // Author: Guillaume Boulant (EDF/R&D) #include "SALOME_KernelServices.hxx" +#include "SALOME_Fake_NamingService.hxx" #include +#include std::map _compo_map; +std::unique_ptr _naming_service; + namespace KERNEL { /** @@ -41,15 +45,28 @@ namespace KERNEL { return orb; } + void assignNamingServiceSL() + { + if ( !_naming_service.get() ) + { + _naming_service.reset( new SALOME_Fake_NamingService ); + } + else + { + THROW_SALOME_EXCEPTION("assignNamingServiceSL : NS SALOME Wrapper is already set !"); + } + } + /** * This function returns a static reference to the SALOME naming service. */ - SALOME_NamingService * getNamingService() { - static SALOME_NamingService * namingService; - if ( namingService == NULL ) { - namingService = new SALOME_NamingService(getORB()); + SALOME_NamingService_Abstract *getNamingService() + { + if ( !_naming_service.get() ) + { + _naming_service.reset( new SALOME_NamingService(getORB()) ); } - return namingService; + return _naming_service.get(); } /** @@ -58,7 +75,7 @@ namespace KERNEL { SALOME_LifeCycleCORBA * getLifeCycleCORBA() { static SALOME_LifeCycleCORBA * lifeCycleCORBA; if ( lifeCycleCORBA == NULL ) { - SALOME_NamingService *aNamingService = getNamingService(); + SALOME_NamingService_Abstract *aNamingService = getNamingService(); lifeCycleCORBA = new SALOME_LifeCycleCORBA(aNamingService); } return lifeCycleCORBA; @@ -73,7 +90,7 @@ namespace KERNEL { SALOMEDS::Study_ptr getStudyServant() { static SALOMEDS::Study_ptr aStudy; if(CORBA::is_nil(aStudy)){ - SALOME_NamingService *aNamingService = getNamingService(); + SALOME_NamingService_Abstract *aNamingService = getNamingService(); CORBA::Object_ptr anObject = aNamingService->Resolve("/Study"); aStudy = SALOMEDS::Study::_narrow(anObject); } @@ -88,7 +105,7 @@ namespace KERNEL { SALOME::Session_ptr getSalomeSession() { static SALOME::Session_ptr salomeSession; if(CORBA::is_nil(salomeSession)){ - SALOME_NamingService *aNamingService = getNamingService(); + SALOME_NamingService_Abstract *aNamingService = getNamingService(); CORBA::Object_ptr obj = aNamingService->Resolve("/Kernel/Session"); salomeSession = SALOME::Session::_narrow(obj); } @@ -105,7 +122,7 @@ namespace KERNEL { static Engines::SalomeLauncher_ptr salomeLauncher; if(CORBA::is_nil(salomeLauncher)){ //LOG("KERNEL_services::getSalomeLauncher(): creating the static instance"); - SALOME_NamingService *aNamingService = getNamingService(); + SALOME_NamingService_Abstract *aNamingService = getNamingService(); CORBA::Object_ptr obj = aNamingService->Resolve("/SalomeLauncher"); salomeLauncher = Engines::SalomeLauncher::_narrow(obj); } @@ -115,7 +132,7 @@ namespace KERNEL { Engines::ResourcesManager_ptr getResourcesManager() { static Engines::ResourcesManager_ptr resourcesManager; if(CORBA::is_nil(resourcesManager)){ - SALOME_NamingService *aNamingService = getNamingService(); + SALOME_NamingService_Abstract *aNamingService = getNamingService(); CORBA::Object_ptr obj = aNamingService->Resolve("/ResourcesManager"); resourcesManager = Engines::ResourcesManager::_narrow(obj); } diff --git a/src/KernelHelpers/SALOME_KernelServices.hxx b/src/KernelHelpers/SALOME_KernelServices.hxx index 0568d5567..0651bda94 100644 --- a/src/KernelHelpers/SALOME_KernelServices.hxx +++ b/src/KernelHelpers/SALOME_KernelServices.hxx @@ -39,7 +39,8 @@ namespace KERNEL { // --------------------------------------------- // SALOME KERNEL main services KERNELHELPERS_EXPORT CORBA::ORB_ptr getORB(); - KERNELHELPERS_EXPORT SALOME_NamingService * getNamingService(); + KERNELHELPERS_EXPORT SALOME_NamingService_Abstract *getNamingService(); + KERNELHELPERS_EXPORT void assignNamingServiceSL(); KERNELHELPERS_EXPORT SALOME_LifeCycleCORBA * getLifeCycleCORBA(); KERNELHELPERS_EXPORT SALOME::Session_ptr getSalomeSession(); KERNELHELPERS_EXPORT SALOMEDS::Study_ptr getStudyServant(); diff --git a/src/KernelHelpers/Test/KernelHelpersUnitTests.cxx b/src/KernelHelpers/Test/KernelHelpersUnitTests.cxx index 390ebb658..c1220bc6c 100644 --- a/src/KernelHelpers/Test/KernelHelpersUnitTests.cxx +++ b/src/KernelHelpers/Test/KernelHelpersUnitTests.cxx @@ -59,7 +59,7 @@ void KernelHelpersUnitTests::TEST_corba() CPPUNIT_ASSERT(!CORBA::is_nil(orb)); - SALOME_NamingService * ns = KERNEL::getNamingService(); + SALOME_NamingService_Abstract * ns = KERNEL::getNamingService(); CPPUNIT_ASSERT(ns!=NULL); SALOME_LifeCycleCORBA * lcc = KERNEL::getLifeCycleCORBA(); diff --git a/src/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/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx index 181f247e6..1d121a0af 100644 --- a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx +++ b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx @@ -82,7 +82,7 @@ IncompatibleComponent::IncompatibleComponent(const IncompatibleComponent &ex): */ //============================================================================= -SALOME_LifeCycleCORBA::SALOME_LifeCycleCORBA(SALOME_NamingService *ns) +SALOME_LifeCycleCORBA::SALOME_LifeCycleCORBA(SALOME_NamingService_Abstract *ns) { // be sure to have an instance of traceCollector, when used via SWIG // in a Python module @@ -104,17 +104,19 @@ SALOME_LifeCycleCORBA::SALOME_LifeCycleCORBA(SALOME_NamingService *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! - - CORBA::Object_var obj = - _NS->Resolve(SALOME_ContainerManager::_ContainerManagerNameInNS); - if (CORBA::is_nil(obj)) - throw SALOME_Exception("Error: Cannot resolve ContainerManager in Naming Service"); - _ContManager=Engines::ContainerManager::_narrow(obj); - - obj = _NS->Resolve(SALOME_ResourcesManager::_ResourcesManagerNameInNS); - if (CORBA::is_nil(obj)) - throw SALOME_Exception("Error: Cannot resolve ResourceManager in Naming Service"); - _ResManager=Engines::ResourcesManager::_narrow(obj); + if( dynamic_cast(_NS) ) + { + CORBA::Object_var obj = + _NS->Resolve(SALOME_ContainerManager::_ContainerManagerNameInNS); + if (CORBA::is_nil(obj)) + throw SALOME_Exception("Error: Cannot resolve ContainerManager in Naming Service"); + _ContManager=Engines::ContainerManager::_narrow(obj); + + obj = _NS->Resolve(SALOME_ResourcesManager::_ResourcesManagerNameInNS); + if (CORBA::is_nil(obj)) + throw SALOME_Exception("Error: Cannot resolve ResourceManager in Naming Service"); + _ResManager=Engines::ResourcesManager::_narrow(obj); + } } //============================================================================= @@ -824,7 +826,7 @@ void SALOME_LifeCycleCORBA::copyFile(const char* hostSrc, const char* fileSrc, c * * \return the naming service */ -SALOME_NamingService * SALOME_LifeCycleCORBA::namingService() +SALOME_NamingService_Abstract * SALOME_LifeCycleCORBA::namingService() { return _NS; } @@ -835,5 +837,8 @@ SALOME_NamingService * SALOME_LifeCycleCORBA::namingService() */ CORBA::ORB_ptr SALOME_LifeCycleCORBA::orb() { - return _NS->orb(); + SALOME_NamingService *NSC = dynamic_cast(_NS); + if(!_NS) + THROW_SALOME_EXCEPTION("SALOME_LifeCycleCORBA::orb : not a CORBA SALOME_NamingService "); + return NSC->orb(); } diff --git a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx index 0e89b532d..11b26c574 100644 --- a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx +++ b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx @@ -50,7 +50,7 @@ #endif -class SALOME_NamingService; +class SALOME_NamingService_Abstract; class LIFECYCLECORBA_EXPORT IncompatibleComponent : public SALOME_Exception { @@ -62,7 +62,7 @@ public : class LIFECYCLECORBA_EXPORT SALOME_LifeCycleCORBA { public: - SALOME_LifeCycleCORBA(SALOME_NamingService *ns = 0); + SALOME_LifeCycleCORBA(SALOME_NamingService_Abstract *ns = 0); virtual ~SALOME_LifeCycleCORBA(); Engines::EngineComponent_ptr @@ -95,7 +95,7 @@ public: Engines::ContainerManager_ptr getContainerManager(); Engines::ResourcesManager_ptr getResourcesManager(); - SALOME_NamingService * namingService(); + SALOME_NamingService_Abstract * namingService(); CORBA::ORB_ptr orb(); void copyFile(const char* hostSrc, const char* fileSrc, const char* hostDest, const char* fileDest); @@ -118,8 +118,8 @@ protected: _LoadComponent(const Engines::ContainerParameters& params, const char *componentName); - SALOME_NamingService *_NS; - SALOME_NamingService *_NSnew; + SALOME_NamingService_Abstract *_NS; + SALOME_NamingService_Abstract *_NSnew; Engines::ContainerManager_var _ContManager; Engines::ResourcesManager_var _ResManager; diff --git a/src/NamingService/CMakeLists.txt b/src/NamingService/CMakeLists.txt index 797ddeb85..42f433d7d 100644 --- a/src/NamingService/CMakeLists.txt +++ b/src/NamingService/CMakeLists.txt @@ -31,6 +31,8 @@ SET(SalomeNS_SOURCES SALOME_NamingService.cxx ServiceUnreachable.cxx NamingService_WaitForServerReadiness.cxx + SALOME_Fake_NamingService.cxx + SALOME_NamingService_Abstract.cxx ) diff --git a/src/NamingService/NamingService_WaitForServerReadiness.cxx b/src/NamingService/NamingService_WaitForServerReadiness.cxx index 42d5a10a6..ea44d4ff4 100644 --- a/src/NamingService/NamingService_WaitForServerReadiness.cxx +++ b/src/NamingService/NamingService_WaitForServerReadiness.cxx @@ -26,6 +26,8 @@ // $Header$ // #include "NamingService_WaitForServerReadiness.hxx" +#include "SALOME_NamingService.hxx" + #include "utilities.h" #include #include @@ -101,3 +103,10 @@ void NamingService_WaitForServerReadiness(SALOME_NamingService* NS, exit(EXIT_FAILURE); } } + +/*! + * Fake NS : no need to wait ;) + */ +void NamingService_WaitForServerReadiness(SALOME_Fake_NamingService* NS, std::string serverName) +{ +} diff --git a/src/NamingService/NamingService_WaitForServerReadiness.hxx b/src/NamingService/NamingService_WaitForServerReadiness.hxx index 5ed45f055..9e0fd7308 100644 --- a/src/NamingService/NamingService_WaitForServerReadiness.hxx +++ b/src/NamingService/NamingService_WaitForServerReadiness.hxx @@ -28,11 +28,16 @@ #ifndef _NAMINGSERVICE_WAITFORSERVERREADINESS_HXX_ #define _NAMINGSERVICE_WAITFORSERVERREADINESS_HXX_ -#include "SALOME_NamingService.hxx" +#include "SALOME_NamingService_defs.hxx" #include -void NAMINGSERVICE_EXPORT NamingService_WaitForServerReadiness(SALOME_NamingService* NS, - std::string serverName); +class SALOME_NamingService; + +void NAMINGSERVICE_EXPORT NamingService_WaitForServerReadiness(SALOME_NamingService* NS, std::string serverName); + +class SALOME_Fake_NamingService; + +void NAMINGSERVICE_EXPORT NamingService_WaitForServerReadiness(SALOME_Fake_NamingService* NS, std::string serverName); #endif diff --git a/src/NamingService/SALOME_Fake_NamingService.cxx b/src/NamingService/SALOME_Fake_NamingService.cxx new file mode 100644 index 000000000..f521034a2 --- /dev/null +++ b/src/NamingService/SALOME_Fake_NamingService.cxx @@ -0,0 +1,90 @@ +// 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 +// + +#include "SALOME_Fake_NamingService.hxx" +#include "Utils_SALOME_Exception.hxx" + +std::mutex SALOME_Fake_NamingService::_mutex; +std::map SALOME_Fake_NamingService::_map; + +SALOME_Fake_NamingService::SALOME_Fake_NamingService(CORBA::ORB_ptr orb) +{ +} + +void SALOME_Fake_NamingService::init_orb(CORBA::ORB_ptr orb) +{ +} + +void SALOME_Fake_NamingService::Register(CORBA::Object_ptr ObjRef, const char* Path) +{ + std::lock_guard g(_mutex); + CORBA::Object_var ObjRefAuto = CORBA::Object::_duplicate(ObjRef); + _map[Path] = ObjRefAuto; +} + +void SALOME_Fake_NamingService::Destroy_Name(const char* Path) +{ +} + +void SALOME_Fake_NamingService::Destroy_Directory(const char* Path) +{ +} + +void SALOME_Fake_NamingService::Destroy_FullDirectory(const char* Path) +{ +} + +bool SALOME_Fake_NamingService::Change_Directory(const char* Path) +{ + return true; +} + +std::vector SALOME_Fake_NamingService::list_subdirs() +{ + return std::vector(); +} + +std::vector SALOME_Fake_NamingService::list_directory() +{ + return std::vector(); +} + +CORBA::Object_ptr SALOME_Fake_NamingService::Resolve(const char* Path) +{ + std::string pathCpp(Path); + auto it = _map.find(pathCpp); + if( it != _map.end() ) + return CORBA::Object::_duplicate((*it).second); + return CORBA::Object::_nil(); +} + +CORBA::Object_ptr SALOME_Fake_NamingService::ResolveFirst(const char* Path) +{ + return CORBA::Object::_nil(); +} + +SALOME_NamingService_Abstract *SALOME_Fake_NamingService::clone() +{ + return new SALOME_Fake_NamingService; +} + +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); +} diff --git a/src/NamingService/SALOME_Fake_NamingService.hxx b/src/NamingService/SALOME_Fake_NamingService.hxx new file mode 100644 index 000000000..f60e1480e --- /dev/null +++ b/src/NamingService/SALOME_Fake_NamingService.hxx @@ -0,0 +1,50 @@ +// 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 "omniORB4/CORBA.h" + +#include "SALOME_NamingService_Abstract.hxx" + +#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; +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..4268406c0 100644 --- a/src/NamingService/SALOME_NamingService.cxx +++ b/src/NamingService/SALOME_NamingService.cxx @@ -73,6 +73,11 @@ SALOME_NamingService::SALOME_NamingService(CORBA::ORB_ptr orb) _initialize_root_context(); } +SALOME_NamingService_Abstract *SALOME_NamingService::clone() +{ + return new SALOME_NamingService(_orb); +} + // ============================================================================ /*! \brief Standard destructor. * @@ -87,6 +92,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. * @@ -548,29 +559,6 @@ SALOME_NamingService::ResolveComponent(const char* hostname, } } -// ============================================================================ -/*! \brief provide a default container name if empty. - * - * the given container name is returned unchanged, unless it is empty. - * \param containerName - * \return container name, where empty input is replaced by "FactoryServer", - * without the path. - * \sa BuildContainerNameForNS(const char *containerName, const char *hostname) - */ -// ============================================================================ - -std::string SALOME_NamingService::ContainerName(const char *containerName) -{ - std::string ret,containerNameCpp(containerName); - - if (containerNameCpp.empty()) - ret = "FactoryServer"; - else - ret = containerName; - - return ret; -} - // ============================================================================ /*! \brief build a container name, given a ContainerParameters struct. * @@ -595,7 +583,7 @@ std::string SALOME_NamingService::ContainerName(const Engines::ContainerParamete else nbproc = params.nb_proc; - std::string ret(ContainerName(params.container_name)); + std::string ret(SALOME_NamingService_Abstract::ContainerName(params.container_name)); if ( nbproc >= 1 ) { @@ -607,30 +595,6 @@ std::string SALOME_NamingService::ContainerName(const Engines::ContainerParamete 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. This form gives a suffixed containerName in case of - * multi processor machine. - * \param containerName name of the container in which the component is - instantiated. - * \param hostname name of the host of the container, without domain names. - * \return the path under the form /Containers/hostname/containerName - * \sa ContainerName(const Engines::MachineParameters& params) - */ -// ============================================================================ - -std::string SALOME_NamingService::BuildContainerNameForNS(const char *containerName, const char *hostname) -{ - std::string ret("/Containers/"); - ret += hostname; - ret += "/"; - ret += ContainerName(containerName); - - return ret; -} - // ============================================================================ /*! \brief build a string representing a container in Naming Service. * diff --git a/src/NamingService/SALOME_NamingService.hxx b/src/NamingService/SALOME_NamingService.hxx index 879c37566..9bd9dc0b1 100644 --- a/src/NamingService/SALOME_NamingService.hxx +++ b/src/NamingService/SALOME_NamingService.hxx @@ -38,46 +38,47 @@ #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 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) ; CORBA::Object_ptr ResolveComponent(const char* hostname, const char* containerName, const char* componentName, - const int nbproc=0) ; - std::string ContainerName(const char *ContainerName); + const int nbproc=0) override; std::string ContainerName(const Engines::ContainerParameters& params); - std::string BuildContainerNameForNS(const char *ContainerName, const char *hostname); std::string BuildContainerNameForNS(const Engines::ContainerParameters& params, const char *hostname); int Find(const char* name) ; bool Create_Directory(const char* Path) ; - bool Change_Directory(const char* Path) ; + bool Change_Directory(const char* Path) override; char* Current_Directory() ; void list() ; - std::vector list_directory() ; - std::vector list_subdirs() ; + std::vector list_directory() override; + std::vector list_subdirs() override; std::vector list_directory_recurs() ; - void Destroy_Name(const char* Path) ; - virtual void Destroy_Directory(const char* Path) ; - virtual void Destroy_FullDirectory(const char* Path) ; + void Destroy_Name(const char* Path) override; + void Destroy_Directory(const char* Path) override; + void Destroy_FullDirectory(const char* Path) override; char *getIORaddr(); CORBA::ORB_ptr orb(); + SALOME_NamingService_Abstract *clone() override; protected: Utils_Mutex _myMutex; diff --git a/src/NamingService/SALOME_NamingService_Abstract.cxx b/src/NamingService/SALOME_NamingService_Abstract.cxx new file mode 100644 index 000000000..4469dfed1 --- /dev/null +++ b/src/NamingService/SALOME_NamingService_Abstract.cxx @@ -0,0 +1,67 @@ +// 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 +// + +#include "SALOME_NamingService_Abstract.hxx" + +// ============================================================================ +/*! \brief provide a default container name if empty. + * + * the given container name is returned unchanged, unless it is empty. + * \param containerName + * \return container name, where empty input is replaced by "FactoryServer", + * without the path. + * \sa BuildContainerNameForNS(const char *containerName, const char *hostname) + */ +// ============================================================================ + +std::string SALOME_NamingService_Abstract::ContainerName(const char *containerName) +{ + std::string ret,containerNameCpp(containerName); + + if (containerNameCpp.empty()) + ret = "FactoryServer"; + else + ret = containerName; + + 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. This form gives a suffixed containerName in case of + * multi processor machine. + * \param containerName name of the container in which the component is + instantiated. + * \param hostname name of the host of the container, without domain names. + * \return the path under the form /Containers/hostname/containerName + * \sa ContainerName(const Engines::MachineParameters& params) + */ +// ============================================================================ + +std::string SALOME_NamingService_Abstract::BuildContainerNameForNS(const char *containerName, const char *hostname) +{ + std::string ret("/Containers/"); + ret += hostname; + ret += "/"; + ret += ContainerName(containerName); + + return ret; +} diff --git a/src/NamingService/SALOME_NamingService_Abstract.hxx b/src/NamingService/SALOME_NamingService_Abstract.hxx new file mode 100644 index 000000000..ce7301c79 --- /dev/null +++ b/src/NamingService/SALOME_NamingService_Abstract.hxx @@ -0,0 +1,47 @@ +// 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" + +#include +#include + +class NAMINGSERVICE_EXPORT SALOME_NamingService_Abstract +{ +public: + virtual void init_orb(CORBA::ORB_ptr orb=0) = 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_Name(const char* Path) = 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 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 char *ContainerName); + static std::string BuildContainerNameForNS(const char *ContainerName, const char *hostname); +}; diff --git a/src/NamingService/Test/NamingServiceTest.cxx b/src/NamingService/Test/NamingServiceTest.cxx index 79f168fad..ef99a79d1 100644 --- a/src/NamingService/Test/NamingServiceTest.cxx +++ b/src/NamingService/Test/NamingServiceTest.cxx @@ -815,11 +815,11 @@ void NamingServiceTest::testContainerName() { std::string ref0 = "FactoryServer"; - std::string ret = _NS.ContainerName(""); + std::string ret = SALOME_NamingService_Abstract::ContainerName(""); CPPUNIT_ASSERT(ret == ref0); ref0 = "MyContainerName"; - ret = _NS.ContainerName(ref0.c_str()); + ret = SALOME_NamingService_Abstract::ContainerName(ref0.c_str()); CPPUNIT_ASSERT(ret == ref0); } @@ -855,11 +855,11 @@ void NamingServiceTest::testBuildContainerNameForNS() { std::string ref0 = "/Containers/theHostName/theContainerName"; - std::string ret = _NS.BuildContainerNameForNS("theContainerName","theHostName"); + std::string ret = SALOME_NamingService_Abstract::BuildContainerNameForNS("theContainerName","theHostName"); CPPUNIT_ASSERT(ret == ref0); ref0 = "/Containers/theHostName/FactoryServer"; - ret = _NS.BuildContainerNameForNS("","theHostName"); + ret = SALOME_NamingService_Abstract::BuildContainerNameForNS("","theHostName"); CPPUNIT_ASSERT(ret == ref0); } 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); diff --git a/src/SALOMEDS/SALOMEDS.cxx b/src/SALOMEDS/SALOMEDS.cxx index 1a73c312f..bd1c112b6 100644 --- a/src/SALOMEDS/SALOMEDS.cxx +++ b/src/SALOMEDS/SALOMEDS.cxx @@ -35,6 +35,7 @@ #include "SALOMEDSClient.hxx" #include "SALOMEDSClient_IParameters.hxx" #include "SALOMEDS_IParameters.hxx" +#include "SALOME_Fake_NamingService.hxx" #include "SALOMEDS_Defines.hxx" @@ -105,10 +106,8 @@ extern "C" return new SALOMEDS_StudyBuilder(theBuilder); } - SALOMEDS_EXPORT - void CreateStudy(CORBA::ORB_ptr orb, PortableServer::POA_ptr root_poa) + void CreateStudyNSAbstract(CORBA::ORB_ptr orb, PortableServer::POA_ptr root_poa, SALOME_NamingService_Abstract& namingService) { - SALOME_NamingService namingService(orb); CORBA::Object_var obj = namingService.Resolve( "/Study" ); SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow( obj ); if( CORBA::is_nil(aStudy) ) { @@ -125,17 +124,32 @@ extern "C" threadPol->destroy(); SALOMEDS_Study_i::SetThePOA(poa); - SALOMEDS_Study_i* aStudy_i = new SALOMEDS_Study_i(orb); + SALOMEDS_Study_i* aStudy_i = new SALOMEDS_Study_i(orb,&namingService); // Activate the objects. This tells the POA that the objects are ready to accept requests. PortableServer::ObjectId_var aStudy_iid = root_poa->activate_object(aStudy_i); aStudy = aStudy_i->_this(); + KERNEL::setStudyServantSA(aStudy,poa); namingService.Register(aStudy, "/Study"); aStudy_i->GetImpl()->GetDocument()->SetModified(false); aStudy_i->_remove_ref(); } } + SALOMEDS_EXPORT + void CreateStudy(CORBA::ORB_ptr orb, PortableServer::POA_ptr root_poa) + { + SALOME_NamingService namingService(orb); + CreateStudyNSAbstract(orb,root_poa,namingService); + } + + SALOMEDS_EXPORT + void CreateStudyWithoutNS(CORBA::ORB_ptr orb, PortableServer::POA_ptr root_poa) + { + SALOME_Fake_NamingService namingService(orb); + CreateStudyNSAbstract(orb,root_poa,namingService); + } + SALOMEDS_EXPORT SALOMEDSClient_IParameters* GetIParameters(const _PTR(AttributeParameter)& ap) { diff --git a/src/SALOMEDS/SALOMEDS_Driver_i.cxx b/src/SALOMEDS/SALOMEDS_Driver_i.cxx index c82cc604e..a5597708d 100644 --- a/src/SALOMEDS/SALOMEDS_Driver_i.cxx +++ b/src/SALOMEDS/SALOMEDS_Driver_i.cxx @@ -348,13 +348,16 @@ SALOMEDSImpl_TMPFile* SALOMEDS_Driver_i::DumpPython(bool isPublished, // SALOMEDS_DriverFactory //############################################################################################################### -SALOMEDS_DriverFactory_i::SALOMEDS_DriverFactory_i(CORBA::ORB_ptr theORB, bool isNSAvail) +SALOMEDS_DriverFactory_i::SALOMEDS_DriverFactory_i(CORBA::ORB_ptr theORB, bool isNSAvail):_orb( CORBA::ORB::_duplicate(theORB) ) { - _orb = CORBA::ORB::_duplicate(theORB); if(isNSAvail) _name_service = new SALOME_NamingService(_orb); } +SALOMEDS_DriverFactory_i::SALOMEDS_DriverFactory_i(CORBA::ORB_ptr theORB, SALOME_NamingService_Abstract *ns):_orb( CORBA::ORB::_duplicate(theORB) ) +{ + _name_service = ns->clone(); +} SALOMEDS_DriverFactory_i::~SALOMEDS_DriverFactory_i() { diff --git a/src/SALOMEDS/SALOMEDS_Driver_i.hxx b/src/SALOMEDS/SALOMEDS_Driver_i.hxx index 3ec27fd16..3ffeef383 100644 --- a/src/SALOMEDS/SALOMEDS_Driver_i.hxx +++ b/src/SALOMEDS/SALOMEDS_Driver_i.hxx @@ -111,11 +111,13 @@ class SALOMEDS_DriverFactory_i : public virtual SALOMEDSImpl_DriverFactory { protected: CORBA::ORB_var _orb; - SALOME_NamingService* _name_service = nullptr; + SALOME_NamingService_Abstract* _name_service = nullptr; public: SALOMEDS_DriverFactory_i(CORBA::ORB_ptr theORB, bool isNSAvail = true); + + SALOMEDS_DriverFactory_i(CORBA::ORB_ptr theORB, SALOME_NamingService_Abstract *ns); virtual ~SALOMEDS_DriverFactory_i(); diff --git a/src/SALOMEDS/SALOMEDS_Study_i.cxx b/src/SALOMEDS/SALOMEDS_Study_i.cxx index 31a2bef46..60961b891 100644 --- a/src/SALOMEDS/SALOMEDS_Study_i.cxx +++ b/src/SALOMEDS/SALOMEDS_Study_i.cxx @@ -64,7 +64,8 @@ UNEXPECT_CATCH(LockProtection, SALOMEDS::StudyBuilder::LockProtection) static SALOMEDS_Driver_i* GetDriver(const SALOMEDSImpl_SObject& theObject, CORBA::ORB_ptr orb); -static PortableServer::POA_ptr _poa; +static PortableServer::POA_var _poa; +static SALOMEDS::Study_var _study; /** * Return a unique study obj but servant is embeded here. @@ -72,17 +73,36 @@ static PortableServer::POA_ptr _poa; */ SALOMEDS::Study_ptr KERNEL::getStudyServantSA() { - static SALOMEDS::Study_ptr aStudy; - if(CORBA::is_nil(aStudy)) + + if(CORBA::is_nil(_study)) { CORBA::ORB_ptr orb = KERNEL::getORB(); CORBA::Object_var obj = orb->resolve_initial_references("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow(obj); _poa = PortableServer::POA::_duplicate(poa); SALOMEDS_Study_i *servant = new SALOMEDS_Study_i(orb,SALOME::Session::_nil()); - aStudy = servant->_this(); + _study = servant->_this(); + } + return SALOMEDS::Study::_duplicate(_study); +} + +/** + * If a study is already built and activated elsewhere (for example in GUI context) + */ +void KERNEL::setStudyServantSA(SALOMEDS::Study_var study, PortableServer::POA_var poa) +{ + if( ! CORBA::is_nil(_study) ) + { + PortableServer::ServantBase *serv = nullptr; + try + { + serv = _poa->reference_to_servant(_study); + } + catch(...) { } + if(serv) + serv->_remove_ref(); } - return SALOMEDS::Study::_duplicate(aStudy); + _study = study; _poa = poa; } namespace SALOMEDS @@ -268,7 +288,7 @@ namespace SALOMEDS void sendMessageToGUI(const char* msg ) { - SALOME_NamingService *aNamingService = KERNEL::getNamingService(); + SALOME_NamingService_Abstract *aNamingService = KERNEL::getNamingService(); CORBA::Object_var obj = aNamingService->Resolve("/Kernel/Session"); SALOME::Session_var aSession = SALOME::Session::_narrow(obj); sendMessageToGUIGivenSession(aSession,msg); @@ -276,13 +296,13 @@ namespace SALOMEDS } // namespace SALOMEDS -SALOMEDS_Study_i::SALOMEDS_Study_i(CORBA::ORB_ptr orb) +SALOMEDS_Study_i::SALOMEDS_Study_i(CORBA::ORB_ptr orb, SALOME_NamingService_Abstract *ns) { + SALOME_NamingService_Abstract *aNamingService = ns==nullptr?KERNEL::getNamingService():ns; _orb = CORBA::ORB::_duplicate(orb); _impl = new SALOMEDSImpl_Study(); - _factory = new SALOMEDS_DriverFactory_i(_orb); + _factory = new SALOMEDS_DriverFactory_i(_orb,aNamingService); _closed = true; - SALOME_NamingService *aNamingService = KERNEL::getNamingService(); CORBA::Object_var obj = aNamingService->Resolve("/Kernel/Session"); SALOME::Session_var aSession = SALOME::Session::_narrow(obj); Init(aSession); @@ -317,7 +337,7 @@ SALOMEDS_Study_i::~SALOMEDS_Study_i() void SALOMEDS_Study_i::Init() { - SALOME_NamingService *aNamingService = KERNEL::getNamingService(); + SALOME_NamingService_Abstract *aNamingService = KERNEL::getNamingService(); CORBA::Object_var obj = aNamingService->Resolve("/Kernel/Session"); SALOME::Session_var aSession = SALOME::Session::_narrow(obj); Init(aSession); @@ -1027,7 +1047,7 @@ void SALOMEDS_Study_i::URL(const wchar_t* wurl) _impl->URL(Kernel_Utils::encode_s(wurl)); // update desktop title with new study name - SALOME_NamingService *aNamingService = KERNEL::getNamingService(); + SALOME_NamingService_Abstract *aNamingService = KERNEL::getNamingService(); CORBA::Object_var obj = aNamingService->Resolve("/Kernel/Session"); SALOME::Session_var aSession = SALOME::Session::_narrow(obj); NameChanged(aSession); diff --git a/src/SALOMEDS/SALOMEDS_Study_i.hxx b/src/SALOMEDS/SALOMEDS_Study_i.hxx index 36d0ef962..37a44de5f 100644 --- a/src/SALOMEDS/SALOMEDS_Study_i.hxx +++ b/src/SALOMEDS/SALOMEDS_Study_i.hxx @@ -46,9 +46,12 @@ #include "SALOMEDSImpl_Study.hxx" #include "SALOMEDSImpl_AttributeIOR.hxx" +class SALOME_NamingService_Abstract; + namespace KERNEL { Standard_EXPORT SALOMEDS::Study_ptr getStudyServantSA(); + Standard_EXPORT void setStudyServantSA(SALOMEDS::Study_var study, PortableServer::POA_var poa); } class Standard_EXPORT SALOMEDS_Study_i: public POA_SALOMEDS::Study @@ -66,7 +69,7 @@ private: public: //! standard constructor - SALOMEDS_Study_i(CORBA::ORB_ptr); + SALOMEDS_Study_i(CORBA::ORB_ptr, SALOME_NamingService_Abstract * = nullptr); //! standard constructor SALOMEDS_Study_i(CORBA::ORB_ptr, SALOME::Session_ptr session); diff --git a/src/SALOMEDSClient/SALOMEDSClient_ClientFactory.cxx b/src/SALOMEDSClient/SALOMEDSClient_ClientFactory.cxx index 2edcbdf5c..ca89d0be4 100644 --- a/src/SALOMEDSClient/SALOMEDSClient_ClientFactory.cxx +++ b/src/SALOMEDSClient/SALOMEDSClient_ClientFactory.cxx @@ -40,14 +40,15 @@ static void* _libHandle = NULL; #endif #endif -#define SOBJECT_FACTORY "SObjectFactory" -#define SCOMPONENT_FACTORY "SComponentFactory" -#define STUDY_FACTORY "StudyFactory" -#define STUDY_CREATE "CreateStudy" -#define BUILDER_FACTORY "BuilderFactory" -#define GET_PARAMETERS "GetIParameters" -#define CONVERT_SOBJECT "ConvertSObject" -#define CONVERT_BUILDER "ConvertBuilder" +#define SOBJECT_FACTORY "SObjectFactory" +#define SCOMPONENT_FACTORY "SComponentFactory" +#define STUDY_FACTORY "StudyFactory" +#define STUDY_CREATE "CreateStudy" +#define STUDY_CREATE_WITHOUT_NS "CreateStudyWithoutNS" +#define BUILDER_FACTORY "BuilderFactory" +#define GET_PARAMETERS "GetIParameters" +#define CONVERT_SOBJECT "ConvertSObject" +#define CONVERT_BUILDER "ConvertBuilder" typedef SALOMEDSClient_SObject* (*SOBJECT_FACTORY_FUNCTION) (SALOMEDS::SObject_ptr); typedef SALOMEDSClient_SComponent* (*SCOMPONENT_FACTORY_FUNCTION) (SALOMEDS::SComponent_ptr); @@ -129,6 +130,19 @@ void ClientFactory::createStudy(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa) if(aCreateFactory) aCreateFactory(orb, poa); } +void ClientFactory::createStudyWithoutNS(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa) +{ +#ifdef WIN32 + if(!_libHandle) _libHandle = ::LoadLibrary(SALOMEDS_LIB_NAME); + if(!aCreateFactory) aCreateFactory = (STUDY_CREATE_FUNCTION)::GetProcAddress(_libHandle, STUDY_CREATE_WITHOUT_NS); +#else + if(!_libHandle) _libHandle = dlopen(SALOMEDS_LIB_NAME, RTLD_LAZY | RTLD_GLOBAL); + if(!aCreateFactory) aCreateFactory = (STUDY_CREATE_FUNCTION) dlsym(_libHandle, STUDY_CREATE_WITHOUT_NS); +#endif + + if(aCreateFactory) aCreateFactory(orb, poa); +} + _PTR(StudyBuilder) ClientFactory::StudyBuilder(SALOMEDS::StudyBuilder_ptr theStudyBuilder) { SALOMEDSClient_StudyBuilder* studyBuilder = NULL; diff --git a/src/SALOMEDSClient/SALOMEDSClient_ClientFactory.hxx b/src/SALOMEDSClient/SALOMEDSClient_ClientFactory.hxx index 6aa8d501a..9775b018c 100644 --- a/src/SALOMEDSClient/SALOMEDSClient_ClientFactory.hxx +++ b/src/SALOMEDSClient/SALOMEDSClient_ClientFactory.hxx @@ -62,6 +62,11 @@ public: * Creates and returns a client Study wrapper */ static void createStudy(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa); + + /*! + * Creates and returns a client Study wrapper without external NS process + */ + static void createStudyWithoutNS(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa); /*! * Returns a client StudyBuilder wrapper that corresponds %theStudy diff --git a/src/Utils/Utils_Identity.cxx b/src/Utils/Utils_Identity.cxx index 7747f5ce4..dbdcf4f10 100644 --- a/src/Utils/Utils_Identity.cxx +++ b/src/Utils/Utils_Identity.cxx @@ -29,11 +29,10 @@ # include # include "utilities.h" # include "Utils_Identity.hxx" +# include extern "C" { -# include - #ifndef WIN32 /* unix functionality */ # include #endif diff --git a/src/Utils/Utils_SALOME_Exception.cxx b/src/Utils/Utils_SALOME_Exception.cxx index 999afd652..99dcb283a 100644 --- a/src/Utils/Utils_SALOME_Exception.cxx +++ b/src/Utils/Utils_SALOME_Exception.cxx @@ -26,7 +26,6 @@ // Module : SALOME // $Header$ // -#include #include "Utils_SALOME_Exception.hxx" #include "utilities.h" @@ -41,82 +40,36 @@ extern "C" } #endif - -const char* duplicate( const char *const str ) ; - -SALOME_Exception::SALOME_Exception( void ): exception() , _text(0) +std::string makeText(const char *text, const char *fileName, const unsigned int lineNumber) { - MESSAGE( "You must use the standard builder: SALOME_Exception::SALOME_Exception( const char *text )" ) ; - INTERRUPTION(1) ; + constexpr char prefix[] = "Salome Exception"; + std::ostringstream oss; + if (fileName) + { + oss << prefix << " in " << fileName << "[" << lineNumber << "] : " << text; + } + else + { + oss << prefix << " : " << text; + } + return oss.str(); } - - -const char *makeText( const char *text, const char *fileName, const unsigned int lineNumber ) +SALOME_Exception::SALOME_Exception(const char *text, const char *fileName, const unsigned int lineNumber) : _text(makeText(text, fileName, lineNumber)) { - char *newText = 0 ; - - ASSERT(text) ; - const size_t l1 = 1+strlen(text) ; - ASSERT(l1>1) ; - - const char* prefix = "Salome Exception" ; - const size_t l0 = 2+strlen(prefix) ; - - if ( fileName ) - { - const size_t l2 = 4+strlen(fileName) ; - ASSERT(l2>4) ; - - ASSERT(lineNumber>=1) ; - const size_t l3 = 4+int(log10(float(lineNumber))) ; - - newText = new char [ 1+l0+l1+l2+l3 ] ; - sprintf( newText , "%s in %s [%u] : %s" , prefix, fileName, lineNumber, text ) ; - } - else - { - newText = new char [ 1+l0+l1 ] ; - sprintf( newText , "%s : %s" , prefix, text ) ; - } - ASSERT(newText) ; - return newText ; } - -SALOME_Exception::SALOME_Exception( const char *text, const char *fileName, const unsigned int lineNumber ) : exception(), _text( makeText( text , fileName , lineNumber ) ) -{ -} - - SALOME_Exception::~SALOME_Exception() noexcept { - if ( _text ) - { - delete [] ((char*)_text); - char** pRef = (char**)&_text; - *pRef = 0; - } - ASSERT(_text==NULL) ; -} - - - -SALOME_Exception::SALOME_Exception( const SALOME_Exception &ex ): _text(duplicate(ex._text)) -{ - ; } - -std::ostream & operator<<( std::ostream &os , const SALOME_Exception &ex ) +std::ostream &operator<<(std::ostream &os, const SALOME_Exception &ex) { - os << ex._text ; - return os ; + os << ex._text; + return os; } - - -const char* SALOME_Exception::what( void ) const noexcept +const char *SALOME_Exception::what(void) const noexcept { - return _text ; + return _text.c_str(); } diff --git a/src/Utils/Utils_SALOME_Exception.hxx b/src/Utils/Utils_SALOME_Exception.hxx index d4d94d568..6c69e83bf 100644 --- a/src/Utils/Utils_SALOME_Exception.hxx +++ b/src/Utils/Utils_SALOME_Exception.hxx @@ -26,60 +26,57 @@ // Module : SALOME // $Header$ // -#if !defined( __Utils_SALOME_Exception_hxx__ ) -#define __Utils_SALOME_Exception_hxx__ +#pragma once -//#include "SALOME_Utils.hxx" - -# include -# include +#include +#include +#include #ifdef LOCALIZED #undef LOCALIZED #endif #if defined(_DEBUG_) || defined(_DEBUG) -# define LOCALIZED(message) #message , __FILE__ , __LINE__ +#define LOCALIZED(message) #message, __FILE__, __LINE__ #else -# define LOCALIZED(message) #message +#define LOCALIZED(message) #message #endif //swig tool on Linux doesn't pass defines from header SALOME_Utils.hxx //therefore (temporary solution) defines are placed below #ifdef WIN32 -# if defined UTILS_EXPORTS || defined OpUtil_EXPORTS -# define UTILS_EXPORT __declspec( dllexport ) -# else -# define UTILS_EXPORT __declspec( dllimport ) -# undef LOCALIZED -# define LOCALIZED(message) #message -# endif +#if defined UTILS_EXPORTS || defined OpUtil_EXPORTS +#define UTILS_EXPORT __declspec(dllexport) +#else +#define UTILS_EXPORT __declspec(dllimport) +#undef LOCALIZED +#define LOCALIZED(message) #message +#endif #else -# define UTILS_EXPORT +#define UTILS_EXPORT #endif class SALOME_Exception; -UTILS_EXPORT std::ostream& operator<<( std::ostream&, const SALOME_Exception& ); +UTILS_EXPORT std::ostream &operator<<(std::ostream &, const SALOME_Exception &); -UTILS_EXPORT const char *makeText( const char *text, const char *fileName, const unsigned int lineNumber ); +UTILS_EXPORT std::string makeText(const char *text, const char *fileName, const unsigned int lineNumber); class UTILS_EXPORT SALOME_Exception : public std::exception { +protected: + std::string _text; +public: + SALOME_Exception() = delete; + SALOME_Exception(const std::string& text):_text(text) { } + SALOME_Exception(const char *text, const char *fileName = nullptr, const unsigned int lineNumber = 0); + virtual ~SALOME_Exception() noexcept; + UTILS_EXPORT friend std::ostream &operator<<(std::ostream &os, const SALOME_Exception &ex); + virtual const char *what(void) const noexcept; +}; -private : - SALOME_Exception( void ); - -protected : - const char* _text ; // non constant pointer but read only char variable - -public : - SALOME_Exception( const char *text, const char *fileName=0, const unsigned int lineNumber=0 ); - SALOME_Exception( const SALOME_Exception &ex ); - virtual ~SALOME_Exception() noexcept; - UTILS_EXPORT friend std::ostream & operator<<( std::ostream &os , const SALOME_Exception &ex ); - virtual const char *what( void ) const noexcept; -} ; - - -#endif /* #if !defined( __Utils_SALOME_Exception_hxx__ ) */ +#define THROW_SALOME_EXCEPTION(text) \ +{ \ + std::ostringstream oss; oss << text; \ + throw SALOME_Exception(oss.str()); \ +}