From: Anthony Geay Date: Wed, 28 Aug 2019 11:57:29 +0000 (+0200) Subject: new SDS service to give access only of a value associated to key into a dict X-Git-Tag: V9_4_0a1~4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b2c915999383be11960317a3652648d4c609ad12;p=modules%2Fkernel.git new SDS service to give access only of a value associated to key into a dict --- diff --git a/idl/SALOME_SDS.idl b/idl/SALOME_SDS.idl index 98447e142..39b5471cf 100644 --- a/idl/SALOME_SDS.idl +++ b/idl/SALOME_SDS.idl @@ -106,6 +106,7 @@ module SALOME 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); + ByteVec getValueOfVarWithTypeDict(in string varName, in ByteVec constKey) raises (SALOME::SALOME_Exception); void takeANap(in double napDurationInSec) raises (SALOME::SALOME_Exception); }; diff --git a/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx b/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx index cd10634f4..6b5fcbc53 100644 --- a/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx +++ b/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx @@ -242,6 +242,35 @@ SALOME::SeqOfByteVec *DataScopeServerBase::getAllKeysOfVarWithTypeDict(const cha return ret; } +SALOME::ByteVec *DataScopeServerBase::getValueOfVarWithTypeDict(const char *varName, const SALOME::ByteVec& constKey) +{ + BasicDataServer *var(retrieveVarInternal2(varName)); + PickelizedPyObjServer *varc(dynamic_cast(var)); + if(!varc) + { + std::ostringstream oss; oss << "DataScopeServerBase::getValueOfVarWithTypeDict : var \"" << varName << "\" exists but it is not serialized !"; + throw Exception(oss.str()); + } + if(!varc->isDict()) + { + std::ostringstream oss; oss << "DataScopeServerBase::getValueOfVarWithTypeDict : var \"" << varName << "\" exists but it is not a PyDict !"; + throw Exception(oss.str()); + } + // + std::string keyCpp; + PickelizedPyObjServer::FromByteSeqToCpp(constKey,keyCpp); + SALOME::AutoPyRef key(PickelizedPyObjServer::GetPyObjFromPickled(keyCpp,this)); + PyObject *value(PyDict_GetItem(varc->getPyObj(),key.get()));//borrowed + if(!value) + { + std::ostringstream oss; oss << "DataScopeServerBase::getValueOfVarWithTypeDict : var \"" << varName << "\" seems to not have key specified !"; + throw Exception(oss.str()); + } + Py_XINCREF(value); + std::string ret(PickelizedPyObjServer::Pickelize(value,this));//value is consumed + return PickelizedPyObjServer::FromCppToByteSeq(ret); +} + void DataScopeServerBase::takeANap(CORBA::Double napDurationInSec) { if(napDurationInSec<0.) diff --git a/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx b/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx index 9eb65b8ce..9b6b1a58a 100644 --- a/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx +++ b/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx @@ -85,6 +85,7 @@ namespace SALOMESDS CORBA::Boolean shutdownIfNotHostedByDSM(SALOME::DataScopeKiller_out killer); SALOME::ByteVec *fetchSerializedContent(const char *varName); SALOME::SeqOfByteVec *getAllKeysOfVarWithTypeDict(const char *varName); + SALOME::ByteVec *getValueOfVarWithTypeDict(const char *varName, const SALOME::ByteVec& constKey); void takeANap(CORBA::Double napDurationInSec); public: ~DataScopeServerBase();