]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
try0
authorAnthony Geay <anthony.geay@edf.fr>
Fri, 10 Jul 2015 15:06:58 +0000 (17:06 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Fri, 10 Jul 2015 15:06:58 +0000 (17:06 +0200)
src/SALOMESDS/SALOMESDS_AutoRefCountPtr.hxx
src/SALOMESDS/SALOMESDS_BasicDataServer.cxx
src/SALOMESDS/SALOMESDS_BasicDataServer.hxx
src/SALOMESDS/SALOMESDS_DataScopeServer.hxx
src/SALOMESDS/SALOMESDS_RefCountServ.cxx
src/SALOMESDS/SALOMESDS_RefCountServ.hxx
src/SALOMESDS/SALOMESDS_Transaction.cxx
src/SALOMESDS/SALOMESDS_Transaction.hxx
src/SALOMESDS/SALOMESDS_TransactionFactory.cxx
src/SALOMESDS/SALOMESDS_TransactionFactory.hxx

index 249829e86ec18d88d737b83a79684f79944d5ead..0d597978c33cfaae6cf6fb16c816c979a690d23a 100644 (file)
 
 namespace SALOMESDS
 {
-  class POAHolder
+  class POAHolder : public virtual PortableServer::ServantBase
   {
   public:
     virtual PortableServer::POA_var getPOA() const = 0;
+    void enforcedRelease()
+    {
+      PortableServer::POA_var poa(getPOA());
+      PortableServer::ObjectId_var oid(poa->servant_to_id(this));
+      poa->deactivate_object(oid);
+      _remove_ref();
+    }
   };
   
   template<class T>
@@ -86,7 +93,8 @@ namespace SALOMESDS
   class AutoServantPtr
   {
   public:
-    AutoServantPtr(T *ptr=0):_ptr(ptr) { }
+    AutoServantPtr(T *ptr=0):_ptr(ptr),_ph(0) { }
+    void setHolder(POAHolder *ph) { _ph=ph; }
     ~AutoServantPtr() { destroyPtr(); }
     bool operator==(const AutoServantPtr& other) const { return _ptr==other._ptr; }
     bool operator==(const T *other) const { return _ptr==other; }
@@ -98,9 +106,17 @@ namespace SALOMESDS
     operator T *() { return _ptr; }
     operator const T *() const { return _ptr; }
   private:
-    void destroyPtr() { if(!_ptr) return; }
+    void destroyPtr()
+    {
+      if(!_ptr)
+        return;
+      if(!_ph)
+        throw Exception("AutoServantPtr : null POA holder !");
+      _ph->enforcedRelease();
+    }
   private:
     T *_ptr;
+    POAHolder *_ph;
   };
 }
 
index 8b6ce446d487c5f1de18f189ec8fdc3403f2c62f..d0f102838b3d8438b5f5db84e7bde847037113ed 100644 (file)
 
 using namespace SALOMESDS;
 
+int BasicDataServer::POA_CNT=0;
+
 BasicDataServer::BasicDataServer(DataScopeServer *father, const std::string& varName):_father(father),_var_name(varName)
 {
+  PortableServer::POA_var poa(_father->getPOA());
+  PortableServer::POAManager_var pman(poa->the_POAManager());
+  CORBA::Object_var obj(_father->getORB()->resolve_initial_references("RootPOA"));
+  PortableServer::POA_var rootPOA(PortableServer::POA::_narrow(obj));
+  CORBA::PolicyList policies;
+  policies.length(1);
+  PortableServer::ThreadPolicy_var threadPol(rootPOA->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL));
+  policies[0]=PortableServer::ThreadPolicy::_duplicate(threadPol);
+  std::ostringstream poaName; poaName << "POA_" <<  POA_CNT++ << "_" << _var_name;
+  _poa=rootPOA->create_POA(poaName.str().c_str(),pman,policies);
+  threadPol->destroy();
 }
 
 SALOME::DataScopeServer_ptr BasicDataServer::getMyDataScopeServer()
 {
-  CORBA::Object_var obj(getPOA()->servant_to_reference(_father));
+  CORBA::Object_var obj(_father->getPOA()->servant_to_reference(_father));
   return SALOME::DataScopeServer::_narrow(obj);
 }
 
@@ -64,7 +77,3 @@ void BasicDataServer::Destroy()
   enforcedRelease();
 }
 
-PortableServer::POA_var BasicDataServer::getPOA() const
-{
-  return _father->getPOA();
-}
index e87da002b8b1712cacdb6942e9c7c6036eae7253..bf146b893bc887209fdbd768fb3609d79e85c04e 100644 (file)
@@ -46,11 +46,13 @@ namespace SALOMESDS
   public:
     std::string getVarNameCpp() const { return _var_name; }
   protected:
-    PortableServer::POA_var getPOA() const;
+    PortableServer::POA_var getPOA() const { return _poa; }
   protected:
     DataScopeServer *_father;
   private:
     std::string _var_name;
+    PortableServer::POA_var _poa;
+    static int POA_CNT;
   };
 }
 
index e00c082a669bb5086d0b750a674d688718903a39..b31345b8ba9e4a17e4b08b41436133fece8d2d2f 100644 (file)
@@ -61,6 +61,7 @@ namespace SALOMESDS
     PyObject *getLocals() const { return _locals; }
     PyObject *getPickler() const { return _pickler; }
     PortableServer::POA_var getPOA() { return _poa; }
+    CORBA::ORB_var getORB() { return _orb; }
     static std::string BuildTmpVarNameFrom(const std::string& varName);
   private:
     std::vector< std::string> getAllVarNames() const;
index 1e03c16f070836c858a9912e310e823e5fc7e7ae..3eaebfcbb9ea95d85643fc36111f6e65b2734c34 100644 (file)
@@ -38,14 +38,6 @@ bool RefCountServ::decrRef() const
   return ret;
 }
 
-void RefCountServ::enforcedRelease()
-{
-  PortableServer::POA_var poa(getPOA());
-  PortableServer::ObjectId_var oid(poa->servant_to_id(this));
-  poa->deactivate_object(oid);
-  _remove_ref();
-}
-
 RefCountServ::RefCountServ():_cnt(1)
 {
 }
index 7a0438eb836cd9d14e345d94670451aa389d36b6..2fee70216c89f69ed62b10bcfeab67c2ef25d6d4 100644 (file)
@@ -31,7 +31,6 @@ namespace SALOMESDS
     void incrRef() const;
     bool decrRef() const;
   protected:
-    void enforcedRelease();
     RefCountServ();
     RefCountServ(const RefCountServ& other);
     virtual ~RefCountServ();
index 4bb1f960a0650b92b36b1458d7914acfada0d73d..5bf2cc4298bfc12d48c35bd2a3a01a87b8d7b5d5 100644 (file)
@@ -48,6 +48,10 @@ TransactionVarCreate::TransactionVarCreate(TransactionFactory *tf, const std::st
   FromByteSeqToVB(constValue,_data);
 }
 
+void TransactionVarCreate::prepareRollBackInCaseOfFailure()
+{//nothing it is not a bug
+}
+
 void TransactionVarCreate::checkAliveAndKicking()
 {
   SALOME::DataScopeServer_var dsc(_tf->getDSM()->retriveDataScope(_scope_name.c_str()));
index a1cdfaac615d51bb6f52be7c627c255fe5109dec..8d1bfee4b5511d1e2f33e5afff4d903474f690e2 100644 (file)
@@ -38,6 +38,7 @@ namespace SALOMESDS
   public:
     Transaction(TransactionFactory *tf, const std::string& varName, const std::string& scopeName):_tf(tf),_var_name(varName),_scope_name(scopeName) { }
     virtual void checkAliveAndKicking();
+    virtual void prepareRollBackInCaseOfFailure() = 0;
   public:
     static void FromByteSeqToVB(const SALOME::ByteVec& bsToBeConv, std::vector<unsigned char>& ret);
   protected:
@@ -51,6 +52,7 @@ namespace SALOMESDS
   public:
     TransactionVarCreate(TransactionFactory *tf, const std::string& varName, const std::string& scopeName, const SALOME::ByteVec& constValue);
     void checkAliveAndKicking();
+    void prepareRollBackInCaseOfFailure();
   protected:
     std::vector<unsigned char> _data;
   };
index 8af10f1f773e3bba58b2fc4978521e2c84bae4d3..3c97b447a40ad4589ede072ff685702dd5045d8a 100644 (file)
@@ -81,5 +81,8 @@ void TransactionFactory::atomicApply(const SALOME::ListOfTransaction& transactio
         }
       elt->_remove_ref();
       transactionsCpp[i]=elt;
+      transactionsCpp[i].setHolder(this);
     }
+  for(std::size_t i=0;i<sz;i++)
+    transactionsCpp[i]->checkAliveAndKicking();
 }
index 2e9507331492ef6c83eec8ac4a95adb35483f5cf..145086e3bc14ac6786df6bafa051dd2c409d925e 100644 (file)
@@ -33,7 +33,7 @@ namespace SALOMESDS
 {
   class DataServerManager;
 
-  class SALOMESDS_EXPORT TransactionFactory : public virtual POA_SALOME::TransactionFactory
+  class SALOMESDS_EXPORT TransactionFactory : public virtual POA_SALOME::TransactionFactory, POAHolder
   {
   public:
     TransactionFactory(DataServerManager *dsm);