From 0630a8d770b5f09ac870bfab32730a9c0f37a287 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Fri, 10 Jul 2015 17:06:58 +0200 Subject: [PATCH] try0 --- src/SALOMESDS/SALOMESDS_AutoRefCountPtr.hxx | 22 ++++++++++++++++--- src/SALOMESDS/SALOMESDS_BasicDataServer.cxx | 19 +++++++++++----- src/SALOMESDS/SALOMESDS_BasicDataServer.hxx | 4 +++- src/SALOMESDS/SALOMESDS_DataScopeServer.hxx | 1 + src/SALOMESDS/SALOMESDS_RefCountServ.cxx | 8 ------- src/SALOMESDS/SALOMESDS_RefCountServ.hxx | 1 - src/SALOMESDS/SALOMESDS_Transaction.cxx | 4 ++++ src/SALOMESDS/SALOMESDS_Transaction.hxx | 2 ++ .../SALOMESDS_TransactionFactory.cxx | 3 +++ .../SALOMESDS_TransactionFactory.hxx | 2 +- 10 files changed, 47 insertions(+), 19 deletions(-) diff --git a/src/SALOMESDS/SALOMESDS_AutoRefCountPtr.hxx b/src/SALOMESDS/SALOMESDS_AutoRefCountPtr.hxx index 249829e86..0d597978c 100644 --- a/src/SALOMESDS/SALOMESDS_AutoRefCountPtr.hxx +++ b/src/SALOMESDS/SALOMESDS_AutoRefCountPtr.hxx @@ -27,10 +27,17 @@ 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 @@ -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; }; } diff --git a/src/SALOMESDS/SALOMESDS_BasicDataServer.cxx b/src/SALOMESDS/SALOMESDS_BasicDataServer.cxx index 8b6ce446d..d0f102838 100644 --- a/src/SALOMESDS/SALOMESDS_BasicDataServer.cxx +++ b/src/SALOMESDS/SALOMESDS_BasicDataServer.cxx @@ -26,13 +26,26 @@ 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(); -} diff --git a/src/SALOMESDS/SALOMESDS_BasicDataServer.hxx b/src/SALOMESDS/SALOMESDS_BasicDataServer.hxx index e87da002b..bf146b893 100644 --- a/src/SALOMESDS/SALOMESDS_BasicDataServer.hxx +++ b/src/SALOMESDS/SALOMESDS_BasicDataServer.hxx @@ -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; }; } diff --git a/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx b/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx index e00c082a6..b31345b8b 100644 --- a/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx +++ b/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx @@ -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; diff --git a/src/SALOMESDS/SALOMESDS_RefCountServ.cxx b/src/SALOMESDS/SALOMESDS_RefCountServ.cxx index 1e03c16f0..3eaebfcbb 100644 --- a/src/SALOMESDS/SALOMESDS_RefCountServ.cxx +++ b/src/SALOMESDS/SALOMESDS_RefCountServ.cxx @@ -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) { } diff --git a/src/SALOMESDS/SALOMESDS_RefCountServ.hxx b/src/SALOMESDS/SALOMESDS_RefCountServ.hxx index 7a0438eb8..2fee70216 100644 --- a/src/SALOMESDS/SALOMESDS_RefCountServ.hxx +++ b/src/SALOMESDS/SALOMESDS_RefCountServ.hxx @@ -31,7 +31,6 @@ namespace SALOMESDS void incrRef() const; bool decrRef() const; protected: - void enforcedRelease(); RefCountServ(); RefCountServ(const RefCountServ& other); virtual ~RefCountServ(); diff --git a/src/SALOMESDS/SALOMESDS_Transaction.cxx b/src/SALOMESDS/SALOMESDS_Transaction.cxx index 4bb1f960a..5bf2cc429 100644 --- a/src/SALOMESDS/SALOMESDS_Transaction.cxx +++ b/src/SALOMESDS/SALOMESDS_Transaction.cxx @@ -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())); diff --git a/src/SALOMESDS/SALOMESDS_Transaction.hxx b/src/SALOMESDS/SALOMESDS_Transaction.hxx index a1cdfaac6..8d1bfee4b 100644 --- a/src/SALOMESDS/SALOMESDS_Transaction.hxx +++ b/src/SALOMESDS/SALOMESDS_Transaction.hxx @@ -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& 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 _data; }; diff --git a/src/SALOMESDS/SALOMESDS_TransactionFactory.cxx b/src/SALOMESDS/SALOMESDS_TransactionFactory.cxx index 8af10f1f7..3c97b447a 100644 --- a/src/SALOMESDS/SALOMESDS_TransactionFactory.cxx +++ b/src/SALOMESDS/SALOMESDS_TransactionFactory.cxx @@ -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;icheckAliveAndKicking(); } diff --git a/src/SALOMESDS/SALOMESDS_TransactionFactory.hxx b/src/SALOMESDS/SALOMESDS_TransactionFactory.hxx index 2e9507331..145086e3b 100644 --- a/src/SALOMESDS/SALOMESDS_TransactionFactory.hxx +++ b/src/SALOMESDS/SALOMESDS_TransactionFactory.hxx @@ -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); -- 2.39.2