From: Anthony Geay Date: Tue, 4 Aug 2015 16:12:23 +0000 (+0200) Subject: Implementation of working glob var. Remove memory leak on TestSalomeSDS.py. X-Git-Tag: V7_7_0a1~11 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=9e9d75481ae70fd213eca8c6e019b3a29b30b94d;p=modules%2Fkernel.git Implementation of working glob var. Remove memory leak on TestSalomeSDS.py. --- diff --git a/idl/SALOME_SDS.idl b/idl/SALOME_SDS.idl index b3ceaa958..ed8b9a39d 100644 --- a/idl/SALOME_SDS.idl +++ b/idl/SALOME_SDS.idl @@ -34,6 +34,7 @@ module SALOME DataScopeServer getMyDataScopeServer(); string getVarName(); string getScopeName(); + long getRCValue(); }; interface PickelizedPyObjServer : BasicDataServer @@ -58,6 +59,11 @@ module SALOME interface DataServerManager; + interface DataScopeKiller + { + void shutdown(); + }; + interface DataScopeServerBase { void ping(); @@ -65,7 +71,7 @@ module SALOME StringVec listVars(); boolean existVar(in string varName) raises (SALOME::SALOME_Exception); void deleteVar(in string varName) raises (SALOME::SALOME_Exception); - void shutdownIfNotHostedByDSM(); + 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); }; @@ -75,13 +81,17 @@ module SALOME BasicDataServer retrieveVar(in string varName) raises (SALOME::SALOME_Exception); PickelizedPyObjRdOnlyServer createRdOnlyVar(in string varName, in ByteVec constValue) raises (SALOME::SALOME_Exception); PickelizedPyObjRdExtServer createRdExtVar(in string varName, in ByteVec constValue) raises (SALOME::SALOME_Exception); - //PickelizedPyObjRdWrServer createRdWrVar(in string typeName, in string varName) raises (SALOME::SALOME_Exception); }; interface Transaction { }; + interface TransactionRdWrAccess : Transaction + { + PickelizedPyObjRdWrServer getVar() raises (SALOME::SALOME_Exception); + }; + typedef sequence ListOfTransaction; interface KeyWaiter @@ -91,6 +101,7 @@ module SALOME interface DataScopeServerTransaction : DataScopeServerBase { + string getAccessOfVar(in string varName) raises (SALOME::SALOME_Exception); Transaction createRdOnlyVarTransac(in string varName, in ByteVec constValue) raises (SALOME::SALOME_Exception); Transaction createRdExtVarTransac(in string varName, in ByteVec constValue) raises (SALOME::SALOME_Exception); Transaction createRdWrVarTransac(in string varName, in ByteVec constValue) raises (SALOME::SALOME_Exception); @@ -98,6 +109,7 @@ module SALOME Transaction addKeyValueInVarErrorIfAlreadyExisting(in string varName, in ByteVec keyValue, in ByteVec constValue) raises (SALOME::SALOME_Exception); void addKeyValueInVarErrorIfAlreadyExistingNow(in string varName, in ByteVec keyValue, in ByteVec constValue) raises (SALOME::SALOME_Exception); Transaction removeKeyInVarErrorIfNotAlreadyExisting(in string varName, in ByteVec keyValue) raises (SALOME::SALOME_Exception); + TransactionRdWrAccess createWorkingVarTransac(in string varName, in ByteVec constValue) raises (SALOME::SALOME_Exception); KeyWaiter waitForKeyInVar(in string varName, in ByteVec keyVal) raises (SALOME::SALOME_Exception); KeyWaiter waitForKeyInVarAndKillIt(in string varName, in ByteVec keyVal, out Transaction transac) raises (SALOME::SALOME_Exception); void atomicApply(in ListOfTransaction transactions) raises (SALOME::SALOME_Exception); diff --git a/src/SALOMESDS/SALOMESDS_BasicDataServer.cxx b/src/SALOMESDS/SALOMESDS_BasicDataServer.cxx index e89fd1653..64fed000e 100644 --- a/src/SALOMESDS/SALOMESDS_BasicDataServer.cxx +++ b/src/SALOMESDS/SALOMESDS_BasicDataServer.cxx @@ -75,6 +75,11 @@ void BasicDataServer::Destroy() enforcedRelease(); } +CORBA::Long BasicDataServer::getRCValue() +{ + return getCounter(); +} + PortableServer::POA_var BasicDataServer::getPOA() const { return _father->getPOA(); diff --git a/src/SALOMESDS/SALOMESDS_BasicDataServer.hxx b/src/SALOMESDS/SALOMESDS_BasicDataServer.hxx index 7a22300ef..eace20393 100644 --- a/src/SALOMESDS/SALOMESDS_BasicDataServer.hxx +++ b/src/SALOMESDS/SALOMESDS_BasicDataServer.hxx @@ -43,6 +43,7 @@ namespace SALOMESDS void Register(); void UnRegister(); void Destroy(); + CORBA::Long getRCValue(); public: DataScopeServerBase *getFather() const { return _father; } std::string getVarNameCpp() const { return _var_name; } diff --git a/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx b/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx index 9dec327d6..514956e24 100644 --- a/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx +++ b/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx @@ -44,11 +44,17 @@ using namespace SALOMESDS; std::size_t DataScopeServerBase::COUNTER=0; -DataScopeServerBase::DataScopeServerBase(CORBA::ORB_ptr orb, const std::string& scopeName):_globals(0),_locals(0),_pickler(0),_orb(CORBA::ORB::_duplicate(orb)),_name(scopeName) +void DataScopeKiller::shutdown() { + Py_Finalize(); + _orb->shutdown(0); } -DataScopeServerBase::DataScopeServerBase(const DataScopeServerBase& other):_globals(0),_locals(0),_pickler(0),_name(other._name),_vars(other._vars) +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) +{ +} + +DataScopeServerBase::DataScopeServerBase(const DataScopeServerBase& other):_globals(0),_locals(0),_pickler(0),_name(other._name),_vars(other._vars),_killer(other._killer) { } @@ -57,6 +63,14 @@ DataScopeServerBase::~DataScopeServerBase() // _globals is borrowed ref -> do nothing Py_XDECREF(_locals); Py_XDECREF(_pickler); + for(std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::const_iterator it=_vars.begin();it!=_vars.end();it++) + { + BasicDataServer *obj((*it).second); + if(obj) + { + obj->decrRef(); + } + } } /*! @@ -126,17 +140,18 @@ void DataScopeServerBase::deleteVar(const char *varName) } std::size_t pos(std::distance(allNames.begin(),it)); std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::iterator it0(_vars.begin()); - (*it0).first->UnRegister(); + for(std::size_t ii=0;iidecrRef(); _vars.erase(it0); } -void DataScopeServerBase::shutdownIfNotHostedByDSM() +CORBA::Boolean DataScopeServerBase::shutdownIfNotHostedByDSM(SALOME::DataScopeKiller_out killer) { SALOME_NamingService ns(_orb); CORBA::Object_var obj(ns.Resolve(DataServerManager::NAME_IN_NS)); SALOME::DataServerManager_var dsm(SALOME::DataServerManager::_narrow(obj)); if(CORBA::is_nil(dsm)) - return ; + throw Exception("Unable to reach in the NS the unique DataServerManager instance of the Session !"); // destroy ref in the naming service std::string fullScopeName(SALOMESDS::DataServerManager::CreateAbsNameInNSFromScopeName(_name)); ns.Destroy_Name(fullScopeName.c_str()); @@ -149,10 +164,17 @@ void DataScopeServerBase::shutdownIfNotHostedByDSM() catch(...) { ret=0; } // if(!ret) - _orb->shutdown(0); + { + enforcedRelease(); + killer=SALOME::DataScopeKiller::_duplicate(_killer); + return true; + } else { + ret->_remove_ref(); enforcedRelease(); + killer=SALOME::DataScopeKiller::_duplicate(_killer); + return false; } } @@ -307,13 +329,43 @@ PickelizedPyObjServer *DataScopeServerBase::checkVarExistingAndDict(const std::s return ret; } +void DataScopeServerBase::moveStatusOfVarFromRdWrToRdOnly(const std::string& varName) +{ + std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::iterator it(retrieveVarInternal4(varName)); + std::pair< SALOME::BasicDataServer_var, BasicDataServer * >& p(*it); + PickelizedPyObjRdWrServer *varc(dynamic_cast(p.second)); + if(!varc) + throw Exception("DataScopeServerBase::moveStatusOfVarFromRdWrToRdOnly : var is not a RdWr !"); + PyObject *pyobj(varc->getPyObj()); Py_XINCREF(pyobj); + PickelizedPyObjRdOnlyServer *newVar(new PickelizedPyObjRdOnlyServer(this,varName,pyobj)); + CORBA::Object_var obj(newVar->activate()); + SALOME::BasicDataServer_var obj2(SALOME::BasicDataServer::_narrow(obj)); + p.first=obj2; p.second=newVar; + varc->decrRef(); +} + +void DataScopeServerBase::moveStatusOfVarFromRdOnlyToRdWr(const std::string& varName) +{ + std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::iterator it(retrieveVarInternal4(varName)); + std::pair< SALOME::BasicDataServer_var, BasicDataServer * >& p(*it); + PickelizedPyObjRdOnlyServer *varc(dynamic_cast(p.second)); + if(!varc) + throw Exception("DataScopeServerBase::moveStatusOfVarFromRdOnlyToRdWr : var is not a RdWr !"); + PyObject *pyobj(varc->getPyObj()); Py_XINCREF(pyobj); + PickelizedPyObjRdWrServer *newVar(new PickelizedPyObjRdWrServer(this,varName,pyobj)); + CORBA::Object_var obj(newVar->activate()); + SALOME::BasicDataServer_var obj2(SALOME::BasicDataServer::_narrow(obj)); + p.first=obj2; p.second=newVar; + varc->decrRef(); +} + std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::const_iterator DataScopeServerBase::retrieveVarInternal3(const std::string& varName) const { std::vector allNames(getAllVarNames()); std::vector::iterator it(std::find(allNames.begin(),allNames.end(),varName)); if(it==allNames.end()) { - std::ostringstream oss; oss << "DataScopeServerBase::retrieveVarInternal : name \"" << varName << "\" does not exists ! Possibilities are :"; + std::ostringstream oss; oss << "DataScopeServerBase::retrieveVarInternal3 : name \"" << varName << "\" does not exists ! Possibilities are :"; std::copy(allNames.begin(),allNames.end(),std::ostream_iterator(oss,", ")); throw Exception(oss.str()); } @@ -323,9 +375,25 @@ std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::const_ return it0; } +std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::iterator DataScopeServerBase::retrieveVarInternal4(const std::string& varName) +{ + std::vector allNames(getAllVarNames()); + std::vector::iterator it(std::find(allNames.begin(),allNames.end(),varName)); + if(it==allNames.end()) + { + std::ostringstream oss; oss << "DataScopeServerBase::retrieveVarInternal4 : name \"" << varName << "\" does not exists ! Possibilities are :"; + std::copy(allNames.begin(),allNames.end(),std::ostream_iterator(oss,", ")); + throw Exception(oss.str()); + } + std::size_t pos(std::distance(allNames.begin(),it)); + std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::iterator it0(_vars.begin()); + for(std::size_t i=0;i to protect against throw - */ SALOME::PickelizedPyObjRdWrServer_ptr DataScopeServer::createRdWrVar(const char *typeName, const char *varName) { std::string varNameCpp(varName),typeNameCpp(typeName); @@ -375,7 +440,7 @@ DataScopeServer::~DataScopeServer() //////// -DataScopeServerTransaction::DataScopeServerTransaction(CORBA::ORB_ptr orb, const std::string& scopeName):DataScopeServerBase(orb,scopeName) +DataScopeServerTransaction::DataScopeServerTransaction(CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName):DataScopeServerBase(orb,killer,scopeName) { CORBA::Object_var obj(_orb->resolve_initial_references("RootPOA")); PortableServer::POA_var poa(PortableServer::POA::_narrow(obj)); @@ -395,6 +460,20 @@ DataScopeServerTransaction::DataScopeServerTransaction(const DataScopeServerTran { } +char *DataScopeServerTransaction::getAccessOfVar(const char *varName) +{ + std::string varNameCpp(varName); + checkExistingVar(varNameCpp); + BasicDataServer *var(retrieveVarInternal2(varName)); + if(!var) + throw Exception("DataScopeServerTransaction::getAccessOfVar : variable is NULL !"); + PickelizedPyObjServer *varc(dynamic_cast(var)); + if(!varc) + throw Exception("DataScopeServerTransaction::getAccessOfVar : variable is not of type PickelizedPyObjServer !"); + std::string ret(varc->getAccessStr()); + return CORBA::string_dup(ret.c_str()); +} + void DataScopeServerTransaction::createRdOnlyVarInternal(const std::string& varName, const SALOME::ByteVec& constValue) { checkNotAlreadyExistingVar(varName); @@ -569,6 +648,20 @@ SALOME::Transaction_ptr DataScopeServerTransaction::removeKeyInVarErrorIfNotAlre return SALOME::Transaction::_narrow(obj); } +SALOME::TransactionRdWrAccess_ptr DataScopeServerTransaction::createWorkingVarTransac(const char *varName, const SALOME::ByteVec& constValue) +{ + std::string varNameCpp(varName); + checkNotAlreadyExistingVar(varName); + PickelizedPyObjRdWrServer *tmp(new PickelizedPyObjRdWrServer(this,varNameCpp,constValue)); + CORBA::Object_var obj(tmp->activate()); + std::pair< SALOME::BasicDataServer_var, BasicDataServer * > p(SALOME::BasicDataServer::_narrow(obj),tmp); + _vars.push_back(p); + // + TransactionMorphRdWrIntoRdOnly *ret(new TransactionMorphRdWrIntoRdOnly(this,varName)); + CORBA::Object_var obj2(ret->activate()); + return SALOME::TransactionRdWrAccess::_narrow(obj2); +} + SALOME::KeyWaiter_ptr DataScopeServerTransaction::waitForKeyInVar(const char *varName, const SALOME::ByteVec& keyVal) { PickelizedPyObjServer *pickelObj(checkVarExistingAndDict(varName)); diff --git a/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx b/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx index ab7e810dc..608ae507e 100644 --- a/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx +++ b/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx @@ -37,26 +37,35 @@ namespace SALOMESDS { + class SALOMESDS_EXPORT DataScopeKiller : public POA_SALOME::DataScopeKiller + { + public: + DataScopeKiller(CORBA::ORB_ptr orb):_orb(CORBA::ORB::_duplicate(orb)) { } + void shutdown(); + private: + CORBA::ORB_var _orb; + }; + class KeyWaiter; class PickelizedPyObjServer; class SALOMESDS_EXPORT DataScopeServerBase : public virtual POA_SALOME::DataScopeServerBase, public POAHolder { public: - DataScopeServerBase(CORBA::ORB_ptr orb, const std::string& scopeName); + DataScopeServerBase(CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName); DataScopeServerBase(const DataScopeServerBase& other); void ping(); char *getScopeName(); SALOME::StringVec *listVars(); CORBA::Boolean existVar(const char *varName); SALOME::BasicDataServer_ptr retrieveVarInternal(const char *varName); - BasicDataServer *retrieveVarInternal2(const std::string& varName); void deleteVar(const char *varName); - void shutdownIfNotHostedByDSM(); + CORBA::Boolean shutdownIfNotHostedByDSM(SALOME::DataScopeKiller_out killer); SALOME::ByteVec *fetchSerializedContent(const char *varName); SALOME::SeqOfByteVec *getAllKeysOfVarWithTypeDict(const char *varName); ~DataScopeServerBase(); public: + BasicDataServer *retrieveVarInternal2(const std::string& varName); void initializePython(int argc, char *argv[]); void registerToSalomePiDict() const; void setPOA(PortableServer::POA_var poa); @@ -73,8 +82,12 @@ namespace SALOMESDS void checkNotAlreadyExistingVar(const std::string& varName) const; void checkExistingVar(const std::string& varName) const; PickelizedPyObjServer *checkVarExistingAndDict(const std::string& varName); + public: + void moveStatusOfVarFromRdWrToRdOnly(const std::string& varName); + void moveStatusOfVarFromRdOnlyToRdWr(const std::string& varName); protected: std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::const_iterator retrieveVarInternal3(const std::string& varName) const; + std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::iterator retrieveVarInternal4(const std::string& varName); protected: PyObject *_globals; PyObject *_locals; @@ -83,13 +96,14 @@ namespace SALOMESDS CORBA::ORB_var _orb; std::string _name; std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > > _vars; + SALOME::DataScopeKiller_var _killer; static std::size_t COUNTER; }; class SALOMESDS_EXPORT DataScopeServer : public DataScopeServerBase, public virtual POA_SALOME::DataScopeServer { public: - DataScopeServer(CORBA::ORB_ptr orb, const std::string& scopeName); + DataScopeServer(CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName); DataScopeServer(const DataScopeServer& other); SALOME::BasicDataServer_ptr retrieveVar(const char *varName) { return retrieveVarInternal(varName); } SALOME::PickelizedPyObjRdOnlyServer_ptr createRdOnlyVar(const char *varName, const SALOME::ByteVec& constValue); @@ -101,7 +115,7 @@ namespace SALOMESDS class SALOMESDS_EXPORT DataScopeServerTransaction : public DataScopeServerBase, public virtual POA_SALOME::DataScopeServerTransaction { public://not remotely callable - DataScopeServerTransaction(CORBA::ORB_ptr orb, const std::string& scopeName); + DataScopeServerTransaction(CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName); DataScopeServerTransaction(const DataScopeServerTransaction& other); ~DataScopeServerTransaction(); void createRdOnlyVarInternal(const std::string& varName, const SALOME::ByteVec& constValue); @@ -113,6 +127,7 @@ namespace SALOMESDS void notifyKey(PyObject *keyObj, PyObject *valueObj); SALOME::ByteVec *waitForMonoThrRev(SALOME::KeyWaiter_ptr kw); public://remotely callable + char *getAccessOfVar(const char *varName); SALOME::Transaction_ptr createRdOnlyVarTransac(const char *varName, const SALOME::ByteVec& constValue); SALOME::Transaction_ptr createRdExtVarTransac(const char *varName, const SALOME::ByteVec& constValue); SALOME::Transaction_ptr createRdWrVarTransac(const char *varName, const SALOME::ByteVec& constValue); @@ -120,6 +135,7 @@ namespace SALOMESDS SALOME::Transaction_ptr addKeyValueInVarErrorIfAlreadyExisting(const char *varName, const SALOME::ByteVec& key, const SALOME::ByteVec& value); void addKeyValueInVarErrorIfAlreadyExistingNow(const char *varName, const SALOME::ByteVec& key, const SALOME::ByteVec& value); SALOME::Transaction_ptr removeKeyInVarErrorIfNotAlreadyExisting(const char *varName, const SALOME::ByteVec& key); + SALOME::TransactionRdWrAccess_ptr createWorkingVarTransac(const char *varName, const SALOME::ByteVec& constValue); SALOME::KeyWaiter_ptr waitForKeyInVar(const char *varName, const SALOME::ByteVec& keyVal); SALOME::KeyWaiter_ptr waitForKeyInVarAndKillIt(const char *varName, const SALOME::ByteVec& keyVal, SALOME::Transaction_out transac); void atomicApply(const SALOME::ListOfTransaction& transactions); diff --git a/src/SALOMESDS/SALOMESDS_DataServerManager.cxx b/src/SALOMESDS/SALOMESDS_DataServerManager.cxx index 326adefe1..f8b2678e0 100644 --- a/src/SALOMESDS/SALOMESDS_DataServerManager.cxx +++ b/src/SALOMESDS/SALOMESDS_DataServerManager.cxx @@ -35,7 +35,7 @@ const char DataServerManager::DFT_SCOPE_NAME_IN_NS[]="Default"; DataServerManager::DataServerManager(int argc, char *argv[], CORBA::ORB_ptr orb, PortableServer::POA_ptr poa):_orb(CORBA::ORB::_duplicate(orb)) { - DataScopeServer *dftScope(new DataScopeServer(orb,DFT_SCOPE_NAME_IN_NS));//_remove_ref will be call by DataScopeServer::shutdownIfNotHostedByDSM + DataScopeServer *dftScope(new DataScopeServer(orb,SALOME::DataScopeKiller::_nil(),DFT_SCOPE_NAME_IN_NS));//_remove_ref will be call by DataScopeServer::shutdownIfNotHostedByDSM PortableServer::POAManager_var pman(poa->the_POAManager()); CORBA::PolicyList policies; policies.length(1); @@ -225,7 +225,10 @@ SALOME::DataScopeServerBase_ptr DataServerManager::retriveDataScope(const char * void DataServerManager::removeDataScope(const char *scopeName) { SALOME::DataScopeServerBase_var scs(getScopePtrGivenName(scopeName)); - scs->shutdownIfNotHostedByDSM(); + SALOME::DataScopeKiller_ptr killer; + if(scs->shutdownIfNotHostedByDSM(killer)) + killer->shutdown(); + CORBA::release(killer); } void DataServerManager::cleanScopesInNS() @@ -246,7 +249,13 @@ void DataServerManager::shutdownScopes() { std::vector scopeNames(listOfScopesCpp()); for(std::vector::const_iterator it=scopeNames.begin();it!=scopeNames.end();it++) - getScopePtrGivenName(*it)->shutdownIfNotHostedByDSM(); + { + SALOME::DataScopeServerBase_var scope(getScopePtrGivenName(*it)); + SALOME::DataScopeKiller_ptr killer; + if(scope->shutdownIfNotHostedByDSM(killer)) + killer->shutdown(); + CORBA::release(killer); + } } std::string DataServerManager::CreateAbsNameInNSFromScopeName(const std::string& scopeName) diff --git a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.cxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.cxx index 0b1a196cc..b4646961e 100644 --- a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.cxx +++ b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.cxx @@ -27,12 +27,14 @@ using namespace SALOMESDS; -PickelizedPyObjRdExtServer::PickelizedPyObjRdExtServer(DataScopeServerBase *father, const std::string& varName, const SALOME::ByteVec& value):PickelizedPyObjServer(father,varName,value) +const char PickelizedPyObjRdExtServer::ACCESS_REPR[]="RdExt"; + +PickelizedPyObjRdExtServer::PickelizedPyObjRdExtServer(DataScopeServerBase *father, const std::string& varName, const SALOME::ByteVec& value):PickelizedPyObjServerModifiable(father,varName,value) { } //! obj is consumed -PickelizedPyObjRdExtServer::PickelizedPyObjRdExtServer(DataScopeServerBase *father, const std::string& varName, PyObject *obj):PickelizedPyObjServer(father,varName,obj) +PickelizedPyObjRdExtServer::PickelizedPyObjRdExtServer(DataScopeServerBase *father, const std::string& varName, PyObject *obj):PickelizedPyObjServerModifiable(father,varName,obj) { } @@ -135,3 +137,8 @@ void PickelizedPyObjRdExtServer::checkDictSetitemRdExtness(PyObject *argsPy) throw Exception("PickelizedPyObjRdExtServer::checkDictSetitemRdExtness : specified key of __setitem__ already exists ! RdExt property is not applied !"); } } + +std::string PickelizedPyObjRdExtServer::getAccessStr() const +{ + return std::string(ACCESS_REPR); +} diff --git a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.hxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.hxx index d982c165b..318e9c343 100644 --- a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.hxx +++ b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.hxx @@ -30,18 +30,22 @@ namespace SALOMESDS { - class PickelizedPyObjRdExtServer : public PickelizedPyObjServer, public virtual POA_SALOME::PickelizedPyObjRdExtServer + class PickelizedPyObjRdExtServer : public PickelizedPyObjServerModifiable, public virtual POA_SALOME::PickelizedPyObjRdExtServer { public: PickelizedPyObjRdExtServer(DataScopeServerBase *father, const std::string& varName, const SALOME::ByteVec& value); PickelizedPyObjRdExtServer(DataScopeServerBase *father, const std::string& varName, PyObject *obj); ~PickelizedPyObjRdExtServer(); SALOME::PickelizedPyObjRdExtServer_ptr invokePythonMethodOn(const char *method, const SALOME::ByteVec& args); + public: + std::string getAccessStr() const; private: void checkRdExtnessOf(const std::string& methodName, PyObject *argsPy); void checkListRdExtnessOf(const std::string& methodName, PyObject *argsPy); void checkDictRdExtnessOf(const std::string& methodName, PyObject *argsPy); void checkDictSetitemRdExtness(PyObject *argsPy); + public: + static const char ACCESS_REPR[]; }; } diff --git a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdOnlyServer.cxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdOnlyServer.cxx index e8bef2342..010ceb3ef 100644 --- a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdOnlyServer.cxx +++ b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdOnlyServer.cxx @@ -22,6 +22,8 @@ using namespace SALOMESDS; +const char PickelizedPyObjRdOnlyServer::ACCESS_REPR[]="RdOnly"; + PickelizedPyObjRdOnlyServer::PickelizedPyObjRdOnlyServer(DataScopeServerBase *father, const std::string& varName, const SALOME::ByteVec& value):PickelizedPyObjServer(father,varName,value) { } @@ -33,3 +35,13 @@ PickelizedPyObjRdOnlyServer::PickelizedPyObjRdOnlyServer(DataScopeServerBase *fa PickelizedPyObjRdOnlyServer::~PickelizedPyObjRdOnlyServer() { } + +void PickelizedPyObjRdOnlyServer::addKeyValueErrorIfAlreadyExisting(PyObject *key, PyObject *value) +{ + throw Exception("PickelizedPyObjRdOnlyServer::addKeyValueErrorIfAlreadyExisting : incompatible with RdOnly !"); +} + +std::string PickelizedPyObjRdOnlyServer::getAccessStr() const +{ + return std::string(ACCESS_REPR); +} diff --git a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdOnlyServer.hxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdOnlyServer.hxx index a5047fdaa..4ff78294b 100644 --- a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdOnlyServer.hxx +++ b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdOnlyServer.hxx @@ -36,6 +36,11 @@ namespace SALOMESDS PickelizedPyObjRdOnlyServer(DataScopeServerBase *father, const std::string& varName, const SALOME::ByteVec& value); PickelizedPyObjRdOnlyServer(DataScopeServerBase *father, const std::string& varName, PyObject *obj); ~PickelizedPyObjRdOnlyServer(); + public: + void addKeyValueErrorIfAlreadyExisting(PyObject *key, PyObject *value); + std::string getAccessStr() const; + public: + static const char ACCESS_REPR[]; }; } diff --git a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdWrServer.cxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdWrServer.cxx index cdb0d6922..38c51e54a 100644 --- a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdWrServer.cxx +++ b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdWrServer.cxx @@ -27,16 +27,18 @@ using namespace SALOMESDS; -PickelizedPyObjRdWrServer::PickelizedPyObjRdWrServer(DataScopeServerBase *father, const std::string& typeName, const std::string& varName):PickelizedPyObjServer(father,varName,CreateDftObjFromType(father->getGlobals(),typeName)) +const char PickelizedPyObjRdWrServer::ACCESS_REPR[]="RdWr"; + +PickelizedPyObjRdWrServer::PickelizedPyObjRdWrServer(DataScopeServerBase *father, const std::string& typeName, const std::string& varName):PickelizedPyObjServerModifiable(father,varName,CreateDftObjFromType(father->getGlobals(),typeName)) { } -PickelizedPyObjRdWrServer::PickelizedPyObjRdWrServer(DataScopeServerBase *father, const std::string& varName, const SALOME::ByteVec& value):PickelizedPyObjServer(father,varName,value) +PickelizedPyObjRdWrServer::PickelizedPyObjRdWrServer(DataScopeServerBase *father, const std::string& varName, const SALOME::ByteVec& value):PickelizedPyObjServerModifiable(father,varName,value) { } //! obj is consumed -PickelizedPyObjRdWrServer::PickelizedPyObjRdWrServer(DataScopeServerBase *father, const std::string& varName, PyObject *obj):PickelizedPyObjServer(father,varName,obj) +PickelizedPyObjRdWrServer::PickelizedPyObjRdWrServer(DataScopeServerBase *father, const std::string& varName, PyObject *obj):PickelizedPyObjServerModifiable(father,varName,obj) { } @@ -52,9 +54,6 @@ void PickelizedPyObjRdWrServer::setSerializedContent(const SALOME::ByteVec& newV setSerializedContentInternal(newValue); } -/*! - * Called remotely -> to protect against throw - */ SALOME::PickelizedPyObjRdWrServer_ptr PickelizedPyObjRdWrServer::invokePythonMethodOn(const char *method, const SALOME::ByteVec& args) { if(!_self) @@ -108,3 +107,22 @@ SALOME::PickelizedPyObjRdWrServer_ptr PickelizedPyObjRdWrServer::invokePythonMet CORBA::Object_var obj(poa->id_to_reference(id)); return SALOME::PickelizedPyObjRdWrServer::_narrow(obj); } + +void PickelizedPyObjRdWrServer::addKeyValueHard(PyObject *key, PyObject *value) +{ + bool isOK(PyDict_SetItem(_self,key,value)==0); + if(!isOK) + throw Exception("PickelizedPyObjRdWrServer::addKeyValueHard : error when trying to add key,value to dict !"); +} + +void PickelizedPyObjRdWrServer::removeKeyInVarErrorIfNotAlreadyExisting(PyObject *key) +{ + checkKeyPresent(key); + if(PyDict_DelItem(_self,key)!=0) + throw Exception("PickelizedPyObjRdWrServer::removeKeyInVarErrorIfNotAlreadyExisting : error during deletion of key in dict !"); +} + +std::string PickelizedPyObjRdWrServer::getAccessStr() const +{ + return std::string(ACCESS_REPR); +} diff --git a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdWrServer.hxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdWrServer.hxx index b6fba2f21..0a3a3e093 100644 --- a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdWrServer.hxx +++ b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdWrServer.hxx @@ -30,7 +30,7 @@ namespace SALOMESDS { - class PickelizedPyObjRdWrServer : public PickelizedPyObjServer, public virtual POA_SALOME::PickelizedPyObjRdWrServer + class PickelizedPyObjRdWrServer : public PickelizedPyObjServerModifiable, public virtual POA_SALOME::PickelizedPyObjRdWrServer { public: PickelizedPyObjRdWrServer(DataScopeServerBase *father, const std::string& typeName, const std::string& varName); @@ -39,6 +39,12 @@ namespace SALOMESDS ~PickelizedPyObjRdWrServer(); void setSerializedContent(const SALOME::ByteVec& newValue); SALOME::PickelizedPyObjRdWrServer_ptr invokePythonMethodOn(const char *method, const SALOME::ByteVec& args); + public: + std::string getAccessStr() const; + void addKeyValueHard(PyObject *key, PyObject *value); + void removeKeyInVarErrorIfNotAlreadyExisting(PyObject *key); + public: + static const char ACCESS_REPR[]; }; } diff --git a/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.cxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.cxx index f770129eb..587bc55fa 100644 --- a/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.cxx +++ b/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.cxx @@ -72,24 +72,14 @@ void PickelizedPyObjServer::checkKeyPresent(PyObject *key) void PickelizedPyObjServer::addKeyValueHard(PyObject *key, PyObject *value) { - bool isOK(PyDict_SetItem(_self,key,value)==0); - if(!isOK) - throw Exception("PickelizedPyObjServer::addKeyValueHard : error when trying to add key,value to dict !"); -} - -void PickelizedPyObjServer::addKeyValueErrorIfAlreadyExisting(PyObject *key, PyObject *value) -{ - checkKeyNotAlreadyPresent(key); - bool isOK(PyDict_SetItem(_self,key,value)==0); - if(!isOK) - throw Exception("PickelizedPyObjServer::addKeyValueErrorIfAlreadyExisting : error when trying to add key,value to dict !"); + std::ostringstream oss; oss << "PickelizedPyObjServer::addKeyValueHard : var \"" << getVarNameCpp() << "\" is not permitted to alter its value !"; + throw Exception(oss.str()); } void PickelizedPyObjServer::removeKeyInVarErrorIfNotAlreadyExisting(PyObject *key) { - checkKeyPresent(key); - if(PyDict_DelItem(_self,key)!=0) - throw Exception("PickelizedPyObjServer::removeKeyInVarErrorIfNotAlreadyExisting : error during deletion of key in dict !"); + std::ostringstream oss; oss << "PickelizedPyObjServer::removeKeyInVarErrorIfNotAlreadyExisting : var \"" << getVarNameCpp() << "\" is not permitted to alter its value !"; + throw Exception(oss.str()); } void PickelizedPyObjServer::FromByteSeqToCpp(const SALOME::ByteVec& bsToBeConv, std::string& ret) @@ -264,3 +254,19 @@ void PickelizedPyObjServer::checkKeyPresence(PyObject *key, bool presence) } Py_XDECREF(retPy); } + +PickelizedPyObjServerModifiable::PickelizedPyObjServerModifiable(DataScopeServerBase *father, const std::string& varName, const SALOME::ByteVec& value):PickelizedPyObjServer(father,varName,value) +{ +} + +PickelizedPyObjServerModifiable::PickelizedPyObjServerModifiable(DataScopeServerBase *father, const std::string& varName, PyObject *obj):PickelizedPyObjServer(father,varName,obj) +{ +} + +void PickelizedPyObjServerModifiable::addKeyValueErrorIfAlreadyExisting(PyObject *key, PyObject *value) +{ + checkKeyNotAlreadyPresent(key); + bool isOK(PyDict_SetItem(_self,key,value)==0); + if(!isOK) + throw Exception("PickelizedPyObjServerModifiable::addKeyValueErrorIfAlreadyExisting : error when trying to add key,value to dict !"); +} diff --git a/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.hxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.hxx index 2b6490651..034588775 100644 --- a/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.hxx +++ b/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.hxx @@ -37,17 +37,19 @@ namespace SALOMESDS public: PickelizedPyObjServer(DataScopeServerBase *father, const std::string& varName, const SALOME::ByteVec& value); PickelizedPyObjServer(DataScopeServerBase *father, const std::string& varName, PyObject *obj); - ~PickelizedPyObjServer(); + virtual ~PickelizedPyObjServer(); void setSerializedContent(const SALOME::ByteVec& newValue); SALOME::ByteVec *fetchSerializedContent(); public: bool isDict(); void checkKeyNotAlreadyPresent(PyObject *key); void checkKeyPresent(PyObject *key); - void addKeyValueHard(PyObject *key, PyObject *value); - void addKeyValueErrorIfAlreadyExisting(PyObject *key, PyObject *value); - void removeKeyInVarErrorIfNotAlreadyExisting(PyObject *key); PyObject *getPyObj() const { return _self; } + public: + virtual void addKeyValueHard(PyObject *key, PyObject *value); + virtual void removeKeyInVarErrorIfNotAlreadyExisting(PyObject *key); + virtual void addKeyValueErrorIfAlreadyExisting(PyObject *key, PyObject *value) = 0; + virtual std::string getAccessStr() const = 0; public: static void FromByteSeqToCpp(const SALOME::ByteVec& bsToBeConv, std::string& ret); static void FromCppToByteSeq(const std::string& strToBeConv, SALOME::ByteVec& ret); @@ -68,6 +70,14 @@ namespace SALOMESDS PyObject *_self; PortableServer::POA_var _poa; }; + + class PickelizedPyObjServerModifiable : public PickelizedPyObjServer + { + public: + PickelizedPyObjServerModifiable(DataScopeServerBase *father, const std::string& varName, const SALOME::ByteVec& value); + PickelizedPyObjServerModifiable(DataScopeServerBase *father, const std::string& varName, PyObject *obj); + void addKeyValueErrorIfAlreadyExisting(PyObject *key, PyObject *value); + }; } #endif diff --git a/src/SALOMESDS/SALOMESDS_RefCountServ.hxx b/src/SALOMESDS/SALOMESDS_RefCountServ.hxx index 2fee70216..3373bfa25 100644 --- a/src/SALOMESDS/SALOMESDS_RefCountServ.hxx +++ b/src/SALOMESDS/SALOMESDS_RefCountServ.hxx @@ -30,6 +30,7 @@ namespace SALOMESDS public: void incrRef() const; bool decrRef() const; + int getCounter() const { return _cnt; } protected: RefCountServ(); RefCountServ(const RefCountServ& other); diff --git a/src/SALOMESDS/SALOMESDS_Transaction.cxx b/src/SALOMESDS/SALOMESDS_Transaction.cxx index ca9bc32ee..463f2f5ff 100644 --- a/src/SALOMESDS/SALOMESDS_Transaction.cxx +++ b/src/SALOMESDS/SALOMESDS_Transaction.cxx @@ -21,6 +21,8 @@ #include "SALOMESDS_Transaction.hxx" #include "SALOMESDS_Exception.hxx" #include "SALOMESDS_PickelizedPyObjServer.hxx" +#include "SALOMESDS_PickelizedPyObjRdWrServer.hxx" +#include "SALOMESDS_PickelizedPyObjRdExtServer.hxx" #include @@ -64,7 +66,7 @@ void TransactionVarCreate::rollBack() } /*! - TODO : To be implemented. + * no implementation it is not a bug ! */ void TransactionVarCreate::notify() { @@ -169,7 +171,7 @@ void TransactionRemoveKeyInVarErrorIfNotAlreadyExisting::perform() } /*! - * not implementation it is not a bug ! + * no implementation it is not a bug ! */ void TransactionRemoveKeyInVarErrorIfNotAlreadyExisting::notify() { @@ -179,3 +181,46 @@ TransactionRemoveKeyInVarErrorIfNotAlreadyExisting::~TransactionRemoveKeyInVarEr { Py_XDECREF(_key); } + +TransactionMorphRdWrIntoRdOnly::TransactionMorphRdWrIntoRdOnly(DataScopeServerTransaction *dsct, const std::string& varName):Transaction(dsct,varName) +{ +} + +SALOME::PickelizedPyObjRdWrServer_ptr TransactionMorphRdWrIntoRdOnly::getVar() +{ + SALOME::BasicDataServer_var obj(_dsct->retrieveVarInternal(_var_name.c_str())); + SALOME::PickelizedPyObjRdWrServer_ptr ret(SALOME::PickelizedPyObjRdWrServer::_narrow(obj)); + if(CORBA::is_nil(ret)) + { + std::ostringstream oss; oss << "TransactionMorphRdWrIntoRdOnly::getVar : var \"" << _var_name << "\" has not expected PickelizedPyObjRdWrServer type !"; + throw Exception(oss.str()); + } + return ret; +} + +void TransactionMorphRdWrIntoRdOnly::prepareRollBackInCaseOfFailure() +{ + BasicDataServer *var(_dsct->retrieveVarInternal2(_var_name)); + if(!var) + throw Exception("TransactionMorphRdWrIntoRdOnly::prepareRollBackInCaseOfFailure : Returned var is NULL !"); + PickelizedPyObjRdWrServer *varc(dynamic_cast(var)); + if(!varc) + throw Exception("TransactionMorphRdWrIntoRdOnly::prepareRollBackInCaseOfFailure : Returned var has not expected type !"); +} + +void TransactionMorphRdWrIntoRdOnly::perform() +{ + _dsct->moveStatusOfVarFromRdWrToRdOnly(_var_name); +} + +void TransactionMorphRdWrIntoRdOnly::rollBack() +{ + _dsct->moveStatusOfVarFromRdOnlyToRdWr(_var_name); +} + +/*! + * no implementation it is not a bug ! + */ +void TransactionMorphRdWrIntoRdOnly::notify() +{ +} diff --git a/src/SALOMESDS/SALOMESDS_Transaction.hxx b/src/SALOMESDS/SALOMESDS_Transaction.hxx index 2bed22478..4fad07b05 100644 --- a/src/SALOMESDS/SALOMESDS_Transaction.hxx +++ b/src/SALOMESDS/SALOMESDS_Transaction.hxx @@ -34,6 +34,8 @@ namespace SALOMESDS { class PickelizedPyObjServer; + class PickelizedPyObjRdWrServer; + class PickelizedPyObjRdExtServer; class SALOMESDS_EXPORT Transaction : public virtual POA_SALOME::Transaction, public POAHolder { @@ -138,6 +140,19 @@ namespace SALOMESDS private: PyObject *_key; }; + + class TransactionMorphRdWrIntoRdOnly : public Transaction, public virtual POA_SALOME::TransactionRdWrAccess + { + public: + TransactionMorphRdWrIntoRdOnly(DataScopeServerTransaction *dsct, const std::string& varName); + public: + SALOME::PickelizedPyObjRdWrServer_ptr getVar(); + public: + void prepareRollBackInCaseOfFailure(); + void perform(); + void rollBack(); + void notify(); + }; } #endif diff --git a/src/SALOMESDS/SALOME_DataScopeServer.cxx b/src/SALOMESDS/SALOME_DataScopeServer.cxx index de6790b1f..11dca2cec 100644 --- a/src/SALOMESDS/SALOME_DataScopeServer.cxx +++ b/src/SALOMESDS/SALOME_DataScopeServer.cxx @@ -41,11 +41,15 @@ int main(int argc, char *argv[]) PortableServer::POA_var poa(PortableServer::POA::_narrow(obj)); PortableServer::POAManager_var mgr(poa->the_POAManager()); mgr->activate(); + // + SALOMESDS::DataScopeKiller *killer(new SALOMESDS::DataScopeKiller(orb)); + SALOME::DataScopeKiller_var killerObj(killer->_this()); + // SALOMESDS::DataScopeServerBase *server(0); if(!isTransac) - server=new SALOMESDS::DataScopeServer(orb,scopeName); + server=new SALOMESDS::DataScopeServer(orb,killerObj,scopeName); else - server=new SALOMESDS::DataScopeServerTransaction(orb,scopeName); + server=new SALOMESDS::DataScopeServerTransaction(orb,killerObj,scopeName); // CORBA::PolicyList policies; policies.length(1); @@ -62,7 +66,7 @@ int main(int argc, char *argv[]) server->registerInNS(serverPtr); // orb->run(); - server->_remove_ref(); + delete killer; return 0; } diff --git a/src/SALOMESDS/SalomeSDSClt.py b/src/SALOMESDS/SalomeSDSClt.py index 48eac9d8c..8c92e6686 100644 --- a/src/SALOMESDS/SalomeSDSClt.py +++ b/src/SALOMESDS/SalomeSDSClt.py @@ -39,7 +39,7 @@ class InvokatorPossibleStyle(InvokatorStyle): @classmethod def IsOK(cls,varPtr): - return isinstance(varPtr,SALOME._objref_PickelizedPyObjRdExtServer) + return isinstance(varPtr,SALOME._objref_PickelizedPyObjRdExtServer) or isinstance(varPtr,SALOME._objref_PickelizedPyObjRdWrServer) pass class InvokatorImpossibleStyle(InvokatorStyle): diff --git a/src/SALOMESDS/TestSalomeSDS.py b/src/SALOMESDS/TestSalomeSDS.py index dc779c77a..c916d19c2 100644 --- a/src/SALOMESDS/TestSalomeSDS.py +++ b/src/SALOMESDS/TestSalomeSDS.py @@ -113,9 +113,11 @@ class SalomeSDSTest(unittest.TestCase): dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName) self.assertTrue(isCreated) # - t0=dss.createRdExtVarTransac(varName,obj2Str({"ab":[4,5,6]})) + t0=dss.createRdWrVarTransac(varName,obj2Str({"ab":[4,5,6]})) dss.atomicApply([t0]) # + self.assertEqual(dss.getAccessOfVar(varName),"RdWr") + # t1=dss.addKeyValueInVarHard(varName,obj2Str("cd"),obj2Str([7,8,9,10])) dss.atomicApply([t1]) # @@ -142,6 +144,8 @@ class SalomeSDSTest(unittest.TestCase): t0=dss.createRdExtVarTransac(varName,obj2Str({"ab":[4,5,6]})) dss.atomicApply([t0]) # + self.assertEqual(dss.getAccessOfVar(varName),"RdExt") + # self.assertRaises(SALOME.SALOME_Exception,dss.addKeyValueInVarErrorIfAlreadyExisting,varName,obj2Str("ab"),obj2Str([7,8,9,10]))#raises because ab is already a key ! t1=dss.addKeyValueInVarErrorIfAlreadyExisting(varName,obj2Str("cd"),obj2Str([7,8,9,10])) dss.atomicApply([t1]) @@ -160,7 +164,7 @@ class SalomeSDSTest(unittest.TestCase): dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName) self.assertTrue(isCreated) # - t0=dss.createRdExtVarTransac(varName,obj2Str({"ab":[4,5,6]})) + t0=dss.createRdWrVarTransac(varName,obj2Str({"ab":[4,5,6]})) dss.atomicApply([t0]) # t1=dss.addKeyValueInVarErrorIfAlreadyExisting(varName,obj2Str("cd"),obj2Str([7,8,9,10])) @@ -182,7 +186,7 @@ class SalomeSDSTest(unittest.TestCase): dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName) self.assertTrue(isCreated) # - t0=dss.createRdExtVarTransac(varName,obj2Str({"ab":[4,5,6]})) + t0=dss.createRdWrVarTransac(varName,obj2Str({"ab":[4,5,6]})) dss.atomicApply([t0]) # t1=dss.addKeyValueInVarHard(varName,obj2Str("cd"),obj2Str([7,8,9,10])) @@ -218,6 +222,52 @@ class SalomeSDSTest(unittest.TestCase): keys=[str2Obj(elt) for elt in dss.getAllKeysOfVarWithTypeDict(varName)] self.assertEqual(keys,['ab','cd']) + def testTransaction6(self): + """ Test to test RdWr global vars with transaction""" + scopeName="Scope1" + varName="a" + dsm=salome.naming_service.Resolve("/DataServerManager") + dsm.cleanScopesInNS() + if scopeName in dsm.listScopes(): + dsm.removeDataScope(scopeName) + dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName) + self.assertTrue(isCreated) + # + t0=dss.createWorkingVarTransac(varName,obj2Str({})) + a=SalomeSDSClt.GetHandlerFromRef(t0.getVar()) + self.assertEqual(dss.getAccessOfVar(varName),"RdWr") + # play + a["ab"]=4 + self.assertEqual(a.local_copy(),{"ab":4}) + a["cd"]=[5] + self.assertEqual(a.local_copy(),{"ab":4,"cd":[5]}) + a["cd"].append(77) + self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77]}) + a.__setitem__("ef",["a","bb"]) + self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77],"ef":["a","bb"]}) + a["ef"].append("ccc") + self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77],"ef":["a","bb","ccc"]}) + a["gh"]=a + self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77],"ef":["a","bb","ccc"],"gh":{"ab":4,"cd":[5,77],"ef":["a","bb","ccc"]}}) + a["gh"]["cd"].append(99) ; a["cd"].append(88) + self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77,88],"ef":["a","bb","ccc"],"gh":{"ab":4,"cd":[5,77,99],"ef":["a","bb","ccc"]}}) + # WARNING here not problem to overwrite + a["gh"]=7 + self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77,88],"ef":["a","bb","ccc"],"gh":7}) + # end of play + self.assertTrue(isinstance(a,SalomeSDSClt.Dict)) + self.assertTrue(isinstance(a,SalomeSDSClt.WrappedType))# important for EEM + # commit : RdWr->RdOnly + dss.atomicApply([t0]) + # + self.assertEqual(dss.getAccessOfVar(varName),"RdOnly") # after atomicApply the var is readOnly. Impossible to change its value ! + self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),{"ab":4,"cd":[5,77,88],"ef":["a","bb","ccc"],"gh":7}) + dsm.cleanScopesInNS() + del a # very important kill Ref before removingDataScope... + if scopeName in dsm.listScopes(): + dsm.removeDataScope(scopeName) + pass + def setUp(self): salome.salome_init() pass