From 952cf5666af13dec4290d0701c424ded007a5e83 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Wed, 15 Jul 2015 09:20:09 +0200 Subject: [PATCH] Correction of little bugs. --- src/SALOMESDS/SALOMESDS_AutoRefCountPtr.hxx | 18 ++++++---- src/SALOMESDS/SALOMESDS_BasicDataServer.cxx | 10 +++--- src/SALOMESDS/SALOMESDS_BasicDataServer.hxx | 4 +-- src/SALOMESDS/SALOMESDS_DataScopeServer.cxx | 36 ++++++------------- src/SALOMESDS/SALOMESDS_DataScopeServer.hxx | 1 - src/SALOMESDS/SALOMESDS_DataServerManager.cxx | 6 ++-- src/SALOMESDS/SALOMESDS_Transaction.hxx | 3 +- src/SALOMESDS/TestSalomeSDS1.py | 1 + 8 files changed, 35 insertions(+), 44 deletions(-) diff --git a/src/SALOMESDS/SALOMESDS_AutoRefCountPtr.hxx b/src/SALOMESDS/SALOMESDS_AutoRefCountPtr.hxx index 0d597978c..dcbe86335 100644 --- a/src/SALOMESDS/SALOMESDS_AutoRefCountPtr.hxx +++ b/src/SALOMESDS/SALOMESDS_AutoRefCountPtr.hxx @@ -31,6 +31,14 @@ namespace SALOMESDS { public: virtual PortableServer::POA_var getPOA() const = 0; + CORBA::Object_var activate() + { + PortableServer::POA_var poa(getPOA()); + PortableServer::ObjectId_var id(poa->activate_object(this)); + CORBA::Object_var ret(poa->id_to_reference(id)); + return ret; + } + void enforcedRelease() { PortableServer::POA_var poa(getPOA()); @@ -89,12 +97,11 @@ namespace SALOMESDS return ret; } - template + template// T is expected to be a POAHolder subclass class AutoServantPtr { public: - AutoServantPtr(T *ptr=0):_ptr(ptr),_ph(0) { } - void setHolder(POAHolder *ph) { _ph=ph; } + AutoServantPtr(T *ptr=0):_ptr(ptr) { } ~AutoServantPtr() { destroyPtr(); } bool operator==(const AutoServantPtr& other) const { return _ptr==other._ptr; } bool operator==(const T *other) const { return _ptr==other; } @@ -110,13 +117,10 @@ namespace SALOMESDS { if(!_ptr) return; - if(!_ph) - throw Exception("AutoServantPtr : null POA holder !"); - _ph->enforcedRelease(); + _ptr->enforcedRelease(); } private: T *_ptr; - POAHolder *_ph; }; } diff --git a/src/SALOMESDS/SALOMESDS_BasicDataServer.cxx b/src/SALOMESDS/SALOMESDS_BasicDataServer.cxx index d1bb917f5..e89fd1653 100644 --- a/src/SALOMESDS/SALOMESDS_BasicDataServer.cxx +++ b/src/SALOMESDS/SALOMESDS_BasicDataServer.cxx @@ -26,11 +26,9 @@ using namespace SALOMESDS; -int BasicDataServer::POA_CNT=0; - BasicDataServer::BasicDataServer(DataScopeServerBase *father, const std::string& varName):_father(father),_var_name(varName) { - PortableServer::POA_var poa(_father->getPOA()); + /*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)); @@ -40,7 +38,7 @@ BasicDataServer::BasicDataServer(DataScopeServerBase *father, const std::string& 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(); + threadPol->destroy();*/ } SALOME::DataScopeServer_ptr BasicDataServer::getMyDataScopeServer() @@ -77,3 +75,7 @@ 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 9d0bc679f..7d127973c 100644 --- a/src/SALOMESDS/SALOMESDS_BasicDataServer.hxx +++ b/src/SALOMESDS/SALOMESDS_BasicDataServer.hxx @@ -46,13 +46,11 @@ namespace SALOMESDS public: std::string getVarNameCpp() const { return _var_name; } protected: - PortableServer::POA_var getPOA() const { return _poa; } + PortableServer::POA_var getPOA() const; protected: DataScopeServerBase *_father; private: std::string _var_name; - PortableServer::POA_var _poa; - static int POA_CNT; }; } diff --git a/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx b/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx index dace3b8fa..3e82e2f5b 100644 --- a/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx +++ b/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx @@ -151,9 +151,7 @@ void DataScopeServerBase::shutdownIfNotHostedByDSM() _orb->shutdown(0); else { - PortableServer::ObjectId_var oid(_poa->servant_to_id(this)); - _poa->deactivate_object(oid); - ret->_remove_ref(); + enforcedRelease(); } } @@ -220,13 +218,6 @@ std::vector< std::string > DataScopeServerBase::getAllVarNames() const return ret; } -CORBA::Object_var DataScopeServerBase::activateWithDedicatedPOA(BasicDataServer *ds) -{ - PortableServer::ObjectId_var id(_poa->activate_object(ds)); - CORBA::Object_var ret(_poa->id_to_reference(id)); - return ret; -} - void DataScopeServerBase::checkNotAlreadyExistingVar(const std::string& varName) { std::vector allNames(getAllVarNames()); @@ -280,7 +271,7 @@ SALOME::PickelizedPyObjRdOnlyServer_ptr DataScopeServer::createRdOnlyVar(const c std::string varNameCpp(varName); checkNotAlreadyExistingVar(varNameCpp); PickelizedPyObjRdOnlyServer *tmp(new PickelizedPyObjRdOnlyServer(this,varNameCpp,constValue)); - CORBA::Object_var ret(activateWithDedicatedPOA(tmp)); + CORBA::Object_var ret(tmp->activate()); std::pair< SALOME::BasicDataServer_var, BasicDataServer * > p(SALOME::BasicDataServer::_narrow(ret),tmp); _vars.push_back(p); return SALOME::PickelizedPyObjRdOnlyServer::_narrow(ret); @@ -291,7 +282,7 @@ SALOME::PickelizedPyObjRdExtServer_ptr DataScopeServer::createRdExtVar(const cha std::string varNameCpp(varName); checkNotAlreadyExistingVar(varNameCpp); PickelizedPyObjRdExtServer *tmp(new PickelizedPyObjRdExtServer(this,varNameCpp,constValue)); - CORBA::Object_var ret(activateWithDedicatedPOA(tmp)); + CORBA::Object_var ret(tmp->activate()); std::pair< SALOME::BasicDataServer_var, BasicDataServer * > p(SALOME::BasicDataServer::_narrow(ret),tmp); _vars.push_back(p); return SALOME::PickelizedPyObjRdExtServer::_narrow(ret); @@ -305,7 +296,7 @@ SALOME::PickelizedPyObjRdWrServer_ptr DataScopeServer::createRdWrVar(const char std::string varNameCpp(varName),typeNameCpp(typeName); checkNotAlreadyExistingVar(varNameCpp); PickelizedPyObjRdWrServer *tmp(new PickelizedPyObjRdWrServer(this,typeNameCpp,varNameCpp)); - CORBA::Object_var ret(activateWithDedicatedPOA(tmp)); + CORBA::Object_var ret(tmp->activate()); std::pair< SALOME::BasicDataServer_var, BasicDataServer * > p(SALOME::BasicDataServer::_narrow(ret),tmp); _vars.push_back(p); return SALOME::PickelizedPyObjRdWrServer::_narrow(ret); @@ -329,7 +320,7 @@ void DataScopeServerTransaction::createRdOnlyVarInternal(const std::string& varN { checkNotAlreadyExistingVar(varName); PickelizedPyObjRdOnlyServer *tmp(new PickelizedPyObjRdOnlyServer(this,varName,constValue)); - CORBA::Object_var ret(activateWithDedicatedPOA(tmp)); + CORBA::Object_var ret(tmp->activate()); std::pair< SALOME::BasicDataServer_var, BasicDataServer * > p(SALOME::BasicDataServer::_narrow(ret),tmp); _vars.push_back(p); } @@ -338,7 +329,7 @@ void DataScopeServerTransaction::createRdExtVarInternal(const std::string& varNa { checkNotAlreadyExistingVar(varName); PickelizedPyObjRdExtServer *tmp(new PickelizedPyObjRdExtServer(this,varName,constValue)); - CORBA::Object_var ret(activateWithDedicatedPOA(tmp)); + CORBA::Object_var ret(tmp->activate()); std::pair< SALOME::BasicDataServer_var, BasicDataServer * > p(SALOME::BasicDataServer::_narrow(ret),tmp); _vars.push_back(p); } @@ -347,7 +338,7 @@ void DataScopeServerTransaction::createRdWrVarInternal(const std::string& varNam { checkNotAlreadyExistingVar(varName); PickelizedPyObjRdWrServer *tmp(new PickelizedPyObjRdWrServer(this,varName,constValue)); - CORBA::Object_var ret(activateWithDedicatedPOA(tmp)); + CORBA::Object_var ret(tmp->activate()); std::pair< SALOME::BasicDataServer_var, BasicDataServer * > p(SALOME::BasicDataServer::_narrow(ret),tmp); _vars.push_back(p); } @@ -368,8 +359,7 @@ SALOME::Transaction_ptr DataScopeServerTransaction::createRdOnlyVarTransac(const { TransactionRdOnlyVarCreate *ret(new TransactionRdOnlyVarCreate(this,varName,constValue)); ret->checkNotAlreadyExisting(); - PortableServer::ObjectId_var id(_poa->activate_object(ret)); - CORBA::Object_var obj(_poa->id_to_reference(id)); + CORBA::Object_var obj(ret->activate()); return SALOME::Transaction::_narrow(obj); } @@ -377,8 +367,7 @@ SALOME::Transaction_ptr DataScopeServerTransaction::createRdExtVarTransac(const { TransactionRdExtVarCreate *ret(new TransactionRdExtVarCreate(this,varName,constValue)); ret->checkNotAlreadyExisting(); - PortableServer::ObjectId_var id(_poa->activate_object(ret)); - CORBA::Object_var obj(_poa->id_to_reference(id)); + CORBA::Object_var obj(ret->activate()); return SALOME::Transaction::_narrow(obj); } @@ -386,8 +375,7 @@ SALOME::Transaction_ptr DataScopeServerTransaction::createRdWrVarTransac(const c { TransactionRdWrVarCreate *ret(new TransactionRdWrVarCreate(this,varName,constValue)); ret->checkNotAlreadyExisting(); - PortableServer::ObjectId_var id(_poa->activate_object(ret)); - CORBA::Object_var obj(_poa->id_to_reference(id)); + CORBA::Object_var obj(ret->activate()); return SALOME::Transaction::_narrow(obj); } @@ -395,8 +383,7 @@ SALOME::Transaction_ptr DataScopeServerTransaction::addKeyValueInVarHard(const c { TransactionAddKeyValueHard *ret(new TransactionAddKeyValueHard(this,varName,key,value)); ret->checkNotAlreadyExisting(); - PortableServer::ObjectId_var id(_poa->activate_object(ret)); - CORBA::Object_var obj(_poa->id_to_reference(id)); + CORBA::Object_var obj(ret->activate()); return SALOME::Transaction::_narrow(obj); } @@ -439,7 +426,6 @@ void DataScopeServerTransaction::atomicApply(const SALOME::ListOfTransaction& tr } elt->_remove_ref(); transactionsCpp[i]=elt; - transactionsCpp[i].setHolder(this); } {// important do not merge loops ! std::vector transactions2(sz); diff --git a/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx b/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx index 03b5934d7..63af1c333 100644 --- a/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx +++ b/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx @@ -64,7 +64,6 @@ namespace SALOMESDS static std::string BuildTmpVarNameFrom(const std::string& varName); public: std::vector< std::string> getAllVarNames() const; - CORBA::Object_var activateWithDedicatedPOA(BasicDataServer *ds); void checkNotAlreadyExistingVar(const std::string& varName); void checkExistingVar(const std::string& varName); protected: diff --git a/src/SALOMESDS/SALOMESDS_DataServerManager.cxx b/src/SALOMESDS/SALOMESDS_DataServerManager.cxx index fa7d9d135..3f9c633de 100644 --- a/src/SALOMESDS/SALOMESDS_DataServerManager.cxx +++ b/src/SALOMESDS/SALOMESDS_DataServerManager.cxx @@ -117,7 +117,7 @@ typename T::PtrType CreateDataScope(const std::string& scopeName, const std::vec } // std::string fullScopeName(DataServerManager::CreateAbsNameInNSFromScopeName(scopeName)); - std::ostringstream oss; oss << "SALOME_DataScopeServer" << " " << scopeName << " " << isTransactionInt; + std::ostringstream oss; oss << "SALOME_DataScopeServer" << " " << scopeName << " " << isTransactionInt << " "; SALOME_ContainerManager::AddOmninamesParams(oss,&ns); std::string command(oss.str()); SALOME_ContainerManager::MakeTheCommandToBeLaunchedASync(command); @@ -176,7 +176,7 @@ public: typedef SALOME::DataScopeServer TheType; static const bool IsTransaction=false; static PtrType nil() { return SALOME::DataScopeServer::_nil(); } - static VarType narrow(CORBA::Object_ptr obj) { return SALOME::DataScopeServer::_narrow(obj); } + static PtrType narrow(CORBA::Object_ptr obj) { return SALOME::DataScopeServer::_narrow(obj); } static PtrType duplicate(PtrType obj) { return SALOME::DataScopeServer::_duplicate(obj); } }; @@ -188,7 +188,7 @@ public: typedef SALOME::DataScopeServerTransaction TheType; static const bool IsTransaction=true; static PtrType nil() { return SALOME::DataScopeServerTransaction::_nil(); } - static VarType narrow(CORBA::Object_ptr obj) { return SALOME::DataScopeServerTransaction::_narrow(obj); } + static PtrType narrow(CORBA::Object_ptr obj) { return SALOME::DataScopeServerTransaction::_narrow(obj); } static PtrType duplicate(PtrType obj) { return SALOME::DataScopeServerTransaction::_duplicate(obj); } }; diff --git a/src/SALOMESDS/SALOMESDS_Transaction.hxx b/src/SALOMESDS/SALOMESDS_Transaction.hxx index f934cdf5c..55531c224 100644 --- a/src/SALOMESDS/SALOMESDS_Transaction.hxx +++ b/src/SALOMESDS/SALOMESDS_Transaction.hxx @@ -33,13 +33,14 @@ namespace SALOMESDS { - class SALOMESDS_EXPORT Transaction : public virtual POA_SALOME::Transaction + class SALOMESDS_EXPORT Transaction : public virtual POA_SALOME::Transaction, public POAHolder { public: Transaction(DataScopeServerTransaction *dsct, const std::string& varName):_dsct(dsct),_var_name(varName) { if(!_dsct) throw Exception("Transaction constructor error !"); } std::string getVarName() const { return _var_name; } void checkNotAlreadyExisting() { _dsct->checkNotAlreadyExistingVar(_var_name); } void checkVarExisting() { _dsct->checkExistingVar(_var_name); } + PortableServer::POA_var getPOA() const { return _dsct->getPOA(); } virtual void prepareRollBackInCaseOfFailure() = 0; virtual void perform() = 0; virtual void rollBack() = 0; diff --git a/src/SALOMESDS/TestSalomeSDS1.py b/src/SALOMESDS/TestSalomeSDS1.py index f33d3a896..bb5aa6b59 100644 --- a/src/SALOMESDS/TestSalomeSDS1.py +++ b/src/SALOMESDS/TestSalomeSDS1.py @@ -25,6 +25,7 @@ import cPickle import gc import SalomeSDSClt +salome.salome_init() st="jjj" dsm=salome.naming_service.Resolve("/DataServerManager") assert(dsm.isAliveAndKicking("Default")) -- 2.39.2