Salome HOME
python_test_driver.py declination of salome_test_driver.py for SSL mode (timeout...
[modules/kernel.git] / src / SALOMESDS / SALOMESDS_KeyWaiter.cxx
index a35830beef4dcbf8bd6e169027be04f3c9544a69..dbd6aaa624558226a799a45c73a1c39f4ad5267e 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -33,7 +33,7 @@ KeyWaiter::KeyWaiter(PickelizedPyObjServer *var, const SALOME::ByteVec& keyVal):
   if(!var)
     throw Exception("KeyWaiter constructor : Invalid glob var is NULL !");
   if(!dynamic_cast<DataScopeServerTransaction *>(var->getFather()))
-    throw Exception("KeyWaiter constructor : Invalid glob var ! Invalid DataScope hosting it ! DataScopeServerTransaction excpected !");
+    throw Exception("KeyWaiter constructor : Invalid glob var ! Invalid DataScope hosting it ! DataScopeServerTransaction expected !");
   std::string st;
   PickelizedPyObjServer::FromByteSeqToCpp(keyVal,st);
   _ze_key=PickelizedPyObjServer::GetPyObjFromPickled(st,getDSS());
@@ -78,28 +78,11 @@ PortableServer::POA_var KeyWaiter::getPOA() const
  * WARNING : here it is the single method that can be invoked in non SINGLE_THREAD POA.
  * So take care to do avoid collapses (especially in python).
  */
-SALOME::ByteVec *KeyWaiter::waitFor()
+void KeyWaiter::waitFor()
 {
   sem_wait(&_sem);
   if(!_ze_value)
     throw Exception("KeyWaiter::waitFor : internal error 1 !");
-  SALOME::ByteVec *ret(0);
-  {// this section is to guarantee that no concurrent threads are doing python stuff at the same time
-    // Here a pickelization is needed so to guarantee to be alone doing python action the idea is to invoke using monothread POA.
-    DataScopeServerTransaction *dss(getDSS());
-    PortableServer::POA_var poa(dss->getPOA());
-    CORBA::Object_var dssPtr(poa->servant_to_reference(dss));
-    SALOME::DataScopeServerTransaction_var dssPtr2(SALOME::DataScopeServerTransaction::_narrow(dssPtr));
-    if(CORBA::is_nil(dssPtr2))
-      throw Exception("KeyWaiter::waitFor : internal error 2 !");
-    CORBA::Object_var thisPtr(getPOA()->servant_to_reference(this));
-    SALOME::KeyWaiter_var thisPtr2(SALOME::KeyWaiter::_narrow(thisPtr));
-    if(CORBA::is_nil(thisPtr2))
-      throw Exception("KeyWaiter::waitFor : internal error 3 !");
-    ret=dssPtr2->waitForMonoThrRev(thisPtr2);//<- this invokation through SINGLE_THREAD POA here will guarantee thread safety
-  }
-  enforcedRelease();
-  return ret;
 }
 
 /*!
@@ -114,6 +97,19 @@ SALOME::ByteVec *KeyWaiter::waitForMonoThr()
   return PickelizedPyObjServer::FromCppToByteSeq(st);
 }
 
+SALOME::ByteVec *KeyWaiter::waitForAndKill()
+{
+  if(!_ze_value)
+    throw Exception("KeyWaiter::waitForAndKill : no value ! invalid call of this method !");
+  Py_XINCREF(_ze_value);
+  std::string st(PickelizedPyObjServer::Pickelize(_ze_value,_var->getFather()));
+  //
+  if(PyDict_DelItem(_var->getPyObj(),_ze_key)!=0)
+    throw Exception("KeyWaiter::waitForAndKill : error during entry removal !");
+  //
+  return PickelizedPyObjServer::FromCppToByteSeq(st);
+}
+
 /*!
  * WARNING call this method before calling go !
  */