From fcccf7280f9882621a81cb6349a398010887e489 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Fri, 17 Jul 2015 18:02:44 +0200 Subject: [PATCH] to be continued... --- src/SALOMESDS/SALOMESDS_BasicDataServer.hxx | 1 + src/SALOMESDS/SALOMESDS_DataScopeServer.cxx | 4 +-- src/SALOMESDS/SALOMESDS_KeyWaiter.cxx | 35 ++++++++++++++++--- src/SALOMESDS/SALOMESDS_KeyWaiter.hxx | 10 ++++-- .../SALOMESDS_PickelizedPyObjServer.cxx | 10 ++++-- .../SALOMESDS_PickelizedPyObjServer.hxx | 2 ++ 6 files changed, 50 insertions(+), 12 deletions(-) diff --git a/src/SALOMESDS/SALOMESDS_BasicDataServer.hxx b/src/SALOMESDS/SALOMESDS_BasicDataServer.hxx index 7d127973c..7a22300ef 100644 --- a/src/SALOMESDS/SALOMESDS_BasicDataServer.hxx +++ b/src/SALOMESDS/SALOMESDS_BasicDataServer.hxx @@ -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; diff --git a/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx b/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx index 38b923393..1369d70fd 100644 --- a/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx +++ b/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx @@ -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); } diff --git a/src/SALOMESDS/SALOMESDS_KeyWaiter.cxx b/src/SALOMESDS/SALOMESDS_KeyWaiter.cxx index aead15337..8640ccee2 100644 --- a/src/SALOMESDS/SALOMESDS_KeyWaiter.cxx +++ b/src/SALOMESDS/SALOMESDS_KeyWaiter.cxx @@ -24,12 +24,14 @@ 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(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; } diff --git a/src/SALOMESDS/SALOMESDS_KeyWaiter.hxx b/src/SALOMESDS/SALOMESDS_KeyWaiter.hxx index f1a6f4685..456d29220 100644 --- a/src/SALOMESDS/SALOMESDS_KeyWaiter.hxx +++ b/src/SALOMESDS/SALOMESDS_KeyWaiter.hxx @@ -26,22 +26,26 @@ #include "SALOMESDS_Defines.hxx" #include "SALOMESDS_AutoRefCountPtr.hxx" +#include "SALOMESDS_DataScopeServer.hxx" +#include "SALOMESDS_PickelizedPyObjServer.hxx" #include 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(_dst->getFather()); }//thanks to dynamic_cast in constructor + private: + PickelizedPyObjServer *_dst; PyObject *_ze_key; PyObject *_ze_value; }; diff --git a/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.cxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.cxx index d0ef1e96f..03e9e6900 100644 --- a/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.cxx +++ b/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.cxx @@ -138,12 +138,12 @@ PyObject *PickelizedPyObjServer::getPyObjFromPickled(const std::vectorgetPickler(),"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) { diff --git a/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.hxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.hxx index 968339b8c..8c856997d 100644 --- a/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.hxx +++ b/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.hxx @@ -43,11 +43,13 @@ namespace SALOMESDS public: bool isDict(); void addKeyValueHard(const std::vector& key, const std::vector& 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& pickledData, DataScopeServerBase *dsb); + static std::string Pickelize(PyObject *obj, DataScopeServerBase *dsb); PyObject *getPyObjFromPickled(const std::string& pickledData); PyObject *getPyObjFromPickled(const std::vector& pickledData); std::string pickelize(PyObject *obj); -- 2.39.2