void UnRegister();
void Destroy();
public:
+ DataScopeServerBase *getFather() const { return _father; }
std::string getVarNameCpp() const { return _var_name; }
protected:
PortableServer::POA_var getPOA() const;
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);
}
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));
//
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);
}
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;
}
#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;
};
}
//! 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);
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)
{
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);