From b2c915999383be11960317a3652648d4c609ad12 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Wed, 28 Aug 2019 13:57:29 +0200 Subject: [PATCH] new SDS service to give access only of a value associated to key into a dict --- idl/SALOME_SDS.idl | 1 + src/SALOMESDS/SALOMESDS_DataScopeServer.cxx | 29 +++++++++++++++++++++ src/SALOMESDS/SALOMESDS_DataScopeServer.hxx | 1 + 3 files changed, 31 insertions(+) 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(); -- 2.39.2