]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
to be continued...
authorAnthony Geay <anthony.geay@edf.fr>
Fri, 17 Jul 2015 16:02:44 +0000 (18:02 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Fri, 17 Jul 2015 16:02:44 +0000 (18:02 +0200)
src/SALOMESDS/SALOMESDS_BasicDataServer.hxx
src/SALOMESDS/SALOMESDS_DataScopeServer.cxx
src/SALOMESDS/SALOMESDS_KeyWaiter.cxx
src/SALOMESDS/SALOMESDS_KeyWaiter.hxx
src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.cxx
src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.hxx

index 7d127973cde0bb740313020631b17715ba520d66..7a22300efb9e2cfe4b4722706ddc194476b3c9e9 100644 (file)
@@ -44,6 +44,7 @@ namespace SALOMESDS
     void UnRegister();
     void Destroy();
   public:
+    DataScopeServerBase *getFather() const { return _father; }
     std::string getVarNameCpp() const { return _var_name; }
   protected:
     PortableServer::POA_var getPOA() const;
index 38b92339326a4c5a7039c31e2096d14fdb61e3f9..1369d70fd1d6252ff38a05713b24b8964c075964 100644 (file)
@@ -411,8 +411,8 @@ SALOME::Transaction_ptr DataScopeServerTransaction::addKeyValueInVarHard(const c
 
 SALOME::KeyWaiter_ptr DataScopeServerTransaction::waitForKeyInVar(const char *varName, const SALOME::ByteVec& keyVal)
 {
-  checkVarExistingAndDict(varName);
-  KeyWaiter *ret(new KeyWaiter(this,keyVal));
+  PickelizedPyObjServer *pickelObj(checkVarExistingAndDict(varName));
+  KeyWaiter *ret(new KeyWaiter(pickelObj,keyVal));
   CORBA::Object_var obj(ret->activate());
   return SALOME::KeyWaiter::_narrow(obj);
 }
index aead1533736825ee434a30e09ed7f46059ee5ef9..8640ccee23a5b9cbdc6f499aa6f6178341372036 100644 (file)
 
 using namespace SALOMESDS;
 
-KeyWaiter::KeyWaiter(DataScopeServerTransaction *dst, const SALOME::ByteVec& keyVal):_dst(dst),_ze_key(0),_ze_value(0)
+KeyWaiter::KeyWaiter(PickelizedPyObjServer *dst, const SALOME::ByteVec& keyVal):_dst(dst),_ze_key(0),_ze_value(0)
 {
+  if(!dynamic_cast<DataScopeServerTransaction *>(dst->getFather()))
+    throw Exception("KeyWaiter constructor : Invalid glob var ! Invalid DataScope hosting it ! DataScopeServerTransaction excpected !");
   std::string st;
   PickelizedPyObjServer::FromByteSeqToCpp(keyVal,st);
-  _ze_key=PickelizedPyObjServer::GetPyObjFromPickled(st,_dst);
-  PyObject *selfMeth(PyObject_GetAttrString(_dst->getPickler(),"__contains__"));
+  _ze_key=PickelizedPyObjServer::GetPyObjFromPickled(st,getDSS());
+  PyObject *selfMeth(PyObject_GetAttrString(_dst->getPyObj(),"__contains__"));
   PyObject *args(PyTuple_New(1));
   PyTuple_SetItem(args,0,_ze_key); Py_XINCREF(_ze_key); // _ze_key is stolen by PyTuple_SetItem
   PyObject *retPy(PyObject_CallObject(selfMeth,args));
@@ -38,7 +40,22 @@ KeyWaiter::KeyWaiter(DataScopeServerTransaction *dst, const SALOME::ByteVec& key
   //
   if(retPy!=Py_False && retPy!=Py_True)
     throw Exception("KeyWaiter constructor : unexpected return of dict.__contains__ !");
-  
+  if(retPy==Py_True)
+    {
+      selfMeth=PyObject_GetAttrString(_dst->getPyObj(),"__getitem__");
+      args=PyTuple_New(1);
+      PyTuple_SetItem(args,0,_ze_key); Py_XINCREF(_ze_key); // _ze_key is stolen by PyTuple_SetItem
+      retPy=PyObject_CallObject(selfMeth,args);
+      if(!retPy)
+        throw Exception("KeyWaiter constructor : dict.__contains__ says true but fails to return value !");
+      _ze_value=retPy;
+      Py_XDECREF(args);
+      Py_XDECREF(selfMeth);
+    }
+  else
+    {
+      //dst->addWaiter();
+    }
   Py_XDECREF(retPy);
 }
 
@@ -51,10 +68,18 @@ KeyWaiter::~KeyWaiter()
 
 PortableServer::POA_var KeyWaiter::getPOA() const
 {
-  return _dst->getPOA4KeyWaiter();
+  return getDSS()->getPOA4KeyWaiter();
 }
 
 SALOME::ByteVec *KeyWaiter::waitFor()
 {
+  if(_ze_value)
+    {
+      Py_XINCREF(_ze_value);
+      std::string st(PickelizedPyObjServer::Pickelize(_ze_value,_dst->getFather()));
+      return PickelizedPyObjServer::FromCppToByteSeq(st);
+    }
+  else
+    throw Exception("KeyWaiter::waitFor : not implemented yet !");
   return 0;
 }
index f1a6f4685a682e358138060fa35184f0009ceff5..456d292207a6dd417bc0ca1f4e78188b6123715c 100644 (file)
 
 #include "SALOMESDS_Defines.hxx"
 #include "SALOMESDS_AutoRefCountPtr.hxx"
+#include "SALOMESDS_DataScopeServer.hxx"
+#include "SALOMESDS_PickelizedPyObjServer.hxx"
 
 #include <Python.h>
 
 namespace SALOMESDS
 {
   class DataScopeServerTransaction;
-
+  
   class SALOMESDS_EXPORT KeyWaiter : public virtual POA_SALOME::KeyWaiter, public POAHolder
   {
   public:
-    KeyWaiter(DataScopeServerTransaction *dst, const SALOME::ByteVec& keyVal);
+    KeyWaiter(PickelizedPyObjServer *dst, const SALOME::ByteVec& keyVal);
     virtual ~KeyWaiter();
     PortableServer::POA_var getPOA() const;
     SALOME::ByteVec *waitFor();
   private:
-    DataScopeServerTransaction *_dst;
+    DataScopeServerTransaction *getDSS() const { return static_cast<DataScopeServerTransaction *>(_dst->getFather()); }//thanks to dynamic_cast in constructor
+  private:
+    PickelizedPyObjServer *_dst;
     PyObject *_ze_key;
     PyObject *_ze_value;
   };
index d0ef1e96fbab5d692b033068d68aea7b37af0fee..03e9e6900edf23a3cce87d9146401fa23f4ec5d0 100644 (file)
@@ -138,12 +138,12 @@ PyObject *PickelizedPyObjServer::getPyObjFromPickled(const std::vector<unsigned
 }
 
 //! obj is consumed by this method.
-std::string PickelizedPyObjServer::pickelize(PyObject *obj)
+std::string PickelizedPyObjServer::Pickelize(PyObject *obj, DataScopeServerBase *dsb)
 {
   PyObject *args(PyTuple_New(2));
   PyTuple_SetItem(args,0,obj);
   PyTuple_SetItem(args,1,PyInt_FromLong(2));// because "assert(cPickle.HIGHEST_PROTOCOL is 2)"
-  PyObject *selfMeth(PyObject_GetAttrString(_father->getPickler(),"dumps"));
+  PyObject *selfMeth(PyObject_GetAttrString(dsb->getPickler(),"dumps"));
   PyObject *retPy(PyObject_CallObject(selfMeth,args));
   Py_XDECREF(selfMeth);
   Py_XDECREF(args);
@@ -157,6 +157,12 @@ std::string PickelizedPyObjServer::pickelize(PyObject *obj)
   return ret;
 }
 
+//! obj is consumed by this method.
+std::string PickelizedPyObjServer::pickelize(PyObject *obj)
+{
+  return Pickelize(obj,_father);
+}
+
 //! obj is consumed by this method.
 void PickelizedPyObjServer::setNewPyObj(PyObject *obj)
 {
index 968339b8c0542038efd2077eeec1d7f4b415a065..8c856997dabdafc3e23b981c68ef7f694c43611d 100644 (file)
@@ -43,11 +43,13 @@ namespace SALOMESDS
   public:
     bool isDict();
     void addKeyValueHard(const std::vector<unsigned char>& key, const std::vector<unsigned char>& value);
+    PyObject *getPyObj() const { return _self; }
   public:
     static void FromByteSeqToCpp(const SALOME::ByteVec& bsToBeConv, std::string& ret);
     static SALOME::ByteVec *FromCppToByteSeq(const std::string& strToBeConv);
     static PyObject *GetPyObjFromPickled(const std::string& pickledData, DataScopeServerBase *dsb);
     static PyObject *GetPyObjFromPickled(const std::vector<unsigned char>& pickledData, DataScopeServerBase *dsb);
+    static std::string Pickelize(PyObject *obj, DataScopeServerBase *dsb);
     PyObject *getPyObjFromPickled(const std::string& pickledData);
     PyObject *getPyObjFromPickled(const std::vector<unsigned char>& pickledData);
     std::string pickelize(PyObject *obj);