From cf7d2bd88cff476f326dff4099b698aa11db5269 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Fri, 10 Nov 2017 09:29:32 +0100 Subject: [PATCH] Impl of mechanism into SDS of switcher hold/reactive requests --- idl/SALOME_SDS.idl | 7 ++++ src/SALOMESDS/SALOMESDS_AutoRefCountPtr.hxx | 1 + src/SALOMESDS/SALOMESDS_DataScopeServer.cxx | 38 +++++++++++++++++++++ src/SALOMESDS/SALOMESDS_DataScopeServer.hxx | 17 ++++++++- 4 files changed, 62 insertions(+), 1 deletion(-) diff --git a/idl/SALOME_SDS.idl b/idl/SALOME_SDS.idl index 24a707899..2f0f26ed6 100644 --- a/idl/SALOME_SDS.idl +++ b/idl/SALOME_SDS.idl @@ -71,6 +71,12 @@ module SALOME { void shutdown(); }; + + interface RequestSwitcher + { + void holdRequests(); + void activeRequests(); + }; interface DataScopeServerBase { @@ -82,6 +88,7 @@ module SALOME boolean shutdownIfNotHostedByDSM(out DataScopeKiller killer) raises (SALOME::SALOME_Exception); ByteVec fetchSerializedContent(in string varName) raises (SALOME::SALOME_Exception); SeqOfByteVec getAllKeysOfVarWithTypeDict(in string varName) raises (SALOME::SALOME_Exception); + RequestSwitcher getRequestSwitcher(); }; interface DataScopeServer : DataScopeServerBase diff --git a/src/SALOMESDS/SALOMESDS_AutoRefCountPtr.hxx b/src/SALOMESDS/SALOMESDS_AutoRefCountPtr.hxx index e56aba80f..8cdad8fc6 100644 --- a/src/SALOMESDS/SALOMESDS_AutoRefCountPtr.hxx +++ b/src/SALOMESDS/SALOMESDS_AutoRefCountPtr.hxx @@ -112,6 +112,7 @@ namespace SALOMESDS const T& operator*() const { return *_ptr; } operator T *() { return _ptr; } operator const T *() const { return _ptr; } + bool isNull() const { return _ptr==NULL; } private: void destroyPtr() { diff --git a/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx b/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx index ac4772586..62d45fb0d 100644 --- a/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx +++ b/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx @@ -52,6 +52,34 @@ void DataScopeKiller::shutdown() _orb->shutdown(0); } +RequestSwitcher::RequestSwitcher(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 independant 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(); +} + +void RequestSwitcher::holdRequests() +{ + _poa_manager_under_control->hold_requests(true); +} + +void RequestSwitcher::activeRequests() +{ + _poa_manager_under_control->activate(); +} + DataScopeServerBase::DataScopeServerBase(CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName):_globals(0),_locals(0),_pickler(0),_orb(CORBA::ORB::_duplicate(orb)),_name(scopeName),_killer(killer) { } @@ -226,6 +254,16 @@ SALOME::SeqOfByteVec *DataScopeServerBase::getAllKeysOfVarWithTypeDict(const cha return ret; } +SALOME::RequestSwitcher_ptr DataScopeServerBase::getRequestSwitcher() +{ + if(_rs.isNull()) + { + _rs=new RequestSwitcher(_orb); + } + CORBA::Object_var obj(_rs->activate()); + return SALOME::RequestSwitcher::_narrow(obj); +} + void DataScopeServerBase::initializePython(int argc, char *argv[]) { Py_Initialize(); diff --git a/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx b/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx index c814dd3ec..e06ec8b22 100644 --- a/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx +++ b/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx @@ -46,6 +46,18 @@ namespace SALOMESDS CORBA::ORB_var _orb; }; + class SALOMESDS_EXPORT RequestSwitcher : public POA_SALOME::RequestSwitcher, public POAHolder + { + public: + RequestSwitcher(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; + }; + class KeyWaiter; class PickelizedPyObjServer; @@ -54,6 +66,7 @@ namespace SALOMESDS public: DataScopeServerBase(CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName); DataScopeServerBase(const DataScopeServerBase& other); + public: // remote access methods void ping(); char *getScopeName(); SALOME::StringVec *listVars(); @@ -63,8 +76,9 @@ namespace SALOMESDS CORBA::Boolean shutdownIfNotHostedByDSM(SALOME::DataScopeKiller_out killer); SALOME::ByteVec *fetchSerializedContent(const char *varName); SALOME::SeqOfByteVec *getAllKeysOfVarWithTypeDict(const char *varName); - ~DataScopeServerBase(); + SALOME::RequestSwitcher_ptr getRequestSwitcher(); public: + ~DataScopeServerBase(); BasicDataServer *retrieveVarInternal2(const std::string& varName); void initializePython(int argc, char *argv[]); void registerToSalomePiDict() const; @@ -99,6 +113,7 @@ namespace SALOMESDS std::string _name; std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > > _vars; SALOME::DataScopeKiller_var _killer; + AutoServantPtr _rs; static std::size_t COUNTER; }; -- 2.39.2