From 9bae342a6076b831c40d4170d59222afc6ec4b9e Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Fri, 5 Jan 2018 15:23:58 +0100 Subject: [PATCH] Go on for RequestSwitcher conquest --- idl/SALOME_SDS.idl | 8 ++- src/Launcher/SALOME_LauncherServer.cxx | 15 +++++- src/SALOMESDS/CMakeLists.txt | 1 + src/SALOMESDS/SALOMESDS_DataScopeServer.cxx | 28 +--------- src/SALOMESDS/SALOMESDS_DataScopeServer.hxx | 10 ++-- src/SALOMESDS/SALOMESDS_DataServerManager.cxx | 13 +++++ src/SALOMESDS/SALOMESDS_DataServerManager.hxx | 2 + src/SALOMESDS/SALOMESDS_RequestSwitcher.cxx | 53 +++++++++++++++++++ src/SALOMESDS/SALOMESDS_RequestSwitcher.hxx | 48 +++++++++++++++++ 9 files changed, 140 insertions(+), 38 deletions(-) create mode 100644 src/SALOMESDS/SALOMESDS_RequestSwitcher.cxx create mode 100644 src/SALOMESDS/SALOMESDS_RequestSwitcher.hxx diff --git a/idl/SALOME_SDS.idl b/idl/SALOME_SDS.idl index 07950bd6e..82f6c2dcf 100644 --- a/idl/SALOME_SDS.idl +++ b/idl/SALOME_SDS.idl @@ -71,11 +71,15 @@ module SALOME { void shutdown(); }; - - interface RequestSwitcher + + interface RequestSwitcherBase { void holdRequests(); void activeRequests(); + }; + + interface RequestSwitcher : RequestSwitcherBase + { StringVec listVars(); ByteVec fetchSerializedContent(in string varName) raises (SALOME::SALOME_Exception); }; diff --git a/src/Launcher/SALOME_LauncherServer.cxx b/src/Launcher/SALOME_LauncherServer.cxx index a82d90050..e7da460f6 100644 --- a/src/Launcher/SALOME_LauncherServer.cxx +++ b/src/Launcher/SALOME_LauncherServer.cxx @@ -76,8 +76,19 @@ int main(int argc, char* argv[]) PortableServer::POA_var root_poa; PortableServer::POAManager_var pman; CORBA::Object_var obj; - - CORBA::ORB_var orb = CORBA::ORB_init( argc , argv ) ; + CORBA::ORB_var orb; + { + int myArgc(argc+2); + char **myArgv(new char *[myArgc]); + for(int i=0;ishutdown(0); } -RequestSwitcher::RequestSwitcher(CORBA::ORB_ptr orb, DataScopeServerBase *ds):_ds(ds) +RequestSwitcher::RequestSwitcher(CORBA::ORB_ptr orb, DataScopeServerBase *ds):RequestSwitcherBase(orb),_ds(ds) { - CORBA::Object_var obj(orb->resolve_initial_references("RootPOA")); - PortableServer::POA_var poa(PortableServer::POA::_narrow(obj)); - _poa_manager_under_control=poa->the_POAManager(); - // - CORBA::PolicyList policies; - policies.length(1); - PortableServer::ThreadPolicy_var threadPol(poa->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL)); - policies[0]=PortableServer::ThreadPolicy::_duplicate(threadPol); - // all is in PortableServer::POAManager::_nil. By specifying _nil cf Advanced CORBA Programming with C++ p 506 - // a new POA manager is created. This POA manager is independent from POA manager of the son ones. - _poa_for_request_control=poa->create_POA("4RqstSwitcher",PortableServer::POAManager::_nil(),policies); - threadPol->destroy(); - PortableServer::POAManager_var mgr(_poa_for_request_control->the_POAManager()); - mgr->activate(); - //obj=orb->resolve_initial_references ("POACurrent");// agy : usage of POACurrent breaks the hold_requests. Why ? - //PortableServer::Current_var current(PortableServer::Current::_narrow(obj)); -} - -void RequestSwitcher::holdRequests() -{ - _poa_manager_under_control->hold_requests(true); -} - -void RequestSwitcher::activeRequests() -{ - _poa_manager_under_control->activate(); } SALOME::StringVec *RequestSwitcher::listVars() diff --git a/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx b/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx index 64eb544c9..05468fc08 100644 --- a/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx +++ b/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx @@ -24,6 +24,7 @@ #include "SALOMEconfig.h" #include CORBA_SERVER_HEADER(SALOME_SDS) +#include "SALOMESDS_RequestSwitcher.hxx" #include "SALOMESDS_RefCountServ.hxx" #include "SALOMESDS_AutoRefCountPtr.hxx" #include "SALOMESDS_BasicDataServer.hxx" @@ -47,23 +48,18 @@ namespace SALOMESDS }; class DataScopeServerBase; - + /*! * Servant activated by a specific POA (single thread) having itself its specific POA_manager. * This class is able to hold/active the default POA_manager shared by other POA than this. */ - class SALOMESDS_EXPORT RequestSwitcher : public POA_SALOME::RequestSwitcher, public POAHolder + class SALOMESDS_EXPORT RequestSwitcher : public RequestSwitcherBase, public virtual POA_SALOME::RequestSwitcher { public: RequestSwitcher(CORBA::ORB_ptr orb, DataScopeServerBase *ds); - void holdRequests(); - void activeRequests(); SALOME::StringVec *listVars(); SALOME::ByteVec *fetchSerializedContent(const char *varName); - PortableServer::POA_var getPOA() const { return _poa_for_request_control; } private: - PortableServer::POA_var _poa_for_request_control; - PortableServer::POAManager_var _poa_manager_under_control; //! handle on its creator to give access to services when _poa_manager_under_control is in hold mode. DataScopeServerBase *_ds; }; diff --git a/src/SALOMESDS/SALOMESDS_DataServerManager.cxx b/src/SALOMESDS/SALOMESDS_DataServerManager.cxx index 8296ba8f2..a613a3a7d 100644 --- a/src/SALOMESDS/SALOMESDS_DataServerManager.cxx +++ b/src/SALOMESDS/SALOMESDS_DataServerManager.cxx @@ -43,6 +43,19 @@ DataServerManager::DataServerManager(int argc, char *argv[], CORBA::ORB_ptr orb, policies[0]=PortableServer::ThreadPolicy::_duplicate(threadPol); _poa=poa->create_POA("SingleThPOA4SDS",pman,policies); threadPol->destroy(); + //An another _poa_for_request_control to give to my boss the pure power + { + CORBA::PolicyList policies; + policies.length(1); + PortableServer::ThreadPolicy_var threadPol(poa->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL)); + policies[0]=PortableServer::ThreadPolicy::_duplicate(threadPol); + // all is in PortableServer::POAManager::_nil. By specifying _nil cf Advanced CORBA Programming with C++ p 506 + // a new POA manager is created. This POA manager is independent from POA manager of the son ones. + _poa_for_request_control=poa->create_POA("4RqstSwitcher",PortableServer::POAManager::_nil(),policies); + threadPol->destroy(); + PortableServer::POAManager_var mgr(_poa_for_request_control->the_POAManager()); + mgr->activate(); + } // dftScope->initializePython(argc,argv);// agy : Very important ! invoke this method BEFORE activation ! // activate this to be ready to be usable from NS. diff --git a/src/SALOMESDS/SALOMESDS_DataServerManager.hxx b/src/SALOMESDS/SALOMESDS_DataServerManager.hxx index 8d7a9da48..f476db082 100644 --- a/src/SALOMESDS/SALOMESDS_DataServerManager.hxx +++ b/src/SALOMESDS/SALOMESDS_DataServerManager.hxx @@ -71,6 +71,8 @@ namespace SALOMESDS CORBA::ORB_var _orb; //! single thread poa PortableServer::POA_var _poa; + //! single thread poa and with a specific poa_manager + PortableServer::POA_var _poa_for_request_control; }; } diff --git a/src/SALOMESDS/SALOMESDS_RequestSwitcher.cxx b/src/SALOMESDS/SALOMESDS_RequestSwitcher.cxx new file mode 100644 index 000000000..22edf72c4 --- /dev/null +++ b/src/SALOMESDS/SALOMESDS_RequestSwitcher.cxx @@ -0,0 +1,53 @@ +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// Author : Anthony GEAY (EDF R&D) + +#include "SALOMESDS_RequestSwitcher.hxx" + +using namespace SALOMESDS; + +RequestSwitcherBase::RequestSwitcherBase(CORBA::ORB_ptr orb) +{ + CORBA::Object_var obj(orb->resolve_initial_references("RootPOA")); + PortableServer::POA_var poa(PortableServer::POA::_narrow(obj)); + _poa_manager_under_control=poa->the_POAManager(); + // + CORBA::PolicyList policies; + policies.length(1); + PortableServer::ThreadPolicy_var threadPol(poa->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL)); + policies[0]=PortableServer::ThreadPolicy::_duplicate(threadPol); + // all is in PortableServer::POAManager::_nil. By specifying _nil cf Advanced CORBA Programming with C++ p 506 + // a new POA manager is created. This POA manager is independent from POA manager of the son ones. + _poa_for_request_control=poa->create_POA("4RqstSwitcher",PortableServer::POAManager::_nil(),policies); + threadPol->destroy(); + PortableServer::POAManager_var mgr(_poa_for_request_control->the_POAManager()); + mgr->activate(); + //obj=orb->resolve_initial_references ("POACurrent");// agy : usage of POACurrent breaks the hold_requests. Why ? + //PortableServer::Current_var current(PortableServer::Current::_narrow(obj)); +} + +void RequestSwitcherBase::holdRequests() +{ + _poa_manager_under_control->hold_requests(true); +} + +void RequestSwitcherBase::activeRequests() +{ + _poa_manager_under_control->activate(); +} diff --git a/src/SALOMESDS/SALOMESDS_RequestSwitcher.hxx b/src/SALOMESDS/SALOMESDS_RequestSwitcher.hxx new file mode 100644 index 000000000..1cb7410ab --- /dev/null +++ b/src/SALOMESDS/SALOMESDS_RequestSwitcher.hxx @@ -0,0 +1,48 @@ +// Copyright (C) 2018 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// Author : Anthony GEAY (EDF R&D) + +#ifndef __SALOMESDS_REQUESTSWITCHER_HXX__ +#define __SALOMESDS_REQUESTSWITCHER_HXX__ + +#include "SALOMEconfig.h" +#include CORBA_SERVER_HEADER(SALOME_SDS) +#include "SALOMESDS_AutoRefCountPtr.hxx" +#include "SALOMESDS_Defines.hxx" + +namespace SALOMESDS +{ + /*! + * Servant activated by a specific POA (single thread) having itself its specific POA_manager. + * This class is able to hold/active the default POA_manager shared by other POA than this. + */ + class SALOMESDS_EXPORT RequestSwitcherBase : public virtual POA_SALOME::RequestSwitcherBase, public POAHolder + { + public: + RequestSwitcherBase(CORBA::ORB_ptr orb); + void holdRequests(); + void activeRequests(); + PortableServer::POA_var getPOA() const { return _poa_for_request_control; } + private: + PortableServer::POA_var _poa_for_request_control; + PortableServer::POAManager_var _poa_manager_under_control; + }; +} + +#endif -- 2.39.2