]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
On the road again.
authorAnthony Geay <anthony.geay@edf.fr>
Mon, 20 Jul 2015 08:07:37 +0000 (10:07 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Mon, 20 Jul 2015 08:07:37 +0000 (10:07 +0200)
src/SALOMESDS/SALOMESDS_DataScopeServer.cxx
src/SALOMESDS/SALOMESDS_DataScopeServer.hxx
src/SALOMESDS/SALOMESDS_KeyWaiter.cxx
src/SALOMESDS/SALOMESDS_KeyWaiter.hxx
src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.cxx
src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.hxx
src/SALOMESDS/SALOMESDS_Transaction.cxx
src/SALOMESDS/SALOMESDS_Transaction.hxx

index 1369d70fd1d6252ff38a05713b24b8964c075964..e07d72ddc4b4d48ee25729a413f7edab3442f3e1 100644 (file)
@@ -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()
 {
 }
index 749fcae9fe387f05efe5d5fefcd743e7f6bdf439..cd575defd720dfe05785fa6430977e5d7ff0f666 100644 (file)
@@ -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;
   };
   
   /*
index 8640ccee23a5b9cbdc6f499aa6f6178341372036..ff5348662de3acce342c4bc9e78f260341bbcdf1 100644 (file)
@@ -54,7 +54,7 @@ KeyWaiter::KeyWaiter(PickelizedPyObjServer *dst, const SALOME::ByteVec& keyVal):
     }
   else
     {
-      //dst->addWaiter();
+      getDSS()->addWaitKey(this);
     }
   Py_XDECREF(retPy);
 }
index 456d292207a6dd417bc0ca1f4e78188b6123715c..d5f09b4bcf040521e5071ab94c683f214f205cc0 100644 (file)
@@ -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();
index 03e9e6900edf23a3cce87d9146401fa23f4ec5d0..f773a32fc6c2bf61e474a60a9f26fa81092af7ea 100644 (file)
@@ -60,15 +60,11 @@ bool PickelizedPyObjServer::isDict()
     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 !");
 }
index 8c856997dabdafc3e23b981c68ef7f694c43611d..3e77f546ce62aac52b311f41bd1ec55cc871288b 100644 (file)
@@ -42,7 +42,7 @@ namespace SALOMESDS
     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);
index 7809157b00acc32a66ddcba499722b37a0fe3506..0bceafbbbf09d9ef211dadd39af3f8905c16bbf3 100644 (file)
@@ -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<unsigned char> 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);
 }
index 37e37f2bcaceb2c7eed3a39a656c8b2284e28a89..5024331c2b40396f38c8ba16d9cf880f2f2cd58f 100644 (file)
@@ -101,8 +101,8 @@ namespace SALOMESDS
     void notify();
     ~TransactionAddKeyValueHard();
   private:
-    std::vector<unsigned char> _key;
-    std::vector<unsigned char> _value;
+    PyObject *_key;
+    PyObject *_value;
     std::string _zeDataBefore;
     PickelizedPyObjServer *_varc;
   };