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);
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()
{
}
namespace SALOMESDS
{
+ class KeyWaiter;
class PickelizedPyObjServer;
class SALOMESDS_EXPORT DataScopeServerBase : public virtual POA_SALOME::DataScopeServerBase, public POAHolder
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);
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;
};
/*
}
else
{
- //dst->addWaiter();
+ getDSS()->addWaitKey(this);
}
Py_XDECREF(retPy);
}
{
public:
KeyWaiter(PickelizedPyObjServer *dst, const SALOME::ByteVec& keyVal);
+ PyObject *getKeyPyObj() const { return _ze_key; }
virtual ~KeyWaiter();
PortableServer::POA_var getPOA() const;
SALOME::ByteVec *waitFor();
return false;
}
-void PickelizedPyObjServer::addKeyValueHard(const std::vector<unsigned char>& key, const std::vector<unsigned char>& 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 !");
}
SALOME::ByteVec *fetchSerializedContent();
public:
bool isDict();
- void addKeyValueHard(const std::vector<unsigned char>& key, const std::vector<unsigned char>& value);
+ void addKeyValueHard(PyObject *key, PyObject *value);
PyObject *getPyObj() const { return _self; }
public:
static void FromByteSeqToCpp(const SALOME::ByteVec& bsToBeConv, std::string& ret);
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<unsigned char> key2,value2;
+ FromByteSeqToVB(key,key2);
+ FromByteSeqToVB(value,value2);
+ _key=PickelizedPyObjServer::GetPyObjFromPickled(key2,_dsct);
+ _value=PickelizedPyObjServer::GetPyObjFromPickled(value2,_dsct);
}
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()
_zeDataBefore.clear();
}
-/*!
- TODO : To be implemented.
- */
void TransactionAddKeyValueHard::notify()
{
+ _dsct->notifyKey(_key,_value);
}
TransactionAddKeyValueHard::~TransactionAddKeyValueHard()
{
+ Py_XDECREF(_key);
+ Py_XDECREF(_value);
}
void notify();
~TransactionAddKeyValueHard();
private:
- std::vector<unsigned char> _key;
- std::vector<unsigned char> _value;
+ PyObject *_key;
+ PyObject *_value;
std::string _zeDataBefore;
PickelizedPyObjServer *_varc;
};