]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Nearly ready to implement wait.
authorAnthony Geay <anthony.geay@edf.fr>
Mon, 13 Jul 2015 16:01:54 +0000 (18:01 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Mon, 13 Jul 2015 16:01:54 +0000 (18:01 +0200)
idl/SALOME_SDS.idl
src/Launcher/SALOME_LauncherServer.cxx
src/SALOMESDS/SALOMESDS_DataScopeServer.cxx
src/SALOMESDS/SALOMESDS_DataScopeServer.hxx
src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.cxx
src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.hxx
src/SALOMESDS/SALOMESDS_Transaction.cxx
src/SALOMESDS/SALOMESDS_Transaction.hxx

index fac3ecdfba2a01aaf206de194eb0442bbc1b24c3..d5c5d4d15f904a86aa3a831bb7b3c89fe8cb7991 100644 (file)
@@ -63,13 +63,13 @@ module SALOME
     string getScopeName();
     StringVec listVars();
     boolean existVar(in string varName) raises (SALOME::SALOME_Exception);
-    BasicDataServer retrieveVar(in string varName) raises (SALOME::SALOME_Exception);
     void deleteVar(in string varName) raises (SALOME::SALOME_Exception);
     void shutdownIfNotHostedByDSM();
   };
 
   interface DataScopeServer : DataScopeServerBase
   {
+    BasicDataServer retrieveVar(in string varName) raises (SALOME::SALOME_Exception);
     PickelizedPyObjRdOnlyServer createRdOnlyVar(in string varName, in ByteVec constValue) raises (SALOME::SALOME_Exception);
     PickelizedPyObjRdExtServer createRdExtVar(in string varName, in ByteVec constValue) raises (SALOME::SALOME_Exception);
     //PickelizedPyObjRdWrServer createRdWrVar(in string typeName, in string varName) raises (SALOME::SALOME_Exception);
@@ -83,6 +83,7 @@ module SALOME
 
   interface DataScopeServerTransaction : DataScopeServerBase
   {
+    ByteVec fetchSerializedContent(in string varName) raises (SALOME::SALOME_Exception);
     Transaction createRdOnlyVarTransac(in string varName, in ByteVec constValue) raises (SALOME::SALOME_Exception);
     Transaction createRdExtVarTransac(in string varName, in ByteVec constValue) raises (SALOME::SALOME_Exception);
     Transaction createRdWrVarTransac(in string varName, in ByteVec constValue) raises (SALOME::SALOME_Exception);
index b5b87cdb1754c6cf320e594fee2fdb14c4c8ad65..d1ffcb03b1f57dc1b02dff69bcceb90995d806e0 100644 (file)
@@ -22,7 +22,6 @@
 
 #include "SALOME_Launcher.hxx"
 #include "SALOMESDS_DataServerManager.hxx"
-#include "SALOMESDS_TransactionFactory.hxx"
 #include "utilities.h"
 #include <sstream>
 #include <iostream>
@@ -103,9 +102,6 @@ int main(int argc, char* argv[])
       SALOMESDS::DataServerManager *dsm(new SALOMESDS::DataServerManager(argc,argv,orb,root_poa));
       dsm->_remove_ref();
       //
-      SALOMESDS::TransactionFactory *tf(new SALOMESDS::TransactionFactory(dsm));
-      tf->_remove_ref();
-      //
       orb->run();
       orb->destroy();
     }
index c08cfc2ee6bb30ed09809bb069b1c81697d24ec2..dace3b8faf2dd2e0046e2236807d96f7e101d549 100644 (file)
@@ -100,23 +100,18 @@ CORBA::Boolean DataScopeServerBase::existVar(const char *varName)
   return false;
 }
 
-SALOME::BasicDataServer_ptr DataScopeServerBase::retrieveVar(const char *varName)
+SALOME::BasicDataServer_ptr DataScopeServerBase::retrieveVarInternal(const char *varName)
 {
-  std::string varNameCpp(varName);
-  std::vector<std::string> allNames(getAllVarNames());
-  std::vector<std::string>::iterator it(std::find(allNames.begin(),allNames.end(),varNameCpp));
-  if(it==allNames.end())
-    {
-      std::ostringstream oss; oss << "DataScopeServerBase::retrieveVar : name \"" << varNameCpp << "\" does not exists ! Possibilities are :";
-      std::copy(allNames.begin(),allNames.end(),std::ostream_iterator<std::string>(oss,", "));
-      throw Exception(oss.str());
-    }
-  std::size_t pos(std::distance(allNames.begin(),it));
-  std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::iterator it0(_vars.begin());
-  for(std::size_t i=0;i<pos;i++,it0++);
+  std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::iterator it0(retrieveVarInternal3(varName));
   return SALOME::BasicDataServer::_duplicate((*it0).first);
 }
 
+BasicDataServer *DataScopeServerBase::retrieveVarInternal2(const std::string& varName)
+{
+  std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::iterator it0(retrieveVarInternal3(varName));
+  return (*it0).second;
+}
+
 void DataScopeServerBase::deleteVar(const char *varName)
 {
   std::string varNameCpp(varName);
@@ -243,6 +238,33 @@ void DataScopeServerBase::checkNotAlreadyExistingVar(const std::string& varName)
     }
 }
 
+void DataScopeServerBase::checkExistingVar(const std::string& varName)
+{
+  std::vector<std::string> allNames(getAllVarNames());
+  std::vector<std::string>::iterator it(std::find(allNames.begin(),allNames.end(),varName));
+  if(it==allNames.end())
+    {
+      std::ostringstream oss; oss << "DataScopeServerBase::checkExistingVar : name \"" << varName << "\" does not exist !";
+      throw Exception(oss.str());
+    }
+}
+
+std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::iterator DataScopeServerBase::retrieveVarInternal3(const std::string& varName)
+{
+  std::vector<std::string> allNames(getAllVarNames());
+  std::vector<std::string>::iterator it(std::find(allNames.begin(),allNames.end(),varName));
+  if(it==allNames.end())
+    {
+      std::ostringstream oss; oss << "DataScopeServerBase::retrieveVarInternal : name \"" << varName << "\" does not exists ! Possibilities are :";
+      std::copy(allNames.begin(),allNames.end(),std::ostream_iterator<std::string>(oss,", "));
+      throw Exception(oss.str());
+    }
+  std::size_t pos(std::distance(allNames.begin(),it));
+  std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::iterator it0(_vars.begin());
+  for(std::size_t i=0;i<pos;i++,it0++);
+  return it0;
+}
+
 ///////
 
 DataScopeServer::DataScopeServer(CORBA::ORB_ptr orb, const std::string& scopeName):DataScopeServerBase(orb,scopeName)
@@ -330,6 +352,18 @@ void DataScopeServerTransaction::createRdWrVarInternal(const std::string& varNam
   _vars.push_back(p);
 }
 
+SALOME::ByteVec *DataScopeServerTransaction::fetchSerializedContent(const char *varName)
+{
+  BasicDataServer *var(retrieveVarInternal2(varName));
+  PickelizedPyObjServer *varc(dynamic_cast<PickelizedPyObjServer *>(var));
+  if(!varc)
+    {
+      std::ostringstream oss; oss << "DataScopeServerTransaction::fetchSerializedContent : var \"" << varName << "\"exists but it is not serialized !";
+      throw Exception(oss.str());
+    }
+  return varc->fetchSerializedContent();
+}
+
 SALOME::Transaction_ptr DataScopeServerTransaction::createRdOnlyVarTransac(const char *varName, const SALOME::ByteVec& constValue)
 {
   TransactionRdOnlyVarCreate *ret(new TransactionRdOnlyVarCreate(this,varName,constValue));
@@ -357,6 +391,15 @@ SALOME::Transaction_ptr DataScopeServerTransaction::createRdWrVarTransac(const c
   return SALOME::Transaction::_narrow(obj);
 }
 
+SALOME::Transaction_ptr DataScopeServerTransaction::addKeyValueInVarHard(const char *varName, const SALOME::ByteVec& key, const SALOME::ByteVec& value)
+{
+  TransactionAddKeyValueHard *ret(new TransactionAddKeyValueHard(this,varName,key,value));
+  ret->checkNotAlreadyExisting();
+  PortableServer::ObjectId_var id(_poa->activate_object(ret));
+  CORBA::Object_var obj(_poa->id_to_reference(id));
+  return SALOME::Transaction::_narrow(obj);
+}
+
 class TrustTransaction
 {
 public:
@@ -407,6 +450,8 @@ void DataScopeServerTransaction::atomicApply(const SALOME::ListOfTransaction& tr
       transactions2[i].operate();
     mustRollback=false;
   }
+  for(std::size_t i=0;i<sz;i++)
+    transactionsCpp[i]->notify();
 }
 
 DataScopeServerTransaction::~DataScopeServerTransaction()
index 769270f43c98e90127a37384e21acc955ed8e84a..03b5934d7d6cca91027d3ecb9aa843853d8e307b 100644 (file)
@@ -46,7 +46,8 @@ namespace SALOMESDS
     char *getScopeName();
     SALOME::StringVec *listVars();
     CORBA::Boolean existVar(const char *varName);
-    SALOME::BasicDataServer_ptr retrieveVar(const char *varName);
+    SALOME::BasicDataServer_ptr retrieveVarInternal(const char *varName);
+    BasicDataServer *retrieveVarInternal2(const std::string& varName);
     void deleteVar(const char *varName);
     void shutdownIfNotHostedByDSM();
     ~DataScopeServerBase();
@@ -65,6 +66,9 @@ namespace SALOMESDS
     std::vector< std::string> getAllVarNames() const;
     CORBA::Object_var activateWithDedicatedPOA(BasicDataServer *ds);
     void checkNotAlreadyExistingVar(const std::string& varName);
+    void checkExistingVar(const std::string& varName);
+  protected:
+    std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::iterator retrieveVarInternal3(const std::string& varName);
   protected:
     PyObject *_globals;
     PyObject *_locals;
@@ -81,6 +85,7 @@ namespace SALOMESDS
   public:
     DataScopeServer(CORBA::ORB_ptr orb, const std::string& scopeName);
     DataScopeServer(const DataScopeServer& other);
+    SALOME::BasicDataServer_ptr retrieveVar(const char *varName) { return retrieveVarInternal(varName); }
     SALOME::PickelizedPyObjRdOnlyServer_ptr createRdOnlyVar(const char *varName, const SALOME::ByteVec& constValue);
     SALOME::PickelizedPyObjRdExtServer_ptr createRdExtVar(const char *varName, const SALOME::ByteVec& constValue);
     SALOME::PickelizedPyObjRdWrServer_ptr createRdWrVar(const char *typeName, const char *varName);
@@ -97,15 +102,16 @@ namespace SALOMESDS
     void createRdExtVarInternal(const std::string& varName, const SALOME::ByteVec& constValue);
     void createRdWrVarInternal(const std::string& varName, const SALOME::ByteVec& constValue);
   public://remotely callable
+    SALOME::ByteVec *fetchSerializedContent(const char *varName);
     SALOME::Transaction_ptr createRdOnlyVarTransac(const char *varName, const SALOME::ByteVec& constValue);
     SALOME::Transaction_ptr createRdExtVarTransac(const char *varName, const SALOME::ByteVec& constValue);
     SALOME::Transaction_ptr createRdWrVarTransac(const char *varName, const SALOME::ByteVec& constValue);
+    SALOME::Transaction_ptr addKeyValueInVarHard(const char *varName, const SALOME::ByteVec& key, const SALOME::ByteVec& value);
     void atomicApply(const SALOME::ListOfTransaction& transactions);
   };
   
   /*
   SALOME::Transaction_ptr addKeyValueInVarErrorIfAlreadyExisting(const char *varName, const char *scopeName, const SALOME::ByteVec& key, const SALOME::ByteVec& value);
-  SALOME::Transaction_ptr addKeyValueInVarHard(const char *varName, const char *scopeName, const SALOME::ByteVec& key, const SALOME::ByteVec& value);
   SALOME::Transaction_ptr removeKeyInVarErrorIfNotAlreadyExisting(const char *varName, const char *scopeName, const SALOME::ByteVec& key);
   SALOME::ByteVec *waitForKeyInVar(const char *varName, const char *scopeName, const SALOME::ByteVec& constKey);
   SALOME::ByteVec *waitForKeyInVarAndKillIt(const char *varName, const char *scopeName, const SALOME::ByteVec& constKey, SALOME::Transaction_out transaction);*/
index 2bc0c120c181adbf7447ec2f0784495561efb29c..0dd9701e3f3327ca7e286118584b69beacba2377 100644 (file)
@@ -52,6 +52,27 @@ SALOME::ByteVec *PickelizedPyObjServer::fetchSerializedContent()
   return FromCppToByteSeq(pickelize(_self));
 }
 
+bool PickelizedPyObjServer::isDict()
+{
+  if(PyDict_Check(_self))
+    return true;
+  else
+    return false;
+}
+
+void PickelizedPyObjServer::addKeyValueHard(const std::vector<unsigned char>& key, const std::vector<unsigned char>& 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);
+  if(!isOK)
+    throw Exception("PickelizedPyObjServer::addKeyValueHard : error when trying to add key,value to dict !");
+}
+
 void PickelizedPyObjServer::FromByteSeqToCpp(const SALOME::ByteVec& bsToBeConv, std::string& ret)
 {
   std::size_t sz(bsToBeConv.length());
@@ -88,6 +109,22 @@ PyObject *PickelizedPyObjServer::getPyObjFromPickled(const std::string& pickledD
   return ret;
 }
 
+//! New reference returned
+PyObject *PickelizedPyObjServer::getPyObjFromPickled(const std::vector<unsigned char>& pickledData)
+{
+  std::size_t sz(pickledData.size());
+  PyObject *pickledDataPy(PyString_FromStringAndSize(NULL,sz));// agy : do not use PyString_FromString because std::string hides a vector of byte.
+  char *buf(PyString_AsString(pickledDataPy));// this buf can be used thanks to python documentation.
+  const unsigned char *inBuf(&pickledData[0]);
+  std::copy(inBuf,inBuf+sz,buf);
+  PyObject *selfMeth(PyObject_GetAttrString(_father->getPickler(),"loads"));
+  PyObject *args(PyTuple_New(1)); PyTuple_SetItem(args,0,pickledDataPy);
+  PyObject *ret(PyObject_CallObject(selfMeth,args));
+  Py_XDECREF(args);
+  Py_XDECREF(selfMeth);
+  return ret;
+}
+
 //! obj is consumed by this method.
 std::string PickelizedPyObjServer::pickelize(PyObject *obj)
 {
index e216262cd28cc1aac6cb25868a60bcb0ef8fd34e..e8f3edb5f14974859ae54b1e2374dc31a618e57f 100644 (file)
@@ -28,6 +28,8 @@
 
 #include "SALOMESDS_BasicDataServer.hxx"
 
+#include <vector>
+
 namespace SALOMESDS
 {
   class PickelizedPyObjServer : public BasicDataServer, public virtual POA_SALOME::PickelizedPyObjServer
@@ -38,10 +40,14 @@ namespace SALOMESDS
     ~PickelizedPyObjServer();
     void setSerializedContent(const SALOME::ByteVec& newValue);
     SALOME::ByteVec *fetchSerializedContent();
-  protected:
+  public:
+    bool isDict();
+    void addKeyValueHard(const std::vector<unsigned char>& key, const std::vector<unsigned char>& value);
+  public:
     static void FromByteSeqToCpp(const SALOME::ByteVec& bsToBeConv, std::string& ret);
     static SALOME::ByteVec *FromCppToByteSeq(const std::string& strToBeConv);
     PyObject *getPyObjFromPickled(const std::string& pickledData);
+    PyObject *getPyObjFromPickled(const std::vector<unsigned char>& pickledData);
     std::string pickelize(PyObject *obj);
     void setNewPyObj(PyObject *obj);
     void setSerializedContentInternal(const SALOME::ByteVec& newValue);
index 31778707c7affd30f83a06bdafcec3b5fd2e96e6..e46a6dafb8e9b99004fa0e9c9686329bdc0af3e7 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "SALOMESDS_Transaction.hxx"
 #include "SALOMESDS_Exception.hxx"
+#include "SALOMESDS_PickelizedPyObjServer.hxx"
 
 #include <sstream>
 
@@ -42,6 +43,10 @@ void Transaction::FromVBToByteSeq(const std::vector<unsigned char>& bsToBeConv,
     ret[i]=bsToBeConv[i];
 }
 
+Transaction::~Transaction()
+{
+}
+
 TransactionVarCreate::TransactionVarCreate(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& constValue):Transaction(dsct,varName)
 {
   FromByteSeqToVB(constValue,_data);
@@ -58,6 +63,13 @@ void TransactionVarCreate::rollBack()
     _dsct->deleteVar(_var_name.c_str());
 }
 
+/*!
+ TODO : To be implemented.
+ */
+void TransactionVarCreate::notify()
+{
+}
+
 void TransactionRdOnlyVarCreate::perform()
 {
   SALOME::ByteVec data2;
@@ -78,3 +90,54 @@ void TransactionRdWrVarCreate::perform()
   FromVBToByteSeq(_data,data2);
   _dsct->createRdWrVarInternal(_var_name,data2);
 }
+
+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);
+}
+
+void TransactionAddKeyValueHard::prepareRollBackInCaseOfFailure()
+{
+  checkNotAlreadyExisting();
+  //
+  BasicDataServer *var(_dsct->retrieveVarInternal2(_var_name.c_str()));
+  _varc=dynamic_cast<PickelizedPyObjServer *>(var);
+  if(!_varc)
+    {
+      std::ostringstream oss; oss << "TransactionAddKeyValueHard::prepareRollBackInCaseOfFailure : var \"" << _var_name << "\"exists but it is not serialized !";
+      throw Exception(oss.str());
+    }
+  if(!_varc->isDict())
+    {
+      std::ostringstream oss; oss << "TransactionAddKeyValueHard::prepareRollBackInCaseOfFailure : var \"" << _var_name << "\"exists but it is not a Dict !";
+      throw Exception(oss.str());
+    }
+  //
+  _zeDataBefore.clear();
+  SALOME::ByteVec *zeDataBefore(_varc->fetchSerializedContent());
+  PickelizedPyObjServer::FromByteSeqToCpp(*zeDataBefore,_zeDataBefore);
+}
+
+void TransactionAddKeyValueHard::perform()
+{
+  _varc->addKeyValueHard(_key,_value);
+}
+
+void TransactionAddKeyValueHard::rollBack()
+{
+  PyObject *obj(_varc->getPyObjFromPickled(_zeDataBefore));
+  _varc->setNewPyObj(obj);
+  _zeDataBefore.clear();
+}
+
+/*!
+ TODO : To be implemented.
+ */
+void TransactionAddKeyValueHard::notify()
+{
+}
+
+TransactionAddKeyValueHard::~TransactionAddKeyValueHard()
+{
+}
index 805b8d6478d402a7b66ccffeec119e05621daaff..f934cdf5c0b7f56efd96c216769f5a8e1eb9a370 100644 (file)
@@ -38,9 +38,13 @@ namespace SALOMESDS
   public:
     Transaction(DataScopeServerTransaction *dsct, const std::string& varName):_dsct(dsct),_var_name(varName) { if(!_dsct) throw Exception("Transaction constructor error !"); }
     std::string getVarName() const { return _var_name; }
+    void checkNotAlreadyExisting() { _dsct->checkNotAlreadyExistingVar(_var_name); }
+    void checkVarExisting() { _dsct->checkExistingVar(_var_name); }
     virtual void prepareRollBackInCaseOfFailure() = 0;
     virtual void perform() = 0;
     virtual void rollBack() = 0;
+    virtual void notify() = 0;
+    virtual ~Transaction();
   public:
     static void FromByteSeqToVB(const SALOME::ByteVec& bsToBeConv, std::vector<unsigned char>& ret);
     static void FromVBToByteSeq(const std::vector<unsigned char>& bsToBeConv, SALOME::ByteVec& ret);
@@ -53,9 +57,9 @@ namespace SALOMESDS
   {
   public:
     TransactionVarCreate(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& constValue);
-    void checkNotAlreadyExisting() { _dsct->checkNotAlreadyExistingVar(_var_name); }
     void prepareRollBackInCaseOfFailure();
     void rollBack();
+    void notify();
   protected:
     std::vector<unsigned char> _data;
   };
@@ -80,6 +84,24 @@ namespace SALOMESDS
     TransactionRdWrVarCreate(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& constValue):TransactionVarCreate(dsct,varName,constValue) { }
     void perform();
   };
+
+  class PickelizedPyObjServer;
+
+  class TransactionAddKeyValueHard : public Transaction
+  {
+  public:
+    TransactionAddKeyValueHard(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& key, const SALOME::ByteVec& value);
+    void prepareRollBackInCaseOfFailure();
+    void perform();
+    void rollBack();
+    void notify();
+    ~TransactionAddKeyValueHard();
+  private:
+    std::vector<unsigned char> _key;
+    std::vector<unsigned char> _value;
+    std::string _zeDataBefore;
+    PickelizedPyObjServer *_varc;
+  };
 }
 
 #endif