From: Anthony GEAY Date: Fri, 19 Feb 2021 13:46:40 +0000 (+0100) Subject: OK for container_i servant X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4ab9a86cc7e6065dd9335a1230fcf22848559a4a;p=modules%2Fgui.git OK for container_i servant --- diff --git a/src/Session/CMakeLists.txt b/src/Session/CMakeLists.txt index 77038452f..5a783b508 100644 --- a/src/Session/CMakeLists.txt +++ b/src/Session/CMakeLists.txt @@ -82,6 +82,7 @@ SET(SalomeSession_HEADERS Session_ServerThread.hxx Session_Session_i.hxx Session_Promises.hxx + Session_NS_wrapper.hxx ) # --- resources --- @@ -100,6 +101,7 @@ SET(SalomeSession_SOURCES Session_ServerThread.cxx Session_Session_i.cxx Session_Promises.cxx + Session_NS_wrapper.cxx ) # --- rules --- diff --git a/src/Session/SALOME_Session_Server.cxx b/src/Session/SALOME_Session_Server.cxx index 464f68e1f..4b7d802d0 100644 --- a/src/Session/SALOME_Session_Server.cxx +++ b/src/Session/SALOME_Session_Server.cxx @@ -38,7 +38,7 @@ #include "Session_ServerCheck.hxx" #include "Session_ServerLauncher.hxx" #include "Session_Promises.hxx" -#include "SALOME_Fake_NamingService.hxx" +#include "Session_NS_wrapper.hxx" #include "GUI_version.h" #include "Qtx.h" @@ -459,7 +459,7 @@ SALOME::Session_var GUIAppNewStyle::getSession() // ---------------------------- MAIN ----------------------- int AbstractGUIApp::main(int argc, char **argv) { - using NamingServiceImplementation = SALOME_Fake_NamingService; + using NamingServiceImplementation = NewStyleNS; // Set-up application settings configuration (as for QSettings) // Note: these are default settings which can be customized (see below) QApplication::setOrganizationName("salome"); diff --git a/src/Session/Session_NS_wrapper.cxx b/src/Session/Session_NS_wrapper.cxx new file mode 100644 index 000000000..b65708db0 --- /dev/null +++ b/src/Session/Session_NS_wrapper.cxx @@ -0,0 +1,109 @@ +// 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 "Session_NS_wrapper.hxx" + +#include "SALOME_Container_i.hxx" +#include "utilities.h" + +Engines_Container_i *OldStyleNS::activateContainer(CORBA::ORB_var orb, PortableServer::POA_var poa, int argc, char **argv) +{ + Engines_Container_i *_container = nullptr; + try + { + MESSAGE("Container thread started"); + + // get or create the child POA + + PortableServer::POA_var factory_poa; + try + { + factory_poa = poa->find_POA("factory_poa", 0); + // 0 = no activation (already done if exists) + } + catch (PortableServer::POA::AdapterNonExistent &) + { + MESSAGE("factory_poa does not exists, create..."); + // define policy objects + PortableServer::ImplicitActivationPolicy_var implicitActivation = + poa->create_implicit_activation_policy(PortableServer::NO_IMPLICIT_ACTIVATION); + // default = NO_IMPLICIT_ACTIVATION + PortableServer::ThreadPolicy_var threadPolicy = + poa->create_thread_policy(PortableServer::ORB_CTRL_MODEL); + // default = ORB_CTRL_MODEL, other choice SINGLE_THREAD_MODEL + + // create policy list + CORBA::PolicyList policyList; + policyList.length(2); + policyList[0] = PortableServer::ImplicitActivationPolicy:: + _duplicate(implicitActivation); + policyList[1] = PortableServer::ThreadPolicy:: + _duplicate(threadPolicy); + + PortableServer::POAManager_var nil_mgr = PortableServer::POAManager::_nil(); + factory_poa = poa->create_POA("factory_poa", + nil_mgr, + policyList); + //with nil_mgr instead of pman, + //a new POA manager is created with the new POA + + // destroy policy objects + implicitActivation->destroy(); + threadPolicy->destroy(); + + // obtain the factory poa manager + PortableServer::POAManager_var pmanfac = factory_poa->the_POAManager(); + pmanfac->activate(); + MESSAGE("pmanfac->activate()"); + } + + char *containerName = (char *)""; + if (argc > 1) + { + containerName = argv[1]; + } + _container = new Engines_Container_i(orb, poa, containerName, argc, argv, true, false); + } + catch (CORBA::SystemException &) + { + INFOS("Caught CORBA::SystemException."); + } + catch (PortableServer::POA::WrongPolicy &) + { + INFOS("Caught CORBA::WrongPolicyException."); + } + catch (PortableServer::POA::ServantAlreadyActive &) + { + INFOS("Caught CORBA::ServantAlreadyActiveException"); + } + catch (CORBA::Exception &) + { + INFOS("Caught CORBA::Exception."); + } + catch (...) + { + INFOS("Caught unknown exception."); + } + return _container; +} + +Engines_Container_i *NewStyleNS::activateContainer(CORBA::ORB_var orb, PortableServer::POA_var poa, int argc, char **argv) +{ + return KERNEL::getContainerSA(); +} diff --git a/src/Session/Session_NS_wrapper.hxx b/src/Session/Session_NS_wrapper.hxx new file mode 100644 index 000000000..44fccdf51 --- /dev/null +++ b/src/Session/Session_NS_wrapper.hxx @@ -0,0 +1,56 @@ +// 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.hxx" + +#include "omniORB4/CORBA.h" + +class Engines_Container_i; + +class OldStyleNS +{ +public: + using RealNS = SALOME_NamingService; +public: + OldStyleNS(CORBA::ORB_ptr orb):_NS(orb) {} + void Register(CORBA::Object_ptr ObjRef, const char* Path) { _NS.Register(ObjRef,Path); } + CORBA::Object_ptr Resolve(const char* Path) { return _NS.Resolve(Path); } + RealNS *getNS() { return &_NS; } + Engines_Container_i *activateContainer(CORBA::ORB_var orb, PortableServer::POA_var poa, int argc, char** argv); +private: + RealNS _NS; +}; + +#include "SALOME_Fake_NamingService.hxx" + +class NewStyleNS +{ +public: + using RealNS = SALOME_Fake_NamingService; +public: + NewStyleNS(CORBA::ORB_ptr orb):_NS(orb) {} + void Register(CORBA::Object_ptr ObjRef, const char* Path) { _NS.Register(ObjRef,Path); } + CORBA::Object_ptr Resolve(const char* Path) { return _NS.Resolve(Path); } + RealNS *getNS() { return &_NS; } + Engines_Container_i *activateContainer(CORBA::ORB_var orb, PortableServer::POA_var poa, int argc, char** argv); +private: + RealNS _NS; +}; diff --git a/src/Session/Session_ServerLauncher.cxx b/src/Session/Session_ServerLauncher.cxx index 730e7f089..73ed5b118 100644 --- a/src/Session/Session_ServerLauncher.cxx +++ b/src/Session/Session_ServerLauncher.cxx @@ -262,8 +262,8 @@ void Session_ServerLauncher::KillAll() } } -template class Session_ServerLauncher; +#include "Session_NS_wrapper.hxx" -#include "SALOME_Fake_NamingService.hxx" +template class Session_ServerLauncher; -template class Session_ServerLauncher; +template class Session_ServerLauncher; diff --git a/src/Session/Session_ServerThread.cxx b/src/Session/Session_ServerThread.cxx index fc1d2ac91..e1effb791 100644 --- a/src/Session/Session_ServerThread.cxx +++ b/src/Session/Session_ServerThread.cxx @@ -123,42 +123,42 @@ void Session_ServerThread::Init() switch (_servType) { case 0: // Container { - NamingService_WaitForServerReadiness(_NS.get(),"/Registry"); - NamingService_WaitForServerReadiness(_NS.get(),"/ContainerManager"); + NamingService_WaitForServerReadiness(this->getNS(),"/Registry"); + NamingService_WaitForServerReadiness(this->getNS(),"/ContainerManager"); ActivateContainer(_argc, _argv); break; } case 1: // ModuleCatalog { - NamingService_WaitForServerReadiness(_NS.get(),"/Registry"); + NamingService_WaitForServerReadiness(this->getNS(),"/Registry"); ActivateModuleCatalog(_argc, _argv); break; } case 2: // Registry { - NamingService_WaitForServerReadiness(_NS.get(),""); + NamingService_WaitForServerReadiness(this->getNS(),""); ActivateRegistry(_argc, _argv); break; } case 3: // SALOMEDS { - NamingService_WaitForServerReadiness(_NS.get(),"/Kernel/ModulCatalog"); + NamingService_WaitForServerReadiness(this->getNS(),"/Kernel/ModulCatalog"); ActivateSALOMEDS(_argc, _argv); break; } case 4: // Session { - NamingService_WaitForServerReadiness(_NS.get(),"/Study"); + NamingService_WaitForServerReadiness(this->getNS(),"/Study"); std::string containerName = "/Containers/"; containerName = containerName + Kernel_Utils::GetHostname(); containerName = containerName + "/FactoryServer"; - NamingService_WaitForServerReadiness(_NS.get(),containerName); + NamingService_WaitForServerReadiness(this->getNS(),containerName); ActivateSession(_argc, _argv); break; } case 5: // Container Manager { - NamingService_WaitForServerReadiness(_NS.get(),""); + NamingService_WaitForServerReadiness(this->getNS(),""); ActivateContainerManager(_argc, _argv); break; } @@ -325,77 +325,19 @@ void Session_ServerThread::ActivateContainerManager(int /*argc*/, char** } } +template +typename MY_NS::RealNS *Session_ServerThread::getNS() +{ + MY_NS *pt(_NS.get()); + if(!pt) + THROW_SALOME_EXCEPTION("Session_ServerThread::getNS : null pointer !"); + return pt->getNS(); +} + template void Session_ServerThread::ActivateContainer(int argc, char** argv) { - try { - MESSAGE("Container thread started"); - - // get or create the child POA - - PortableServer::POA_var factory_poa; - try { - factory_poa = _root_poa->find_POA("factory_poa",0); - // 0 = no activation (already done if exists) - } - catch (PortableServer::POA::AdapterNonExistent&) { - MESSAGE("factory_poa does not exists, create..."); - // define policy objects - PortableServer::ImplicitActivationPolicy_var implicitActivation = - _root_poa->create_implicit_activation_policy(PortableServer::NO_IMPLICIT_ACTIVATION); - // default = NO_IMPLICIT_ACTIVATION - PortableServer::ThreadPolicy_var threadPolicy = - _root_poa->create_thread_policy(PortableServer::ORB_CTRL_MODEL); - // default = ORB_CTRL_MODEL, other choice SINGLE_THREAD_MODEL - - // create policy list - CORBA::PolicyList policyList; - policyList.length(2); - policyList[0] = PortableServer::ImplicitActivationPolicy:: - _duplicate(implicitActivation); - policyList[1] = PortableServer::ThreadPolicy:: - _duplicate(threadPolicy); - - PortableServer::POAManager_var nil_mgr - = PortableServer::POAManager::_nil(); - factory_poa = _root_poa->create_POA("factory_poa", - nil_mgr, - policyList); - //with nil_mgr instead of pman, - //a new POA manager is created with the new POA - - // destroy policy objects - implicitActivation->destroy(); - threadPolicy->destroy(); - - // obtain the factory poa manager - PortableServer::POAManager_var pmanfac = factory_poa->the_POAManager(); - pmanfac->activate(); - MESSAGE("pmanfac->activate()"); - } - - char *containerName = (char*)""; - if (argc >1) { - containerName = argv[1]; - } - - _container = new Engines_Container_i(_orb, _root_poa, containerName, argc, argv, true, false); - } - catch(CORBA::SystemException&) { - INFOS("Caught CORBA::SystemException."); - } - catch(PortableServer::POA::WrongPolicy&) { - INFOS("Caught CORBA::WrongPolicyException."); - } - catch(PortableServer::POA::ServantAlreadyActive&) { - INFOS("Caught CORBA::ServantAlreadyActiveException"); - } - catch(CORBA::Exception&) { - INFOS("Caught CORBA::Exception."); - } - catch(...) { - INFOS("Caught unknown exception."); - } + _container = this->_NS->activateContainer(this->_orb,this->_root_poa,argc,argv); } template @@ -452,10 +394,8 @@ void Session_SessionThread::ActivateSession(int argc, char ** argv) } } -template class Session_ServerThread; -template class Session_SessionThread; - -#include "SALOME_Fake_NamingService.hxx" +template class Session_ServerThread; +template class Session_SessionThread; -template class Session_ServerThread; -template class Session_SessionThread; +template class Session_ServerThread; +template class Session_SessionThread; diff --git a/src/Session/Session_ServerThread.hxx b/src/Session/Session_ServerThread.hxx index 1df729038..a10aca6dc 100644 --- a/src/Session/Session_ServerThread.hxx +++ b/src/Session/Session_ServerThread.hxx @@ -27,6 +27,7 @@ #ifndef _SESSION_SERVERTHREAD_HXX_ #define _SESSION_SERVERTHREAD_HXX_ +#include "Session_NS_wrapper.hxx" #include "SALOME_Session.hxx" #include @@ -41,6 +42,8 @@ class Engines_Container_i; template class SESSION_EXPORT Session_ServerThread { +public: + using RealNS = typename MY_NS::RealNS; public: static const int NB_SRV_TYP; static const char* _serverTypes[]; @@ -61,13 +64,14 @@ protected: virtual void ActivateSession ( int argc, char ** argv ); void ActivateEngine ( int argc, char ** argv ); void ActivateContainerManager( int argc, char ** argv ); + RealNS *getNS(); protected: int _argc; char ** _argv; int _servType; CORBA::ORB_var _orb; PortableServer::POA_var _root_poa; - std::unique_ptr _NS; + std::unique_ptr _NS; Engines_Container_i* _container; };