From: Anthony Geay Date: Mon, 20 Jul 2015 08:07:37 +0000 (+0200) Subject: On the road again. X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=9f9e142d7ed308feaab8673c36b5eef9c1887d82;p=modules%2Fkernel.git On the road again. --- diff --git a/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx b/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx index 1369d70fd..e07d72ddc 100644 --- a/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx +++ b/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx @@ -401,6 +401,39 @@ SALOME::Transaction_ptr DataScopeServerTransaction::createRdWrVarTransac(const c return SALOME::Transaction::_narrow(obj); } +void DataScopeServerTransaction::addWaitKey(KeyWaiter *kw) +{ + if(!kw) + throw Exception("DataScopeServerTransaction::addWaitKey : NULL input object !"); + _waiting_keys.push_back(kw); +} + +void DataScopeServerTransaction::pingKey(PyObject *keyObj) +{ + PyObject *cmpObj(getPyCmpFunc()); + if(!keyObj) + throw Exception("Key Object is NULL !"); + PyObject *args(PyTuple_New(2)); + PyTuple_SetItem(args,0,keyObj); Py_XINCREF(keyObj); + std::size_t ii(0); + for(std::list< KeyWaiter *>::iterator it=_waiting_keys.begin();it!=_waiting_keys.end();it++,ii++) + { + PyObject *waitKey((*it)->getKeyPyObj()); + PyTuple_SetItem(args,1,waitKey); Py_XINCREF(waitKey); + PyObject *res(PyObject_CallObject(cmpObj,args)); + if(res==NULL) + { + std::ostringstream oss; oss << "DataScopeServerTransaction::pingKey : for object id #" << ii << " error during cmp(k,wk[i]) !"; + throw Exception(oss.str()); + } + Py_XDECREF(res); + } +} + +void DataScopeServerTransaction::notifyKey(PyObject *keyObj, PyObject *valueObj) +{ +} + SALOME::Transaction_ptr DataScopeServerTransaction::addKeyValueInVarHard(const char *varName, const SALOME::ByteVec& key, const SALOME::ByteVec& value) { checkNotAlreadyExistingVar(varName); @@ -470,6 +503,23 @@ void DataScopeServerTransaction::atomicApply(const SALOME::ListOfTransaction& tr transactionsCpp[i]->notify(); } +/*! + * Returns borrowed reference. + */ +PyObject *DataScopeServerTransaction::getPyCmpFunc() +{ + PyObject *builtins(PyDict_GetItemString(_globals,"__builtins__"));//borrowed + if(builtins==NULL) + throw Exception("Fail to find reference to builtins !"); + PyObject *builtins2(PyModule_GetDict(builtins));//borrowed + if(builtins2==NULL) + throw Exception("Fail to invoke __dict__ on builtins !"); + PyObject *cmpObj(PyDict_GetItemString(builtins2,"cmp")); + if(cmpObj==NULL) + throw Exception("Fail to find cmp in __builtins__ !"); + return cmpObj; +} + DataScopeServerTransaction::~DataScopeServerTransaction() { } diff --git a/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx b/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx index 749fcae9f..cd575defd 100644 --- a/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx +++ b/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx @@ -37,6 +37,7 @@ namespace SALOMESDS { + class KeyWaiter; class PickelizedPyObjServer; class SALOMESDS_EXPORT DataScopeServerBase : public virtual POA_SALOME::DataScopeServerBase, public POAHolder @@ -104,6 +105,9 @@ namespace SALOMESDS void createRdExtVarInternal(const std::string& varName, const SALOME::ByteVec& constValue); void createRdWrVarInternal(const std::string& varName, const SALOME::ByteVec& constValue); PortableServer::POA_var getPOA4KeyWaiter() const { return _poa_for_key_waiter; } + void addWaitKey(KeyWaiter *kw); + void pingKey(PyObject *keyObj); + void notifyKey(PyObject *keyObj, PyObject *valueObj); public://remotely callable SALOME::ByteVec *fetchSerializedContent(const char *varName); SALOME::Transaction_ptr createRdOnlyVarTransac(const char *varName, const SALOME::ByteVec& constValue); @@ -112,8 +116,11 @@ namespace SALOMESDS SALOME::Transaction_ptr addKeyValueInVarHard(const char *varName, const SALOME::ByteVec& key, const SALOME::ByteVec& value); SALOME::KeyWaiter_ptr waitForKeyInVar(const char *varName, const SALOME::ByteVec& keyVal); void atomicApply(const SALOME::ListOfTransaction& transactions); + private: + PyObject *getPyCmpFunc(); private: PortableServer::POA_var _poa_for_key_waiter; + std::list< KeyWaiter * > _waiting_keys; }; /* diff --git a/src/SALOMESDS/SALOMESDS_KeyWaiter.cxx b/src/SALOMESDS/SALOMESDS_KeyWaiter.cxx index 8640ccee2..ff5348662 100644 --- a/src/SALOMESDS/SALOMESDS_KeyWaiter.cxx +++ b/src/SALOMESDS/SALOMESDS_KeyWaiter.cxx @@ -54,7 +54,7 @@ KeyWaiter::KeyWaiter(PickelizedPyObjServer *dst, const SALOME::ByteVec& keyVal): } else { - //dst->addWaiter(); + getDSS()->addWaitKey(this); } Py_XDECREF(retPy); } diff --git a/src/SALOMESDS/SALOMESDS_KeyWaiter.hxx b/src/SALOMESDS/SALOMESDS_KeyWaiter.hxx index 456d29220..d5f09b4bc 100644 --- a/src/SALOMESDS/SALOMESDS_KeyWaiter.hxx +++ b/src/SALOMESDS/SALOMESDS_KeyWaiter.hxx @@ -39,6 +39,7 @@ namespace SALOMESDS { public: KeyWaiter(PickelizedPyObjServer *dst, const SALOME::ByteVec& keyVal); + PyObject *getKeyPyObj() const { return _ze_key; } virtual ~KeyWaiter(); PortableServer::POA_var getPOA() const; SALOME::ByteVec *waitFor(); diff --git a/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.cxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.cxx index 03e9e6900..f773a32fc 100644 --- a/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.cxx +++ b/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.cxx @@ -60,15 +60,11 @@ bool PickelizedPyObjServer::isDict() return false; } -void PickelizedPyObjServer::addKeyValueHard(const std::vector& key, const std::vector& value) +void PickelizedPyObjServer::addKeyValueHard(PyObject *key, PyObject *value) { if(!isDict()) throw Exception("PickelizedPyObjServer::addKeyValueHard : not a dict !"); - PyObject *k(getPyObjFromPickled(key)); - PyObject *v(getPyObjFromPickled(value)); - bool isOK(PyDict_SetItem(_self,k,v)==0); - Py_XDECREF(k); - Py_XDECREF(v); + bool isOK(PyDict_SetItem(_self,key,value)==0); if(!isOK) throw Exception("PickelizedPyObjServer::addKeyValueHard : error when trying to add key,value to dict !"); } diff --git a/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.hxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.hxx index 8c856997d..3e77f546c 100644 --- a/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.hxx +++ b/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.hxx @@ -42,7 +42,7 @@ namespace SALOMESDS SALOME::ByteVec *fetchSerializedContent(); public: bool isDict(); - void addKeyValueHard(const std::vector& key, const std::vector& value); + void addKeyValueHard(PyObject *key, PyObject *value); PyObject *getPyObj() const { return _self; } public: static void FromByteSeqToCpp(const SALOME::ByteVec& bsToBeConv, std::string& ret); diff --git a/src/SALOMESDS/SALOMESDS_Transaction.cxx b/src/SALOMESDS/SALOMESDS_Transaction.cxx index 7809157b0..0bceafbbb 100644 --- a/src/SALOMESDS/SALOMESDS_Transaction.cxx +++ b/src/SALOMESDS/SALOMESDS_Transaction.cxx @@ -93,8 +93,11 @@ void TransactionRdWrVarCreate::perform() TransactionAddKeyValueHard::TransactionAddKeyValueHard(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& key, const SALOME::ByteVec& value):Transaction(dsct,varName),_varc(0) { - FromByteSeqToVB(key,_key); - FromByteSeqToVB(value,_value); + std::vector key2,value2; + FromByteSeqToVB(key,key2); + FromByteSeqToVB(value,value2); + _key=PickelizedPyObjServer::GetPyObjFromPickled(key2,_dsct); + _value=PickelizedPyObjServer::GetPyObjFromPickled(value2,_dsct); } void TransactionAddKeyValueHard::prepareRollBackInCaseOfFailure() @@ -104,6 +107,7 @@ void TransactionAddKeyValueHard::prepareRollBackInCaseOfFailure() _zeDataBefore.clear(); SALOME::ByteVec *zeDataBefore(_varc->fetchSerializedContent()); PickelizedPyObjServer::FromByteSeqToCpp(*zeDataBefore,_zeDataBefore); + _dsct->pingKey(_key);// check that key is OK with all waiting keys } void TransactionAddKeyValueHard::perform() @@ -118,13 +122,13 @@ void TransactionAddKeyValueHard::rollBack() _zeDataBefore.clear(); } -/*! - TODO : To be implemented. - */ void TransactionAddKeyValueHard::notify() { + _dsct->notifyKey(_key,_value); } TransactionAddKeyValueHard::~TransactionAddKeyValueHard() { + Py_XDECREF(_key); + Py_XDECREF(_value); } diff --git a/src/SALOMESDS/SALOMESDS_Transaction.hxx b/src/SALOMESDS/SALOMESDS_Transaction.hxx index 37e37f2bc..5024331c2 100644 --- a/src/SALOMESDS/SALOMESDS_Transaction.hxx +++ b/src/SALOMESDS/SALOMESDS_Transaction.hxx @@ -101,8 +101,8 @@ namespace SALOMESDS void notify(); ~TransactionAddKeyValueHard(); private: - std::vector _key; - std::vector _value; + PyObject *_key; + PyObject *_value; std::string _zeDataBefore; PickelizedPyObjServer *_varc; };