From 432334fea9fe698091e7097fd268b6b16276168e Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Thu, 15 Jan 2015 16:43:37 +0100 Subject: [PATCH] Almost ready to be used. Valgrind OK on TestSalomeSDS2. --- idl/SALOME_SDS.idl | 4 + src/SALOMESDS/SALOMESDS_BasicDataServer.cxx | 11 +++ src/SALOMESDS/SALOMESDS_BasicDataServer.hxx | 3 + src/SALOMESDS/SALOMESDS_DataScopeServer.cxx | 59 +++++++------- src/SALOMESDS/SALOMESDS_DataScopeServer.hxx | 3 +- src/SALOMESDS/SALOMESDS_DataServerManager.cxx | 6 +- .../SALOMESDS_PickelizedPyObjRdExtServer.cxx | 48 +++++++++--- .../SALOMESDS_PickelizedPyObjRdExtServer.hxx | 7 +- .../SALOMESDS_PickelizedPyObjRdWrServer.cxx | 1 - .../SALOMESDS_PickelizedPyObjServer.cxx | 6 -- .../SALOMESDS_PickelizedPyObjServer.hxx | 3 - src/SALOMESDS/SalomeSDSClt.py | 12 +-- src/SALOMESDS/TestSalomeSDS2.py | 77 +++++++++++++++++++ 13 files changed, 179 insertions(+), 61 deletions(-) create mode 100644 src/SALOMESDS/TestSalomeSDS2.py diff --git a/idl/SALOME_SDS.idl b/idl/SALOME_SDS.idl index 61099d289..dd2782a40 100644 --- a/idl/SALOME_SDS.idl +++ b/idl/SALOME_SDS.idl @@ -26,8 +26,11 @@ module SALOME typedef sequence StringVec; typedef sequence ByteVec; + interface DataScopeServer; + interface BasicDataServer : GenericObj { + DataScopeServer getMyDataScopeServer(); string getVarName(); string getScopeName(); }; @@ -60,6 +63,7 @@ module SALOME string getScopeName(); StringVec listVars(); BasicDataServer retrieveVar(in string varName) raises (SALOME::SALOME_Exception); + void deleteVar(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); diff --git a/src/SALOMESDS/SALOMESDS_BasicDataServer.cxx b/src/SALOMESDS/SALOMESDS_BasicDataServer.cxx index 4d3e89151..00a639b34 100644 --- a/src/SALOMESDS/SALOMESDS_BasicDataServer.cxx +++ b/src/SALOMESDS/SALOMESDS_BasicDataServer.cxx @@ -30,6 +30,12 @@ BasicDataServer::BasicDataServer(DataScopeServer *father, const std::string& var { } +SALOME::DataScopeServer_ptr BasicDataServer::getMyDataScopeServer() +{ + CORBA::Object_var obj(getPOA()->servant_to_reference(_father)); + return SALOME::DataScopeServer::_narrow(obj); +} + /*! * Called remotely -> to protect against throw */ @@ -57,3 +63,8 @@ void BasicDataServer::Destroy() { enforcedRelease(); } + +PortableServer::POA_var BasicDataServer::getPOA() +{ + return _father->getPOA(); +} diff --git a/src/SALOMESDS/SALOMESDS_BasicDataServer.hxx b/src/SALOMESDS/SALOMESDS_BasicDataServer.hxx index e0ed15dbf..3115064c0 100644 --- a/src/SALOMESDS/SALOMESDS_BasicDataServer.hxx +++ b/src/SALOMESDS/SALOMESDS_BasicDataServer.hxx @@ -36,6 +36,7 @@ namespace SALOMESDS { public: BasicDataServer(DataScopeServer *father, const std::string& varName); + SALOME::DataScopeServer_ptr getMyDataScopeServer(); char *getVarName(); char *getScopeName(); public: @@ -44,6 +45,8 @@ namespace SALOMESDS void Destroy(); public: std::string getVarNameCpp() const { return _var_name; } + protected: + PortableServer::POA_var getPOA(); protected: DataScopeServer *_father; private: diff --git a/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx b/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx index d2ab4e605..3ff2e0479 100644 --- a/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx +++ b/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx @@ -80,7 +80,7 @@ SALOME::StringVec *DataScopeServer::listVars() SALOME::StringVec *ret(new SALOME::StringVec); std::size_t sz(_vars.size()); ret->length(sz); - std::list< std::pair< SALOME::BasicDataServer_var, AutoRefCountPtr > >::iterator it(_vars.begin()); + std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::iterator it(_vars.begin()); for(std::size_t i=0;i to protect against throw - */ SALOME::BasicDataServer_ptr DataScopeServer::retrieveVar(const char *varName) { std::string varNameCpp(varName); @@ -105,18 +102,35 @@ SALOME::BasicDataServer_ptr DataScopeServer::retrieveVar(const char *varName) throw Exception(oss.str()); } std::size_t pos(std::distance(allNames.begin(),it)); - std::list< std::pair< SALOME::BasicDataServer_var, AutoRefCountPtr > >::iterator it0(_vars.begin()); + std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::iterator it0(_vars.begin()); for(std::size_t i=0;i allNames(getAllVarNames()); + std::vector::iterator it(std::find(allNames.begin(),allNames.end(),varNameCpp)); + if(it==allNames.end()) + { + std::ostringstream oss; oss << "DataScopeServer::deleteVar : name \"" << varNameCpp << "\" 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()); + (*it0).first->UnRegister(); + _vars.erase(it0); +} + SALOME::PickelizedPyObjRdOnlyServer_ptr DataScopeServer::createRdOnlyVar(const char *varName, const SALOME::ByteVec& constValue) { std::string varNameCpp(varName); checkNotAlreadyExistingVar(varNameCpp); - AutoRefCountPtr tmp(new PickelizedPyObjRdOnlyServer(this,varNameCpp,constValue)); + PickelizedPyObjRdOnlyServer *tmp(new PickelizedPyObjRdOnlyServer(this,varNameCpp,constValue)); CORBA::Object_var ret(activateWithDedicatedPOA(tmp)); - std::pair< SALOME::BasicDataServer_var, AutoRefCountPtr > p(SALOME::BasicDataServer::_narrow(ret),DynamicCastSafe(tmp)); + std::pair< SALOME::BasicDataServer_var, BasicDataServer * > p(SALOME::BasicDataServer::_narrow(ret),tmp); _vars.push_back(p); return SALOME::PickelizedPyObjRdOnlyServer::_narrow(ret); } @@ -125,9 +139,9 @@ SALOME::PickelizedPyObjRdExtServer_ptr DataScopeServer::createRdExtVar(const cha { std::string varNameCpp(varName); checkNotAlreadyExistingVar(varNameCpp); - AutoRefCountPtr tmp(new PickelizedPyObjRdExtServer(this,varNameCpp,constValue)); + PickelizedPyObjRdExtServer *tmp(new PickelizedPyObjRdExtServer(this,varNameCpp,constValue)); CORBA::Object_var ret(activateWithDedicatedPOA(tmp)); - std::pair< SALOME::BasicDataServer_var, AutoRefCountPtr > p(SALOME::BasicDataServer::_narrow(ret),DynamicCastSafe(tmp)); + std::pair< SALOME::BasicDataServer_var, BasicDataServer * > p(SALOME::BasicDataServer::_narrow(ret),tmp); _vars.push_back(p); return SALOME::PickelizedPyObjRdExtServer::_narrow(ret); } @@ -139,9 +153,9 @@ SALOME::PickelizedPyObjRdWrServer_ptr DataScopeServer::createRdWrVar(const char { std::string varNameCpp(varName),typeNameCpp(typeName); checkNotAlreadyExistingVar(varNameCpp); - AutoRefCountPtr tmp(new PickelizedPyObjRdWrServer(this,typeNameCpp,varNameCpp)); + PickelizedPyObjRdWrServer *tmp(new PickelizedPyObjRdWrServer(this,typeNameCpp,varNameCpp)); CORBA::Object_var ret(activateWithDedicatedPOA(tmp)); - std::pair< SALOME::BasicDataServer_var, AutoRefCountPtr > p(SALOME::BasicDataServer::_narrow(ret),DynamicCastSafe(tmp)); + std::pair< SALOME::BasicDataServer_var, BasicDataServer * > p(SALOME::BasicDataServer::_narrow(ret),tmp); _vars.push_back(p); return SALOME::PickelizedPyObjRdWrServer::_narrow(ret); } @@ -231,7 +245,7 @@ std::vector< std::string > DataScopeServer::getAllVarNames() const { std::size_t sz(_vars.size()); std::vector ret(sz); - std::list< std::pair< SALOME::BasicDataServer_var, AutoRefCountPtr > >::const_iterator it(_vars.begin()); + std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::const_iterator it(_vars.begin()); for(std::size_t i=0;igetVarNameCpp(); return ret; @@ -239,23 +253,8 @@ std::vector< std::string > DataScopeServer::getAllVarNames() const CORBA::Object_var DataScopeServer::activateWithDedicatedPOA(BasicDataServer *ds) { - CORBA::Object_var obj(_orb->resolve_initial_references("RootPOA")); - PortableServer::POA_var rootPoa; - if(!CORBA::is_nil(obj)) - rootPoa=PortableServer::POA::_narrow(obj); - PortableServer::POAManager_var pman(rootPoa->the_POAManager()); - 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::string name(ds->getVarNameCpp()); - std::ostringstream oss; oss << "POA@" << name; - std::string zePOAName(oss.str()); - PortableServer::POA_var poa(rootPoa->create_POA(zePOAName.c_str(),pman,policies)); - threadPol->destroy(); - // - PortableServer::ObjectId_var id(poa->activate_object(ds)); - CORBA::Object_var ret(poa->id_to_reference(id)); + PortableServer::ObjectId_var id(_poa->activate_object(ds)); + CORBA::Object_var ret(_poa->id_to_reference(id)); return ret; } @@ -265,7 +264,7 @@ void DataScopeServer::checkNotAlreadyExistingVar(const std::string& varName) std::vector::iterator it(std::find(allNames.begin(),allNames.end(),varName)); if(it!=allNames.end()) { - std::ostringstream oss; oss << "DataScopeServer::createGlobalStringVar : name \"" << varName << "\" already exists !"; + std::ostringstream oss; oss << "DataScopeServer::checkNotAlreadyExistingVar : name \"" << varName << "\" already exists !"; throw Exception(oss.str()); } } diff --git a/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx b/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx index 2f95251af..1147ba665 100644 --- a/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx +++ b/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx @@ -45,6 +45,7 @@ namespace SALOMESDS char *getScopeName(); SALOME::StringVec *listVars(); SALOME::BasicDataServer_ptr retrieveVar(const char *varName); + void deleteVar(const char *varName); SALOME::PickelizedPyObjRdOnlyServer_ptr createRdOnlyVar(const char *varName, const SALOME::ByteVec& constValue); SALOME::PickelizedPyObjRdExtServer_ptr createRdExtVar(const char *varName, const SALOME::ByteVec& constValue); SALOME::PickelizedPyObjRdWrServer_ptr createRdWrVar(const char *typeName, const char *varName); @@ -70,7 +71,7 @@ namespace SALOMESDS PortableServer::POA_var _poa; CORBA::ORB_var _orb; std::string _name; - std::list< std::pair< SALOME::BasicDataServer_var, AutoRefCountPtr > > _vars; + std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > > _vars; static std::size_t COUNTER; }; } diff --git a/src/SALOMESDS/SALOMESDS_DataServerManager.cxx b/src/SALOMESDS/SALOMESDS_DataServerManager.cxx index 0193b5076..003539143 100644 --- a/src/SALOMESDS/SALOMESDS_DataServerManager.cxx +++ b/src/SALOMESDS/SALOMESDS_DataServerManager.cxx @@ -119,10 +119,12 @@ SALOME::DataScopeServer_ptr DataServerManager::createDataScope(const char *scope // SALOME_NamingService ns(_orb); std::string fullScopeName(CreateAbsNameInNSFromScopeName(scopeName)); - std::ostringstream oss; oss << "SALOME_DataScopeServer" << " " << scopeName << " "; + std::ostringstream oss; oss << "valgrind --leak-check=yes SALOME_DataScopeServer" << " " << scopeName << " "; SALOME_ContainerManager::AddOmninamesParams(oss,&ns); std::string command(oss.str()); - SALOME_ContainerManager::MakeTheCommandToBeLaunchedASync(command); + //SALOME_ContainerManager::MakeTheCommandToBeLaunchedASync(command); + command+=" > err.log 2>&1 &"; + std::cerr << "************** " << command << std::endl; int status(SALOME_ContainerManager::SystemThreadSafe(command.c_str())); int count(SALOME_ContainerManager::GetTimeOutToLoaunchServer()); SALOME::DataScopeServer_var ret(SALOME::DataScopeServer::_nil()); diff --git a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.cxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.cxx index 752669d7d..5409851c0 100644 --- a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.cxx +++ b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.cxx @@ -47,10 +47,10 @@ SALOME::PickelizedPyObjRdExtServer_ptr PickelizedPyObjRdExtServer::invokePythonM { if(!_self) throw Exception("PickelizedPyObjRdExtServer::invokePythonMethodOn : self is NULL !"); - checkRdExtnessOf(method); std::string argsCpp; FromByteSeqToCpp(args,argsCpp); PyObject *argsPy(getPyObjFromPickled(argsCpp)); + checkRdExtnessOf(method,argsPy); // PyObject *selfMeth(PyObject_GetAttrString(_self,method)); if(!selfMeth) @@ -68,42 +68,70 @@ SALOME::PickelizedPyObjRdExtServer_ptr PickelizedPyObjRdExtServer::invokePythonM } PickelizedPyObjRdExtServer *ret(new PickelizedPyObjRdExtServer(_father,DataScopeServer::BuildTmpVarNameFrom(getVarNameCpp()),res)); PortableServer::POA_var poa(_father->getPOA()); - ret->setPOA(poa); PortableServer::ObjectId_var id(poa->activate_object(ret)); CORBA::Object_var obj(poa->id_to_reference(id)); return SALOME::PickelizedPyObjRdExtServer::_narrow(obj); } -void PickelizedPyObjRdExtServer::checkRdExtnessOf(const std::string& methodName) +void PickelizedPyObjRdExtServer::checkRdExtnessOf(const std::string& methodName, PyObject *argsPy) { if(!_self) - throw Exception("PickelizedPyObjRdExtServer::checkRdExtnessOf : self is NULL !"); + { + Py_XDECREF(argsPy); + throw Exception("PickelizedPyObjRdExtServer::checkRdExtnessOf : self is NULL !"); + } if(PyTuple_Check(_self)==1 || PyString_Check(_self)==1 || PyInt_Check(_self)==1 || PyBool_Check(_self)==1 || PyFloat_Check(_self)==1) return ;//_self is tuple, str, int or float -> immutable in python. So no method can break the RdExtness of _self. if(PyList_Check(_self)==1) - checkListRdExtnessOf(methodName); + checkListRdExtnessOf(methodName,argsPy); else if(PyDict_Check(_self)==1) - checkDictRdExtnessOf(methodName); + checkDictRdExtnessOf(methodName,argsPy); else throw Exception("PickelizedPyObjRdExtServer::checkRdExtnessOf : Supported python types are [list,tuple,dict,str,int,float] !"); } -void PickelizedPyObjRdExtServer::checkListRdExtnessOf(const std::string& methodName) +void PickelizedPyObjRdExtServer::checkListRdExtnessOf(const std::string& methodName, PyObject *argsPy) { static const char *THE_RDEXT_METH_OF_LIST[]={"__getitem__","append","extend","insert","reverse","sort"}; for(std::size_t i=0;i __setitem__ is NOT RdExt ! + Py_XDECREF(argsPy); + throw Exception("PickelizedPyObjRdExtServer::checkDictSetitemRdExtness : specified key of __setitem__ already exists ! RdExt property is not applied !"); + } +} diff --git a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.hxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.hxx index 293b64aa6..ea62b734e 100644 --- a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.hxx +++ b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.hxx @@ -38,9 +38,10 @@ namespace SALOMESDS ~PickelizedPyObjRdExtServer(); SALOME::PickelizedPyObjRdExtServer_ptr invokePythonMethodOn(const char *method, const SALOME::ByteVec& args); private: - void checkRdExtnessOf(const std::string& methodName); - void checkListRdExtnessOf(const std::string& methodName); - void checkDictRdExtnessOf(const std::string& methodName); + 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); }; } diff --git a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdWrServer.cxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdWrServer.cxx index 64459730f..848cefc16 100644 --- a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdWrServer.cxx +++ b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdWrServer.cxx @@ -104,7 +104,6 @@ SALOME::PickelizedPyObjRdWrServer_ptr PickelizedPyObjRdWrServer::invokePythonMet } PickelizedPyObjRdWrServer *ret(new PickelizedPyObjRdWrServer(_father,DataScopeServer::BuildTmpVarNameFrom(getVarNameCpp()),res)); PortableServer::POA_var poa(_father->getPOA()); - ret->setPOA(poa); PortableServer::ObjectId_var id(poa->activate_object(ret)); CORBA::Object_var obj(poa->id_to_reference(id)); return SALOME::PickelizedPyObjRdWrServer::_narrow(obj); diff --git a/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.cxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.cxx index 3cfa90d84..baba4b55d 100644 --- a/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.cxx +++ b/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.cxx @@ -40,7 +40,6 @@ PickelizedPyObjServer::PickelizedPyObjServer(DataScopeServer *father, const std: PickelizedPyObjServer::~PickelizedPyObjServer() { - std::cerr << "~~~~~~~~~~ PickelizedPyObjServer : " << getVarNameCpp() << std::endl; Py_XDECREF(_self); } @@ -53,11 +52,6 @@ SALOME::ByteVec *PickelizedPyObjServer::fetchSerializedContent() return FromCppToByteSeq(pickelize(_self)); } -PortableServer::POA_var PickelizedPyObjServer::getPOA() -{ - return _poa; -} - void PickelizedPyObjServer::FromByteSeqToCpp(const SALOME::ByteVec& bsToBeConv, std::string& ret) { std::size_t sz(bsToBeConv.length()); diff --git a/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.hxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.hxx index cc691bdb8..ba8af50b9 100644 --- a/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.hxx +++ b/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.hxx @@ -38,10 +38,7 @@ namespace SALOMESDS ~PickelizedPyObjServer(); void setSerializedContent(const SALOME::ByteVec& newValue); SALOME::ByteVec *fetchSerializedContent(); - public: - void setPOA(PortableServer::POA_var poa) { _poa=poa; } protected: - PortableServer::POA_var getPOA(); static void FromByteSeqToCpp(const SALOME::ByteVec& bsToBeConv, std::string& ret); static SALOME::ByteVec *FromCppToByteSeq(const std::string& strToBeConv); PyObject *getPyObjFromPickled(const std::string& pickledData); diff --git a/src/SALOMESDS/SalomeSDSClt.py b/src/SALOMESDS/SalomeSDSClt.py index 112602487..9b9218c62 100644 --- a/src/SALOMESDS/SalomeSDSClt.py +++ b/src/SALOMESDS/SalomeSDSClt.py @@ -24,7 +24,7 @@ import cPickle class WrappedType(object): def __init__(self,varPtr,isTemporaryVar=False): - assert(isinstance(varPtr,SALOME._objref_PickelizedPyObjRdWrServer)) + assert(isinstance(varPtr,SALOME._objref_PickelizedPyObjServer)) self._var_ptr=varPtr if not isTemporaryVar: self._var_ptr.Register() @@ -44,6 +44,7 @@ class WrappedType(object): return (self._wrapped_type,(self.local_copy(),)) def assign(self,elt): + assert(isinstance(self._var_ptr,SALOME._objref_PickelizedPyObjRdWrServer)) st=cPickle.dumps(elt,cPickle.HIGHEST_PROTOCOL) self._var_ptr.setSerializedContent(st) pass @@ -449,7 +450,7 @@ class String(WrappedType): class Caller: def __init__(self,varPtr,meth): - assert(isinstance(varPtr,SALOME._objref_PickelizedPyObjRdWrServer)) + assert(isinstance(varPtr,SALOME._objref_PickelizedPyObjServer)) self._var_ptr=varPtr self._meth=meth pass @@ -464,9 +465,10 @@ PyHandlerTypeMap={int:Int,float:Float,str:String,list:List,tuple:Tuple,dict:Dict def GetHandlerFromRef(objCorba,isTempVar=False): """ Returns a client that allows to handle a remote corba ref of a global var easily. """ - assert(isinstance(objCorba,SALOME._objref_PickelizedPyObjRdWrServer)) + assert(isinstance(objCorba,SALOME._objref_PickelizedPyObjServer)) v=cPickle.loads(objCorba.fetchSerializedContent()) if v is None: + objCorba.UnRegister() return None return PyHandlerTypeMap[v.__class__](objCorba,isTempVar) @@ -474,13 +476,13 @@ def GetHandlerFromRef(objCorba,isTempVar=False): def CreateRdOnlyGlobalVar(value,varName,scopeName): import salome dsm=salome.naming_service.Resolve("/DataServerManager") - d2s,isCreated=dsm.giveADataScopeCalled() + d2s,isCreated=dsm.giveADataScopeCalled(scopeName) return GetHandlerFromRef(d2s.createRdOnlyVar(varName,cPickle.dumps(value,cPickle.HIGHEST_PROTOCOL)),False) def CreateRdExtGlobalVar(value,varName,scopeName): import salome dsm=salome.naming_service.Resolve("/DataServerManager") - d2s,isCreated=dsm.giveADataScopeCalled() + d2s,isCreated=dsm.giveADataScopeCalled(scopeName) return GetHandlerFromRef(d2s.createRdExtVar(varName,cPickle.dumps(value,cPickle.HIGHEST_PROTOCOL)),False) def GetHandlerFromName(scopeName,varName): diff --git a/src/SALOMESDS/TestSalomeSDS2.py b/src/SALOMESDS/TestSalomeSDS2.py new file mode 100644 index 000000000..2ad849da6 --- /dev/null +++ b/src/SALOMESDS/TestSalomeSDS2.py @@ -0,0 +1,77 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2007-2014 CEA/DEN, EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# Author : Anthony Geay + +import SalomeSDSClt +import SALOME +import salome +import unittest +import gc + +class SalomeSDS2Test(unittest.TestCase): + + def testList1(self): + a=SalomeSDSClt.CreateRdExtGlobalVar([],"a","Scope0") + self.assertEqual(a.local_copy(),[]) + a.append(5) + self.assertEqual(a.local_copy(),[5]) + self.assertRaises(SALOME.SALOME_Exception,a.__delitem__,0) + a.append(["rt"]) + self.assertEqual(a.local_copy(),[5,["rt"]]) + a[1].append(8) + self.assertEqual(a.local_copy(),[5,["rt",8]]) + a.extend(a) + self.assertEqual(a.local_copy(),[5,["rt",8],5,["rt",8]]) + a.extend(a[3:]) + self.assertEqual(a.local_copy(),[5,["rt",8],5,["rt",8],["rt",8]]) + a[4].append(7) + self.assertEqual(a.local_copy(),[5,["rt",8],5,["rt",8],["rt",8,7]]) + a._var_ptr.getMyDataScopeServer().deleteVar("a") + pass + + def testDict1(self): + a=SalomeSDSClt.CreateRdExtGlobalVar({},"a","Scope0") + 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"]}) + self.assertRaises(SALOME.SALOME_Exception,a.__setitem__,"ef",["a","bb"]) + self.assertRaises(SALOME.SALOME_Exception,a.__setitem__,"ef",["a","bb","ccc"]) + 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"]}}) + a._var_ptr.getMyDataScopeServer().deleteVar("a") + pass + + def setUp(self): + salome.salome_init() + pass + + pass + +unittest.main() + -- 2.39.2