]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Impl of mechanism into SDS of switcher hold/reactive requests
authorAnthony Geay <anthony.geay@edf.fr>
Fri, 10 Nov 2017 08:29:32 +0000 (09:29 +0100)
committerCédric Aguerre <cedric.aguerre@edf.fr>
Tue, 23 Jan 2018 15:48:09 +0000 (16:48 +0100)
idl/SALOME_SDS.idl
src/SALOMESDS/SALOMESDS_AutoRefCountPtr.hxx
src/SALOMESDS/SALOMESDS_DataScopeServer.cxx
src/SALOMESDS/SALOMESDS_DataScopeServer.hxx

index 24a707899834134cafc34785a708af7eba591f74..2f0f26ed67d7994c92203b8363ef1a806671e4b8 100644 (file)
@@ -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
index e56aba80fe8d5b2c45b9bf0fe95379e345b9fb2d..8cdad8fc64aa778ac5648a0343747aa8024c6335 100644 (file)
@@ -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()
     {
index ac4772586dec68428acb06ac9583db8891904918..62d45fb0deaf4a643d52cdc4fece2abcb2ecd983 100644 (file)
@@ -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();
index c814dd3ec18242247e7505f81d4d6bf7627fac37..e06ec8b22932132fa0eb7fd36f098bc9a7829d6e 100644 (file)
@@ -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<RequestSwitcher> _rs;
     static std::size_t COUNTER;
   };