]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
new SDS service to give access only of a value associated to key into a dict
authorAnthony Geay <anthony.geay@edf.fr>
Wed, 28 Aug 2019 11:57:29 +0000 (13:57 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Wed, 28 Aug 2019 11:57:29 +0000 (13:57 +0200)
idl/SALOME_SDS.idl
src/SALOMESDS/SALOMESDS_DataScopeServer.cxx
src/SALOMESDS/SALOMESDS_DataScopeServer.hxx

index 98447e142cdefe9e48d00bac867c9027bc38a104..39b5471cffd92378ab50c902db748e01dc995fa6 100644 (file)
@@ -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);
   };
 
index cd10634f48b7e5385430ee7ba7fd5153851dcfb1..6b5fcbc53870088bd2f02d4e6f3b7adc81b4cc17 100644 (file)
@@ -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<PickelizedPyObjServer *>(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.)
index 9eb65b8ce2a43fe8109786b1e9eb946b0bd3e7c0..9b6b1a58a3e15c6db230b9331e1f71bb3d074176 100644 (file)
@@ -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();