]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
on the road of read only and read ext. coming soon \!
authorAnthony Geay <anthony.geay@edf.fr>
Wed, 7 Jan 2015 16:52:49 +0000 (17:52 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Wed, 7 Jan 2015 16:52:49 +0000 (17:52 +0100)
18 files changed:
idl/SALOME_SDS.idl
src/SALOMESDS/CMakeLists.txt
src/SALOMESDS/SALOMESDS_BasicDataServer.cxx
src/SALOMESDS/SALOMESDS_BasicDataServer.hxx
src/SALOMESDS/SALOMESDS_DataScopeServer.cxx
src/SALOMESDS/SALOMESDS_DataScopeServer.hxx
src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.cxx [new file with mode: 0644]
src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.hxx [new file with mode: 0644]
src/SALOMESDS/SALOMESDS_PickelizedPyObjRdOnlyServer.cxx [new file with mode: 0644]
src/SALOMESDS/SALOMESDS_PickelizedPyObjRdOnlyServer.hxx [new file with mode: 0644]
src/SALOMESDS/SALOMESDS_PickelizedPyObjRdWrServer.cxx [new file with mode: 0644]
src/SALOMESDS/SALOMESDS_PickelizedPyObjRdWrServer.hxx [new file with mode: 0644]
src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.cxx [new file with mode: 0644]
src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.hxx [new file with mode: 0644]
src/SALOMESDS/SALOMESDS_StringDataServer.cxx [deleted file]
src/SALOMESDS/SALOMESDS_StringDataServer.hxx [deleted file]
src/SALOMESDS/SalomeSDSClt.py
src/SALOMESDS/TestSalomeSDS1.py

index 9fcc3ec8575ff6bf07162169e275bdf4db29d4dc..27b9306879a16c01bf717975a2fd56327d22b3ef 100644 (file)
@@ -30,15 +30,26 @@ module SALOME
   {
     string getVarName();
     string getScopeName();
-    void setReadOnlyStatus();
-    void setRWStatus();
   };
 
-  interface StringDataServer : BasicDataServer
+  interface PickelizedPyObjServer : BasicDataServer
   {
-    void setSerializedContent(in ByteVec newValue) raises (SALOME::SALOME_Exception);
     ByteVec fetchSerializedContent() raises (SALOME::SALOME_Exception);
-    StringDataServer invokePythonMethodOn(in string method, in ByteVec args) raises (SALOME::SALOME_Exception);
+  };
+
+  interface PickelizedPyObjRdOnlyServer : PickelizedPyObjServer
+  {
+  };
+
+  interface PickelizedPyObjRdExtServer : PickelizedPyObjServer
+  {
+    PickelizedPyObjRdExtServer invokePythonMethodOn(in string method, in ByteVec args) raises (SALOME::SALOME_Exception);
+  };
+
+  interface PickelizedPyObjRdWrServer : PickelizedPyObjServer
+  {
+    void setSerializedContent(in ByteVec newValue) raises (SALOME::SALOME_Exception);
+    PickelizedPyObjRdWrServer invokePythonMethodOn(in string method, in ByteVec args) raises (SALOME::SALOME_Exception);
   };
 
   interface DataServerManager;
@@ -49,8 +60,8 @@ module SALOME
     string getScopeName();
     StringVec listVars();
     BasicDataServer retrieveVar(in string varName) raises (SALOME::SALOME_Exception);
-    StringDataServer createGlobalStringVar(in string typeName, in string varName) raises (SALOME::SALOME_Exception);
-    StringDataServer createGlobalTmpVar(in ByteVec newValue) raises (SALOME::SALOME_Exception);
+    PickelizedPyObjRdOnlyServer createRdOnlyVar(in string varName, in ByteVec constValue) raises (SALOME::SALOME_Exception);
+    PickelizedPyObjRdWrServer createRdWrVar(in string typeName, in string varName) raises (SALOME::SALOME_Exception);
     void shutdownIfNotHostedByDSM();
   };
 
index 421c27f60849c9baf82a8d780b0b0a012a855a58..b86b576767614703cab12c4e2e10f10221aeb53c 100644 (file)
@@ -40,7 +40,10 @@ SET(SalomeSDS_SOURCES
   SALOMESDS_BasicDataServer.cxx
   SALOMESDS_DataScopeServer.cxx
   SALOMESDS_DataServerManager.cxx
-  SALOMESDS_StringDataServer.cxx
+  SALOMESDS_PickelizedPyObjServer.cxx
+  SALOMESDS_PickelizedPyObjRdOnlyServer.cxx
+  SALOMESDS_PickelizedPyObjRdExtServer.cxx
+  SALOMESDS_PickelizedPyObjRdWrServer.cxx
   )
 
 ADD_LIBRARY(SalomeSDS ${SalomeSDS_SOURCES})
index d002d2fb9bd33b8ef6428b3e2f7ea66fd5b20e4c..4d3e89151fdb2e32ca4bb0fb9bc53a61bce3c010 100644 (file)
@@ -26,7 +26,7 @@
 
 using namespace SALOMESDS;
 
-BasicDataServer::BasicDataServer(DataScopeServer *father, const std::string& varName):_father(father),_is_read_only(false),_var_name(varName)
+BasicDataServer::BasicDataServer(DataScopeServer *father, const std::string& varName):_father(father),_var_name(varName)
 {
 }
 
@@ -43,22 +43,6 @@ char *BasicDataServer::getScopeName()
   return _father->getScopeName();
 }
 
-/*!
- * Called remotely -> to protect against throw
- */
-void BasicDataServer::setReadOnlyStatus()
-{
-  _is_read_only=true;
-}
-
-/*!
- * Called remotely -> to protect against throw
- */
-void BasicDataServer::setRWStatus()
-{
-  _is_read_only=false;
-}
-
 void BasicDataServer::Register()
 {
   incrRef();
@@ -73,9 +57,3 @@ void BasicDataServer::Destroy()
 {
   enforcedRelease();
 }
-
-void BasicDataServer::checkReadOnlyStatusRegardingConstness(const char *sender) const
-{
-  if(isReadOnly())
-    throw Exception(sender);
-}
index d6139aabccabbbfb247e3fd082a438989331c06d..e0ed15dbf783ee7c3fad3ab649b3bb12c2464426 100644 (file)
@@ -38,22 +38,15 @@ namespace SALOMESDS
     BasicDataServer(DataScopeServer *father, const std::string& varName);
     char *getVarName();
     char *getScopeName();
-    void setReadOnlyStatus();
-    void setRWStatus();
   public:
     void Register();
     void UnRegister();
     void Destroy();
   public:
     std::string getVarNameCpp() const { return _var_name; }
-  protected:
-    void checkReadOnlyStatusRegardingConstness(const char *sender) const;
-    bool isReadOnly() const { return _is_read_only; }
   protected:
     DataScopeServer *_father;
   private:
-    //! false by default
-    bool _is_read_only;
     std::string _var_name;
   };
 }
index a1a109496385737b6ef3aeceac45e9e491469fb5..8f9aabcbc1223645b7465a4045e7e566d57fc050 100644 (file)
@@ -20,7 +20,8 @@
 
 #include "SALOMESDS_DataScopeServer.hxx"
 #include "SALOMESDS_DataServerManager.hxx"
-#include "SALOMESDS_StringDataServer.hxx"
+#include "SALOMESDS_PickelizedPyObjRdOnlyServer.hxx"
+#include "SALOMESDS_PickelizedPyObjRdWrServer.hxx"
 #include "SALOME_NamingService.hxx"
 #include "SALOMESDS_Exception.hxx"
 
@@ -108,39 +109,29 @@ SALOME::BasicDataServer_ptr DataScopeServer::retrieveVar(const char *varName)
   return SALOME::BasicDataServer::_duplicate((*it0).first);
 }
 
-/*!
- * Called remotely -> to protect against throw
- */
-SALOME::StringDataServer_ptr DataScopeServer::createGlobalStringVar(const char *typeName, const char *varName)
+SALOME::PickelizedPyObjRdOnlyServer_ptr DataScopeServer::createRdOnlyVar(const char *varName, const SALOME::ByteVec& constValue)
 {
-  std::string varNameCpp(varName),typeNameCpp(typeName);
-  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 << "DataScopeServer::createGlobalStringVar : name \"" << varNameCpp << "\" already exists !";
-      throw Exception(oss.str());
-    }
-  AutoRefCountPtr<StringDataServer> tmp(new StringDataServer(this,typeNameCpp,varNameCpp));
+  std::string varNameCpp(varName);
+  checkNotAlreadyExistingVar(varNameCpp);
+  AutoRefCountPtr<PickelizedPyObjRdOnlyServer> tmp(new PickelizedPyObjRdOnlyServer(this,varNameCpp,constValue));
   CORBA::Object_var ret(activateWithDedicatedPOA(tmp));
-  std::pair< SALOME::BasicDataServer_var, AutoRefCountPtr<BasicDataServer> > p(SALOME::BasicDataServer::_narrow(ret),DynamicCastSafe<StringDataServer,BasicDataServer>(tmp));
+  std::pair< SALOME::BasicDataServer_var, AutoRefCountPtr<BasicDataServer> > p(SALOME::BasicDataServer::_narrow(ret),DynamicCastSafe<PickelizedPyObjRdOnlyServer,BasicDataServer>(tmp));
   _vars.push_back(p);
-  return SALOME::StringDataServer::_narrow(ret);
+  return SALOME::PickelizedPyObjRdOnlyServer::_narrow(ret);
 }
 
 /*!
  * Called remotely -> to protect against throw
  */
-SALOME::StringDataServer_ptr DataScopeServer::createGlobalTmpVar(const SALOME::ByteVec& newValue)
+SALOME::PickelizedPyObjRdWrServer_ptr DataScopeServer::createRdWrVar(const char *typeName, const char *varName)
 {
-  static const char TMP_VAR_NAME[]="TmP";
-  std::string vn(BuildTmpVarNameFrom(TMP_VAR_NAME));
-  StringDataServer *retCpp(new StringDataServer(this,vn,newValue));
-  retCpp->setPOA(_poa);
-  //
-  PortableServer::ObjectId_var id(_poa->activate_object(retCpp));
-  CORBA::Object_var ret(_poa->id_to_reference(id));
-  return SALOME::StringDataServer::_narrow(ret);
+  std::string varNameCpp(varName),typeNameCpp(typeName);
+  checkNotAlreadyExistingVar(varNameCpp);
+  AutoRefCountPtr<PickelizedPyObjRdWrServer> tmp(new PickelizedPyObjRdWrServer(this,typeNameCpp,varNameCpp));
+  CORBA::Object_var ret(activateWithDedicatedPOA(tmp));
+  std::pair< SALOME::BasicDataServer_var, AutoRefCountPtr<BasicDataServer> > p(SALOME::BasicDataServer::_narrow(ret),DynamicCastSafe<PickelizedPyObjRdWrServer,BasicDataServer>(tmp));
+  _vars.push_back(p);
+  return SALOME::PickelizedPyObjRdWrServer::_narrow(ret);
 }
 
 void DataScopeServer::shutdownIfNotHostedByDSM()
@@ -255,3 +246,14 @@ CORBA::Object_var DataScopeServer::activateWithDedicatedPOA(BasicDataServer *ds)
   CORBA::Object_var ret(poa->id_to_reference(id));
   return ret;
 }
+
+void DataScopeServer::checkNotAlreadyExistingVar(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 << "DataScopeServer::createGlobalStringVar : name \"" << varName << "\" already exists !";
+      throw Exception(oss.str());
+    }
+}
index cf80fee60e314bf3bfa0bf3c12fc32afb5d11b0a..8a06052c7fbc0bbf3e87d41da638712a7b27489f 100644 (file)
@@ -45,8 +45,8 @@ namespace SALOMESDS
     char *getScopeName();
     SALOME::StringVec *listVars();
     SALOME::BasicDataServer_ptr retrieveVar(const char *varName);
-    SALOME::StringDataServer_ptr createGlobalStringVar(const char *typeName, const char *varName);
-    SALOME::StringDataServer_ptr createGlobalTmpVar(const SALOME::ByteVec& newValue);
+    SALOME::PickelizedPyObjRdOnlyServer_ptr createRdOnlyVar(const char *varName, const SALOME::ByteVec& constValue);
+    SALOME::PickelizedPyObjRdWrServer_ptr createRdWrVar(const char *typeName, const char *varName);
     void shutdownIfNotHostedByDSM();
     ~DataScopeServer();
   public:
@@ -61,6 +61,7 @@ namespace SALOMESDS
   private:
     std::vector< std::string> getAllVarNames() const;
     CORBA::Object_var activateWithDedicatedPOA(BasicDataServer *ds);
+    void checkNotAlreadyExistingVar(const std::string& varName);
   private:
     PyObject *_globals;
     PyObject *_locals;
diff --git a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.cxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.cxx
new file mode 100644 (file)
index 0000000..ff38164
--- /dev/null
@@ -0,0 +1,74 @@
+// Copyright (C) 2007-2014  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
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Anthony GEAY (EDF R&D)
+
+#include "SALOMESDS_PickelizedPyObjRdExtServer.hxx"
+#include "SALOMESDS_DataScopeServer.hxx"
+#include "SALOMESDS_Exception.hxx"
+
+#include <iostream>
+#include <sstream>
+
+using namespace SALOMESDS;
+
+PickelizedPyObjRdExtServer::PickelizedPyObjRdExtServer(DataScopeServer *father, const std::string& varName, const SALOME::ByteVec& value):PickelizedPyObjServer(father,varName,value)
+{
+}
+
+//! obj is consumed
+PickelizedPyObjRdExtServer::PickelizedPyObjRdExtServer(DataScopeServer *father, const std::string& varName, PyObject *obj):PickelizedPyObjServer(father,varName,obj)
+{
+}
+
+PickelizedPyObjRdExtServer::~PickelizedPyObjRdExtServer()
+{
+}
+
+/*!
+ * Called remotely -> to protect against throw
+ */
+SALOME::PickelizedPyObjRdExtServer_ptr PickelizedPyObjRdExtServer::invokePythonMethodOn(const char *method, const SALOME::ByteVec& args)
+{
+  if(!_self)
+    throw Exception("PickelizedPyObjRdExtServer::invokePythonMethodOn : self is NULL !");
+  std::string argsCpp;
+  FromByteSeqToCpp(args,argsCpp);
+  PyObject *argsPy(getPyObjFromPickled(argsCpp));
+  //
+  PyObject *selfMeth(PyObject_GetAttrString(_self,method));
+  if(!selfMeth)
+    {
+      std::ostringstream oss; oss << "PickelizedPyObjRdExtServer::invokePythonMethodOn : Method \"" << method << "\" is not available !";
+      throw Exception(oss.str());
+    }
+  PyObject *res(PyObject_CallObject(selfMeth,argsPy));// self can have been modified by this call !
+  Py_XDECREF(selfMeth);
+  Py_XDECREF(argsPy);
+  if(!res)
+    {
+      std::ostringstream oss; oss << "PickelizedPyObjRdExtServer::invokePythonMethodOn : Problem during invokation serverside of Method \"" << method << "\" !";
+      throw Exception(oss.str());
+    }
+  PickelizedPyObjRdExtServer *ret(new PickelizedPyObjRdExtServer(_father,DataScopeServer::BuildTmpVarNameFrom(getVarNameCpp()),res));
+  PortableServer::POA_var poa(_father->getPOA());
+  ret->setPOA(poa);
+  PortableServer::ObjectId_var id(poa->activate_object(ret));
+  CORBA::Object_var obj(poa->id_to_reference(id));
+  return SALOME::PickelizedPyObjRdExtServer::_narrow(obj);
+}
diff --git a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.hxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.hxx
new file mode 100644 (file)
index 0000000..100d1c5
--- /dev/null
@@ -0,0 +1,43 @@
+// Copyright (C) 2007-2014  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
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Anthony GEAY (EDF R&D)
+
+#ifndef __SALOMESDS_PICKELIZEDPYOBJRDEXTSERVER_HXX__
+#define __SALOMESDS_PICKELIZEDPYOBJRDEXTSERVER_HXX__
+
+#include "SALOMEconfig.h"
+#include CORBA_SERVER_HEADER(SALOME_SDS)
+
+#include <Python.h>
+
+#include "SALOMESDS_PickelizedPyObjServer.hxx"
+
+namespace SALOMESDS
+{
+  class PickelizedPyObjRdExtServer : public PickelizedPyObjServer, public virtual POA_SALOME::PickelizedPyObjRdExtServer
+  {
+  public:
+    PickelizedPyObjRdExtServer(DataScopeServer *father, const std::string& varName, const SALOME::ByteVec& value);
+    PickelizedPyObjRdExtServer(DataScopeServer *father, const std::string& varName, PyObject *obj);
+    ~PickelizedPyObjRdExtServer();
+    SALOME::PickelizedPyObjRdExtServer_ptr invokePythonMethodOn(const char *method, const SALOME::ByteVec& args);
+  };
+}
+
+#endif
diff --git a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdOnlyServer.cxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdOnlyServer.cxx
new file mode 100644 (file)
index 0000000..4626d00
--- /dev/null
@@ -0,0 +1,35 @@
+// Copyright (C) 2007-2014  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
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Anthony GEAY (EDF R&D)
+
+#include "SALOMESDS_PickelizedPyObjRdOnlyServer.hxx"
+
+using namespace SALOMESDS;
+
+PickelizedPyObjRdOnlyServer::PickelizedPyObjRdOnlyServer(DataScopeServer *father, const std::string& varName, const SALOME::ByteVec& value):PickelizedPyObjServer(father,varName,value)
+{
+}
+
+PickelizedPyObjRdOnlyServer::PickelizedPyObjRdOnlyServer(DataScopeServer *father, const std::string& varName, PyObject *obj):PickelizedPyObjServer(father,varName,obj)
+{
+}
+
+PickelizedPyObjRdOnlyServer::~PickelizedPyObjRdOnlyServer()
+{
+}
diff --git a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdOnlyServer.hxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdOnlyServer.hxx
new file mode 100644 (file)
index 0000000..68924a7
--- /dev/null
@@ -0,0 +1,42 @@
+// Copyright (C) 2007-2014  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
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Anthony GEAY (EDF R&D)
+
+#ifndef __SALOMESDS_PICKELIZEDPYOBJRDONLYSERVER_HXX__
+#define __SALOMESDS_PICKELIZEDPYOBJRDONLYSERVER_HXX__
+
+#include "SALOMEconfig.h"
+#include CORBA_SERVER_HEADER(SALOME_SDS)
+
+#include <Python.h>
+
+#include "SALOMESDS_PickelizedPyObjServer.hxx"
+
+namespace SALOMESDS
+{
+  class PickelizedPyObjRdOnlyServer : public PickelizedPyObjServer, public virtual POA_SALOME::PickelizedPyObjRdOnlyServer
+  {
+  public:
+    PickelizedPyObjRdOnlyServer(DataScopeServer *father, const std::string& varName, const SALOME::ByteVec& value);
+    PickelizedPyObjRdOnlyServer(DataScopeServer *father, const std::string& varName, PyObject *obj);
+    ~PickelizedPyObjRdOnlyServer();
+  };
+}
+
+#endif
diff --git a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdWrServer.cxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdWrServer.cxx
new file mode 100644 (file)
index 0000000..3487204
--- /dev/null
@@ -0,0 +1,87 @@
+// Copyright (C) 2007-2014  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
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Anthony GEAY (EDF R&D)
+
+#include "SALOMESDS_PickelizedPyObjRdWrServer.hxx"
+#include "SALOMESDS_DataScopeServer.hxx"
+#include "SALOMESDS_Exception.hxx"
+
+#include <iostream>
+#include <sstream>
+
+using namespace SALOMESDS;
+
+PickelizedPyObjRdWrServer::PickelizedPyObjRdWrServer(DataScopeServer *father, const std::string& typeName, const std::string& varName):PickelizedPyObjServer(father,varName,CreateDftObjFromType(father->getGlobals(),typeName))
+{
+}
+
+PickelizedPyObjRdWrServer::PickelizedPyObjRdWrServer(DataScopeServer *father, const std::string& varName, const SALOME::ByteVec& value):PickelizedPyObjServer(father,varName,value)
+{
+}
+
+//! obj is consumed
+PickelizedPyObjRdWrServer::PickelizedPyObjRdWrServer(DataScopeServer *father, const std::string& varName, PyObject *obj):PickelizedPyObjServer(father,varName,obj)
+{
+}
+
+PickelizedPyObjRdWrServer::~PickelizedPyObjRdWrServer()
+{
+}
+
+/*!
+ * Called remotely -> to protect against throw
+ */
+void PickelizedPyObjRdWrServer::setSerializedContent(const SALOME::ByteVec& newValue)
+{
+  setSerializedContentInternal(newValue);
+}
+
+/*!
+ * Called remotely -> to protect against throw
+ */
+SALOME::PickelizedPyObjRdWrServer_ptr PickelizedPyObjRdWrServer::invokePythonMethodOn(const char *method, const SALOME::ByteVec& args)
+{
+  if(!_self)
+    throw Exception("PickelizedPyObjRdWrServer::invokePythonMethodOn : self is NULL !");
+  std::string argsCpp;
+  FromByteSeqToCpp(args,argsCpp);
+  PyObject *argsPy(getPyObjFromPickled(argsCpp));
+  //
+  PyObject *selfMeth(PyObject_GetAttrString(_self,method));
+  if(!selfMeth)
+    {
+      std::ostringstream oss; oss << "PickelizedPyObjRdWrServer::invokePythonMethodOn : Method \"" << method << "\" is not available !";
+      throw Exception(oss.str());
+    }
+  PyObject *res(PyObject_CallObject(selfMeth,argsPy));// self can have been modified by this call !
+  Py_XDECREF(selfMeth);
+  Py_XDECREF(argsPy);
+  if(!res)
+    {
+      PyErr_Clear();
+      std::ostringstream oss; oss << "PickelizedPyObjRdWrServer::invokePythonMethodOn : Problem during invokation serverside of Method \"" << method << "\" !";
+      throw Exception(oss.str());
+    }
+  PickelizedPyObjRdWrServer *ret(new PickelizedPyObjRdWrServer(_father,DataScopeServer::BuildTmpVarNameFrom(getVarNameCpp()),res));
+  PortableServer::POA_var poa(_father->getPOA());
+  ret->setPOA(poa);
+  PortableServer::ObjectId_var id(poa->activate_object(ret));
+  CORBA::Object_var obj(poa->id_to_reference(id));
+  return SALOME::PickelizedPyObjRdWrServer::_narrow(obj);
+}
diff --git a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdWrServer.hxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdWrServer.hxx
new file mode 100644 (file)
index 0000000..fe33ca2
--- /dev/null
@@ -0,0 +1,45 @@
+// Copyright (C) 2007-2014  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
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Anthony GEAY (EDF R&D)
+
+#ifndef __SALOMESDS_PICKELIZEDPYOBJRDWRSERVER_HXX__
+#define __SALOMESDS_PICKELIZEDPYOBJRDWRSERVER_HXX__
+
+#include "SALOMEconfig.h"
+#include CORBA_SERVER_HEADER(SALOME_SDS)
+
+#include <Python.h>
+
+#include "SALOMESDS_PickelizedPyObjServer.hxx"
+
+namespace SALOMESDS
+{
+  class PickelizedPyObjRdWrServer : public PickelizedPyObjServer, public virtual POA_SALOME::PickelizedPyObjRdWrServer
+  {
+  public:
+    PickelizedPyObjRdWrServer(DataScopeServer *father, const std::string& typeName, const std::string& varName);
+    PickelizedPyObjRdWrServer(DataScopeServer *father, const std::string& varName, const SALOME::ByteVec& value);
+    PickelizedPyObjRdWrServer(DataScopeServer *father, const std::string& varName, PyObject *obj);
+    ~PickelizedPyObjRdWrServer();
+    void setSerializedContent(const SALOME::ByteVec& newValue);
+    SALOME::PickelizedPyObjRdWrServer_ptr invokePythonMethodOn(const char *method, const SALOME::ByteVec& args);
+  };
+}
+
+#endif
diff --git a/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.cxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.cxx
new file mode 100644 (file)
index 0000000..53c0b1a
--- /dev/null
@@ -0,0 +1,164 @@
+// Copyright (C) 2007-2014  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
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Anthony GEAY (EDF R&D)
+
+#include "SALOMESDS_PickelizedPyObjServer.hxx"
+#include "SALOMESDS_DataScopeServer.hxx"
+#include "SALOMESDS_Exception.hxx"
+
+#include <iostream>
+#include <sstream>
+
+using namespace SALOMESDS;
+
+PickelizedPyObjServer::PickelizedPyObjServer(DataScopeServer *father, const std::string& varName, const SALOME::ByteVec& value):BasicDataServer(father,varName),_self(0)
+{
+  setSerializedContentInternal(value);
+}
+
+//! obj is consumed
+PickelizedPyObjServer::PickelizedPyObjServer(DataScopeServer *father, const std::string& varName, PyObject *obj):BasicDataServer(father,varName),_self(obj)
+{
+}
+
+PickelizedPyObjServer::~PickelizedPyObjServer()
+{
+  std::cerr << "~~~~~~~~~~ PickelizedPyObjServer : " << getVarNameCpp() << std::endl;
+  Py_XDECREF(_self);
+}
+
+/*!
+ * Called remotely -> to protect against throw
+ */
+SALOME::ByteVec *PickelizedPyObjServer::fetchSerializedContent()
+{
+  Py_XINCREF(_self);//because pickelize consume _self
+  return FromCppToByteSeq(pickelize(_self));
+}
+
+PortableServer::POA_var PickelizedPyObjServer::getPOA()
+{
+  return _poa;
+}
+
+void PickelizedPyObjServer::FromByteSeqToCpp(const SALOME::ByteVec& bsToBeConv, std::string& ret)
+{
+  std::size_t sz(bsToBeConv.length());
+  ret.resize(sz,' ');
+  char *buf(const_cast<char *>(ret.c_str()));
+  for(std::size_t i=0;i<sz;i++)
+    buf[i]=bsToBeConv[i];
+}
+
+SALOME::ByteVec *PickelizedPyObjServer::FromCppToByteSeq(const std::string& strToBeConv)
+{
+  SALOME::ByteVec *ret(new SALOME::ByteVec);
+  const char *buf(strToBeConv.c_str());
+  std::size_t sz(strToBeConv.size());
+  ret->length(sz);
+  for(std::size_t i=0;i<sz;i++)
+    (*ret)[i]=buf[i];
+  return ret;
+}
+
+//! New reference returned
+PyObject *PickelizedPyObjServer::getPyObjFromPickled(const std::string& 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 char *inBuf(pickledData.c_str());
+  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)
+{
+  PyObject *args(PyTuple_New(2));
+  PyTuple_SetItem(args,0,obj);
+  PyTuple_SetItem(args,1,PyInt_FromLong(2));// because "assert(cPickle.HIGHEST_PROTOCOL is 2)"
+  PyObject *selfMeth(PyObject_GetAttrString(_father->getPickler(),"dumps"));
+  PyObject *retPy(PyObject_CallObject(selfMeth,args));
+  Py_XDECREF(selfMeth);
+  Py_XDECREF(args);
+  std::size_t sz(PyString_Size(retPy));
+  std::string ret(sz,'\0');
+  const char *buf(PyString_AsString(retPy));
+  char *inBuf(const_cast<char *>(ret.c_str()));
+  for(std::size_t i=0;i<sz;i++)
+    inBuf[i]=buf[i];
+  Py_XDECREF(retPy);
+  return ret;
+}
+
+//! obj is consumed by this method.
+void PickelizedPyObjServer::setNewPyObj(PyObject *obj)
+{
+  if(!obj)
+    throw Exception("PickelizedPyObjServer::setNewPyObj : trying to assign a NULL pyobject in this !");
+  if(obj==_self)
+    return ;
+  if(_self)
+    {
+      PyObject *selfType(PyObject_Type(_self));
+      if(PyObject_IsInstance(obj,selfType)!=1)
+        {
+          Py_XDECREF(obj);
+          Py_XDECREF(selfType);
+          throw Exception("PickelizedPyObjServer::setNewPyObj : type of new object is not the same than those previously set !");
+        }
+      else
+        Py_XDECREF(selfType);
+    }
+  Py_XDECREF(_self);
+  _self=obj;
+}
+
+void PickelizedPyObjServer::setSerializedContentInternal(const SALOME::ByteVec& newValue)
+{
+  std::string data;
+  FromByteSeqToCpp(newValue,data);
+  setNewPyObj(getPyObjFromPickled(data));
+}
+
+PyObject *PickelizedPyObjServer::CreateDftObjFromType(PyObject *globals, const std::string& typeName)
+{
+  PyObject *builtins(PyDict_GetItemString(globals,"__builtins__"));
+  if(!builtins)
+    throw Exception("PickelizedPyObjServer constructor : no __builtins__ in globals !");
+  PyObject *builtins2(PyModule_GetDict(builtins));
+  if(!builtins2)
+    throw Exception("PickelizedPyObjServer constructor : internal error fail to invoke __dict__ on __builtins__ !");
+  PyObject *tmp(PyDict_GetItemString(builtins2,typeName.c_str()));
+  if(!tmp)
+    {
+      std::ostringstream oss; oss << "PickelizedPyObjServer::CreateDftObjFromType : Invalid type name \"" << typeName << "\" !";
+      throw Exception(oss.str());
+    }
+  PyObject *args(PyTuple_New(0));
+  PyObject *ret(PyObject_CallObject(tmp,args));
+  Py_XDECREF(args);
+  return ret;
+}
diff --git a/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.hxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.hxx
new file mode 100644 (file)
index 0000000..cc691bd
--- /dev/null
@@ -0,0 +1,59 @@
+// Copyright (C) 2007-2014  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
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Anthony GEAY (EDF R&D)
+
+#ifndef __SALOMESDS_PICKELIZEDPYOBJSERVER_HXX__
+#define __SALOMESDS_PICKELIZEDPYOBJSERVER_HXX__
+
+#include "SALOMEconfig.h"
+#include CORBA_SERVER_HEADER(SALOME_SDS)
+
+#include <Python.h>
+
+#include "SALOMESDS_BasicDataServer.hxx"
+
+namespace SALOMESDS
+{
+  class PickelizedPyObjServer : public BasicDataServer, public virtual POA_SALOME::PickelizedPyObjServer
+  {
+  public:
+    PickelizedPyObjServer(DataScopeServer *father, const std::string& varName, const SALOME::ByteVec& value);
+    PickelizedPyObjServer(DataScopeServer *father, const std::string& varName, PyObject *obj);
+    ~PickelizedPyObjServer();
+    void setSerializedContent(const SALOME::ByteVec& newValue);
+    SALOME::ByteVec *fetchSerializedContent();
+  public:
+    void setPOA(PortableServer::POA_var poa) { _poa=poa; }
+  protected:
+    PortableServer::POA_var getPOA();
+    static void FromByteSeqToCpp(const SALOME::ByteVec& bsToBeConv, std::string& ret);
+    static SALOME::ByteVec *FromCppToByteSeq(const std::string& strToBeConv);
+    PyObject *getPyObjFromPickled(const std::string& pickledData);
+    std::string pickelize(PyObject *obj);
+    void setNewPyObj(PyObject *obj);
+    void setSerializedContentInternal(const SALOME::ByteVec& newValue);
+    static PyObject *CreateDftObjFromType(PyObject *globals, const std::string& typeName);
+  protected:
+    static const char FAKE_VAR_NAME_FOR_WORK[];
+    PyObject *_self;
+    PortableServer::POA_var _poa;
+  };
+}
+
+#endif
diff --git a/src/SALOMESDS/SALOMESDS_StringDataServer.cxx b/src/SALOMESDS/SALOMESDS_StringDataServer.cxx
deleted file mode 100644 (file)
index 8bece77..0000000
+++ /dev/null
@@ -1,211 +0,0 @@
-// Copyright (C) 2007-2014  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
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-// Author : Anthony GEAY (EDF R&D)
-
-#include "SALOMESDS_StringDataServer.hxx"
-#include "SALOMESDS_DataScopeServer.hxx"
-#include "SALOMESDS_Exception.hxx"
-
-#include <iostream>
-#include <sstream>
-
-using namespace SALOMESDS;
-
-StringDataServer::StringDataServer(DataScopeServer *father, const std::string& typeName, const std::string& varName):BasicDataServer(father,varName),_self(0)
-{
-  _self=CreateDftObjFromType(father->getGlobals(),typeName);
-}
-
-StringDataServer::StringDataServer(DataScopeServer *father, const std::string& varName, const SALOME::ByteVec& value):BasicDataServer(father,varName),_self(0)
-{
-  setSerializedContentInternal(value);
-}
-
-//! obj is consumed
-StringDataServer::StringDataServer(DataScopeServer *father, const std::string& varName, PyObject *obj):BasicDataServer(father,varName),_self(obj)
-{
-}
-
-StringDataServer::~StringDataServer()
-{
-  std::cerr << "~~~~~~~~~~ StringDataServer : " << getVarNameCpp() << std::endl;
-  Py_XDECREF(_self);
-}
-
-/*!
- * Called remotely -> to protect against throw
- */
-void StringDataServer::setSerializedContent(const SALOME::ByteVec& newValue)
-{
-  setSerializedContentInternal(newValue);
-}
-
-/*!
- * Called remotely -> to protect against throw
- */
-SALOME::ByteVec *StringDataServer::fetchSerializedContent()
-{
-  Py_XINCREF(_self);//because pickelize consume _self
-  return FromCppToByteSeq(pickelize(_self));
-}
-
-/*!
- * Called remotely -> to protect against throw
- */
-SALOME::StringDataServer_ptr StringDataServer::invokePythonMethodOn(const char *method, const SALOME::ByteVec& args)
-{
-  if(!_self)
-    throw Exception("StringDataServer::invokePythonMethodOn : self is NULL !");
-  std::string argsCpp;
-  FromByteSeqToCpp(args,argsCpp);
-  PyObject *argsPy(getPyObjFromPickled(argsCpp));
-  //
-  PyObject *selfMeth(PyObject_GetAttrString(_self,method));
-  if(!selfMeth)
-    {
-      std::ostringstream oss; oss << "StringDataServer::invokePythonMethodOn : Method \"" << method << "\" is not available !";
-      throw Exception(oss.str());
-    }
-  PyObject *res(PyObject_CallObject(selfMeth,argsPy));// self can have been modified by this call !
-  Py_XDECREF(selfMeth);
-  Py_XDECREF(argsPy);
-  if(!res)
-    {
-      std::ostringstream oss; oss << "StringDataServer::invokePythonMethodOn : Problem during invokation serverside of Method \"" << method << "\" !";
-      throw Exception(oss.str());
-    }
-  StringDataServer *ret(new StringDataServer(_father,DataScopeServer::BuildTmpVarNameFrom(getVarNameCpp()),res));
-  PortableServer::POA_var poa(_father->getPOA());
-  ret->setPOA(poa);
-  PortableServer::ObjectId_var id(poa->activate_object(ret));
-  CORBA::Object_var obj(poa->id_to_reference(id));
-  return SALOME::StringDataServer::_narrow(obj);
-}
-
-PortableServer::POA_var StringDataServer::getPOA()
-{
-  return _poa;
-}
-
-void StringDataServer::FromByteSeqToCpp(const SALOME::ByteVec& bsToBeConv, std::string& ret)
-{
-  std::size_t sz(bsToBeConv.length());
-  ret.resize(sz,' ');
-  char *buf(const_cast<char *>(ret.c_str()));
-  for(std::size_t i=0;i<sz;i++)
-    buf[i]=bsToBeConv[i];
-}
-
-SALOME::ByteVec *StringDataServer::FromCppToByteSeq(const std::string& strToBeConv)
-{
-  SALOME::ByteVec *ret(new SALOME::ByteVec);
-  const char *buf(strToBeConv.c_str());
-  std::size_t sz(strToBeConv.size());
-  ret->length(sz);
-  for(std::size_t i=0;i<sz;i++)
-    (*ret)[i]=buf[i];
-  return ret;
-}
-
-//! New reference returned
-PyObject *StringDataServer::getPyObjFromPickled(const std::string& 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 char *inBuf(pickledData.c_str());
-  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 StringDataServer::pickelize(PyObject *obj)
-{
-  PyObject *args(PyTuple_New(2));
-  PyTuple_SetItem(args,0,obj);
-  PyTuple_SetItem(args,1,PyInt_FromLong(2));// because "assert(cPickle.HIGHEST_PROTOCOL is 2)"
-  PyObject *selfMeth(PyObject_GetAttrString(_father->getPickler(),"dumps"));
-  PyObject *retPy(PyObject_CallObject(selfMeth,args));
-  Py_XDECREF(selfMeth);
-  Py_XDECREF(args);
-  std::size_t sz(PyString_Size(retPy));
-  std::string ret(sz,'\0');
-  const char *buf(PyString_AsString(retPy));
-  char *inBuf(const_cast<char *>(ret.c_str()));
-  for(std::size_t i=0;i<sz;i++)
-    inBuf[i]=buf[i];
-  Py_XDECREF(retPy);
-  return ret;
-}
-
-//! obj is consumed by this method.
-void StringDataServer::setNewPyObj(PyObject *obj)
-{
-  if(!obj)
-    throw Exception("StringDataServer::setNewPyObj : trying to assign a NULL pyobject in this !");
-  if(obj==_self)
-    return ;
-  if(_self)
-    {
-      PyObject *selfType(PyObject_Type(_self));
-      if(PyObject_IsInstance(obj,selfType)!=1)
-        {
-          Py_XDECREF(obj);
-          Py_XDECREF(selfType);
-          throw Exception("StringDataServer::setNewPyObj : type of new object is not the same than those previously set !");
-        }
-      else
-        Py_XDECREF(selfType);
-    }
-  Py_XDECREF(_self);
-  _self=obj;
-}
-
-void StringDataServer::setSerializedContentInternal(const SALOME::ByteVec& newValue)
-{
-  checkReadOnlyStatusRegardingConstness("StringDataServer::setSerializedContent : read only var !");
-  std::string data;
-  FromByteSeqToCpp(newValue,data);
-  setNewPyObj(getPyObjFromPickled(data));
-}
-
-PyObject *StringDataServer::CreateDftObjFromType(PyObject *globals, const std::string& typeName)
-{
-  PyObject *builtins(PyDict_GetItemString(globals,"__builtins__"));
-  if(!builtins)
-    throw Exception("StringDataServer constructor : no __builtins__ in globals !");
-  PyObject *builtins2(PyModule_GetDict(builtins));
-  if(!builtins2)
-    throw Exception("StringDataServer constructor : internal error fail to invoke __dict__ on __builtins__ !");
-  PyObject *tmp(PyDict_GetItemString(builtins2,typeName.c_str()));
-  if(!tmp)
-    {
-      std::ostringstream oss; oss << "StringDataServer::CreateDftObjFromType : Invalid type name \"" << typeName << "\" !";
-      throw Exception(oss.str());
-    }
-  PyObject *args(PyTuple_New(0));
-  PyObject *ret(PyObject_CallObject(tmp,args));
-  Py_XDECREF(args);
-  return ret;
-}
diff --git a/src/SALOMESDS/SALOMESDS_StringDataServer.hxx b/src/SALOMESDS/SALOMESDS_StringDataServer.hxx
deleted file mode 100644 (file)
index 0385ceb..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-// Copyright (C) 2007-2014  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
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-// Author : Anthony GEAY (EDF R&D)
-
-#ifndef __SALOMESDS_STRINGDATASERVER_HXX__
-#define __SALOMESDS_STRINGDATASERVER_HXX__
-
-#include "SALOMEconfig.h"
-#include CORBA_SERVER_HEADER(SALOME_SDS)
-
-#include <Python.h>
-
-#include "SALOMESDS_BasicDataServer.hxx"
-
-namespace SALOMESDS
-{
-  class StringDataServer : public BasicDataServer, public virtual POA_SALOME::StringDataServer
-  {
-  public:
-    StringDataServer(DataScopeServer *father, const std::string& typeName, const std::string& varName);
-    StringDataServer(DataScopeServer *father, const std::string& varName, const SALOME::ByteVec& value);
-    StringDataServer(DataScopeServer *father, const std::string& varName, PyObject *obj);
-    ~StringDataServer();
-    void setSerializedContent(const SALOME::ByteVec& newValue);
-    SALOME::ByteVec *fetchSerializedContent();
-    SALOME::StringDataServer_ptr invokePythonMethodOn(const char *method, const SALOME::ByteVec& args);
-  public:
-    void setPOA(PortableServer::POA_var poa) { _poa=poa; }
-  private:
-    PortableServer::POA_var getPOA();
-    static void FromByteSeqToCpp(const SALOME::ByteVec& bsToBeConv, std::string& ret);
-    static SALOME::ByteVec *FromCppToByteSeq(const std::string& strToBeConv);
-    PyObject *getPyObjFromPickled(const std::string& pickledData);
-    std::string pickelize(PyObject *obj);
-    void setNewPyObj(PyObject *obj);
-    void setSerializedContentInternal(const SALOME::ByteVec& newValue);
-    static PyObject *CreateDftObjFromType(PyObject *globals, const std::string& typeName);
-  private:
-    static const char FAKE_VAR_NAME_FOR_WORK[];
-    PyObject *_self;
-    PortableServer::POA_var _poa;
-  };
-}
-
-#endif
index 5a12f11b9f799b2a3dfb32faf250d52436ec257f..e2fec5879d022ac23cf784f7813a7f5a56ee6f9f 100644 (file)
@@ -24,7 +24,7 @@ import cPickle
 
 class WrappedType(object):
     def __init__(self,varPtr,isTemporaryVar=False):
-        assert(isinstance(varPtr,SALOME._objref_StringDataServer))
+        assert(isinstance(varPtr,SALOME._objref_PickelizedPyObjRdWrServer))
         self._var_ptr=varPtr
         if not isTemporaryVar:
             self._var_ptr.Register()
@@ -66,10 +66,46 @@ class List(WrappedType):
     def __setitem__(self,*args):
         ret=Caller(self._var_ptr,"__setitem__")
         return ret(*args)
+    
+    def __delitem__(self,*args):
+        ret=Caller(self._var_ptr,"__delitem__")
+        return ret(*args)
 
     def append(self,*args):
         ret=Caller(self._var_ptr,"append")
-        return ret(*args) 
+        return ret(*args)
+
+    def extend(self,*args):
+        ret=Caller(self._var_ptr,"extend")
+        return ret(*args)
+
+    def insert(self,*args):
+        ret=Caller(self._var_ptr,"insert")
+        return ret(*args)
+
+    def pop(self,*args):
+        ret=Caller(self._var_ptr,"pop")
+        return ret(*args)
+
+    def remove(self,*args):
+        ret=Caller(self._var_ptr,"remove")
+        return ret(*args)
+
+    def reverse(self,*args):
+        ret=Caller(self._var_ptr,"reverse")
+        return ret(*args)
+
+    def sort(self,*args):
+        ret=Caller(self._var_ptr,"sort")
+        return ret(*args)
+
+    #
+    
+    def count(self,*args):
+        return self.local_copy().count(*args)
+
+    def index(self,*args):
+        return self.local_copy().index(*args)
 
     def __len__(self):
         return len(self.local_copy())
@@ -81,18 +117,17 @@ class Tuple(WrappedType):
         self._wrapped_type=tuple
         pass
 
-    def assign(self,elt):
-        st=cPickle.dumps(elt,cPickle.HIGHEST_PROTOCOL)
-        self._var_ptr.setSerializedContent(st)
-        pass
-
     def __getitem__(self,*args):
         ret=Caller(self._var_ptr,"__getitem__")
         return ret(*args)
+    
+    # work on local copy
 
-    def __setitem__(self,*args):
-        ret=Caller(self._var_ptr,"__setitem__")
-        return ret(*args)
+    def count(self,*args):
+        return self.local_copy().count(*args)
+
+    def index(self,*args):
+        return self.local_copy().index(*args)
     
     def __len__(self):
         return len(self.local_copy())
@@ -113,6 +148,56 @@ class Dict(WrappedType):
         ret=Caller(self._var_ptr,"__setitem__")
         return ret(*args)
 
+    def __delitem__(self,*args):
+        ret=Caller(self._var_ptr,"__delitem__")
+        return ret(*args)
+    
+    def clear(self,*args):
+        ret=Caller(self._var_ptr,"clear")
+        return ret(*args)
+
+    def get(self,*args):
+        ret=Caller(self._var_ptr,"get")
+        return ret(*args)
+
+    def items(self,*args):
+        ret=Caller(self._var_ptr,"items")
+        return ret(*args)
+
+    def pop(self,*args):
+        ret=Caller(self._var_ptr,"pop")
+        return ret(*args)
+
+    def popitem(self,*args):
+        ret=Caller(self._var_ptr,"popitem")
+        return ret(*args)
+
+    def setdefault(self,*args):
+        ret=Caller(self._var_ptr,"setdefault")
+        return ret(*args)
+
+    def update(self,*args):
+        ret=Caller(self._var_ptr,"update")
+        return ret(*args)
+
+    def values(self,*args):
+        ret=Caller(self._var_ptr,"values")
+        return ret(*args)
+    # work on local copy
+
+    def __contains__(self,*args):
+        return self.local_copy().__contains__(*args)
+
+    def has_key(self,*args):
+        return self.local_copy().has_key(*args)
+
+    def keys(self,*args):
+        return self.local_copy().keys(*args)
+
+    def copy(self,*args):
+        return self.local_copy().copy(*args)
+
     def __len__(self):
         return len(self.local_copy())
 
@@ -131,6 +216,62 @@ class Float(WrappedType):
     def __isub__(self,*args):
         ret=Caller(self._var_ptr,"__sub__")
         return ret(*args)
+
+    def __imul__(self,*args):
+        ret=Caller(self._var_ptr,"__mul__")
+        return ret(*args)
+
+    def __idiv__(self,*args):
+        ret=Caller(self._var_ptr,"__div__")
+        return ret(*args)
+
+    def __add__(self,*args):
+        ret=Caller(self._var_ptr,"__add__")
+        return ret(*args)
+
+    def __sub__(self,*args):
+        ret=Caller(self._var_ptr,"__sub__")
+        return ret(*args)
+
+    def __mul__(self,*args):
+        ret=Caller(self._var_ptr,"__mul__")
+        return ret(*args)
+
+    def __div__(self,*args):
+        ret=Caller(self._var_ptr,"__div__")
+        return ret(*args)
+    
+    def __pow__(self,*args):
+        ret=Caller(self._var_ptr,"__pow__")
+        return ret(*args)
+
+    def as_integer_ratio(self,*args):
+        ret=Caller(self._var_ptr,"as_integer_ratio")
+        return ret(*args)
+
+    def conjugate(self,*args):
+        ret=Caller(self._var_ptr,"conjugate")
+        return ret(*args)
+
+    def fromhex(self,*args):
+        ret=Caller(self._var_ptr,"fromhex")
+        return ret(*args)
+
+    def hex(self,*args):
+        ret=Caller(self._var_ptr,"hex")
+        return ret(*args)
+
+    def imag(self,*args):
+        ret=Caller(self._var_ptr,"imag")
+        return ret(*args)
+
+    def is_integer(self,*args):
+        ret=Caller(self._var_ptr,"is_integer")
+        return ret(*args)
+
+    def real(self,*args):
+        ret=Caller(self._var_ptr,"real")
+        return ret(*args)
     pass
 
 class Int(WrappedType):
@@ -170,6 +311,34 @@ class Int(WrappedType):
     def __div__(self,*args):
         ret=Caller(self._var_ptr,"__div__")
         return ret(*args)
+
+    def __pow__(self,*args):
+        ret=Caller(self._var_ptr,"__pow__")
+        return ret(*args)
+
+    def bit_length(self,*args):
+        ret=Caller(self._var_ptr,"bit_length")
+        return ret(*args)
+
+    def conjugate(self,*args):
+        ret=Caller(self._var_ptr,"conjugate")
+        return ret(*args)
+
+    def denominator(self,*args):
+        ret=Caller(self._var_ptr,"denominator")
+        return ret(*args)
+
+    def imag(self,*args):
+        ret=Caller(self._var_ptr,"imag")
+        return ret(*args)
+    
+    def numerator(self,*args):
+        ret=Caller(self._var_ptr,"numerator")
+        return ret(*args)
+
+    def real(self,*args):
+        ret=Caller(self._var_ptr,"real")
+        return ret(*args)
     pass
 
 class String(WrappedType):
@@ -177,11 +346,178 @@ class String(WrappedType):
         WrappedType.__init__(self,varPtr,isTemporaryVar)
         self._wrapped_type=int
         pass
+
+    def __add__(self,*args):
+        ret=Caller(self._var_ptr,"__add__")
+        return ret(*args)
+
+    def __iadd__(self,*args):
+        ret=Caller(self._var_ptr,"__add__")
+        return ret(*args)
+
+    def __getitem__(self,*args):
+        ret=Caller(self._var_ptr,"__getitem__")
+        return ret(*args)
+
+    def capitalize(self,*args):
+        ret=Caller(self._var_ptr,"capitalize")
+        return ret(*args)
+
+    def center(self,*args):
+        ret=Caller(self._var_ptr,"center")
+        return ret(*args)
+
+    def count(self,*args):
+        ret=Caller(self._var_ptr,"count")
+        return ret(*args)
+
+    def decode(self,*args):
+        ret=Caller(self._var_ptr,"decode")
+        return ret(*args)
+
+    def encode(self,*args):
+        ret=Caller(self._var_ptr,"encode")
+        return ret(*args)
+
+    def endswith(self,*args):
+        ret=Caller(self._var_ptr,"endswith")
+        return ret(*args)
+
+    def expandtabs(self,*args):
+        ret=Caller(self._var_ptr,"expandtabs")
+        return ret(*args)
+
+    def find(self,*args):
+        ret=Caller(self._var_ptr,"find")
+        return ret(*args)
+
+    def format(self,*args):
+        ret=Caller(self._var_ptr,"format")
+        return ret(*args)
+
+    def index(self,*args):
+        ret=Caller(self._var_ptr,"index")
+        return ret(*args)
+
+    def isalnum(self,*args):
+        ret=Caller(self._var_ptr,"isalnum")
+        return ret(*args)
+
+    def isalpha(self,*args):
+        ret=Caller(self._var_ptr,"isalpha")
+        return ret(*args)
+
+    def isdigit(self,*args):
+        ret=Caller(self._var_ptr,"isdigit")
+        return ret(*args)
+
+    def islower(self,*args):
+        ret=Caller(self._var_ptr,"islower")
+        return ret(*args)
+
+    def isspace(self,*args):
+        ret=Caller(self._var_ptr,"isspace")
+        return ret(*args)
+
+    def istitle(self,*args):
+        ret=Caller(self._var_ptr,"istitle")
+        return ret(*args)
+
+    def isupper(self,*args):
+        ret=Caller(self._var_ptr,"isupper")
+        return ret(*args)
+
+    def join(self,*args):
+        ret=Caller(self._var_ptr,"join")
+        return ret(*args)
+
+    def ljust(self,*args):
+        ret=Caller(self._var_ptr,"ljust")
+        return ret(*args)
+
+    def lower(self,*args):
+        ret=Caller(self._var_ptr,"lower")
+        return ret(*args)
+
+    def lstrip(self,*args):
+        ret=Caller(self._var_ptr,"lstrip")
+        return ret(*args)
+
+    def partition(self,*args):
+        ret=Caller(self._var_ptr,"partition")
+        return ret(*args)
+
+    def replace(self,*args):
+        ret=Caller(self._var_ptr,"replace")
+        return ret(*args)
+
+    def rfind(self,*args):
+        ret=Caller(self._var_ptr,"rfind")
+        return ret(*args)
+
+    def rindex(self,*args):
+        ret=Caller(self._var_ptr,"rindex")
+        return ret(*args)
+
+    def rjust(self,*args):
+        ret=Caller(self._var_ptr,"rjust")
+        return ret(*args)
+
+    def rpartition(self,*args):
+        ret=Caller(self._var_ptr,"rpartition")
+        return ret(*args)
+
+    def rsplit(self,*args):
+        ret=Caller(self._var_ptr,"rsplit")
+        return ret(*args)
+
+    def rstrip(self,*args):
+        ret=Caller(self._var_ptr,"rstrip")
+        return ret(*args)
+
+    def split(self,*args):
+        ret=Caller(self._var_ptr,"split")
+        return ret(*args)
+
+    def splitlines(self,*args):
+        ret=Caller(self._var_ptr,"splitlines")
+        return ret(*args)
+
+    def startswith(self,*args):
+        ret=Caller(self._var_ptr,"startswith")
+        return ret(*args)
+
+    def strip(self,*args):
+        ret=Caller(self._var_ptr,"strip")
+        return ret(*args)
+
+    def swapcase(self,*args):
+        ret=Caller(self._var_ptr,"swapcase")
+        return ret(*args)
+
+    def title(self,*args):
+        ret=Caller(self._var_ptr,"title")
+        return ret(*args)
+
+    def translate(self,*args):
+        ret=Caller(self._var_ptr,"translate")
+        return ret(*args)
+
+    def upper(self,*args):
+        ret=Caller(self._var_ptr,"upper")
+        return ret(*args)
+
+    def zfill(self,*args):
+        ret=Caller(self._var_ptr,"zfill")
+        return ret(*args)
+
+    def __len__(self):
+        return len(self.local_copy())
     pass
 
 class Caller:
     def __init__(self,varPtr,meth):
-        assert(isinstance(varPtr,SALOME._objref_StringDataServer))
+        assert(isinstance(varPtr,SALOME._objref_PickelizedPyObjRdWrServer))
         self._var_ptr=varPtr
         self._meth=meth
         pass
@@ -196,7 +532,7 @@ PyHandlerTypeMap={int:Int,float:Float,str:String,list:List,tuple:Tuple,dict:Dict
 def GetHandlerFromRef(objCorba,isTempVar=False):
     """ Returns a client that allows to handle a remote corba ref of a global var easily.
     """
-    assert(isinstance(objCorba,SALOME._objref_StringDataServer))
+    assert(isinstance(objCorba,SALOME._objref_PickelizedPyObjRdWrServer))
     v=cPickle.loads(objCorba.fetchSerializedContent())
     if v is None:
         return None
index 44ab8edb333e30e7688a9ebdf222a5899bff895d..af073282753660b35fa5399787abf6d314689e65 100644 (file)
@@ -32,14 +32,14 @@ assert(isinstance(dsm,SALOME._objref_DataServerManager))
 assert(isinstance(dsm.getDefaultScope(),SALOME._objref_DataScopeServer))
 d2s=dsm.createDataScope("tonyy")
 assert(isinstance(d2s,SALOME._objref_DataScopeServer))
-a=d2s.createGlobalStringVar("str","c")
+a=d2s.createRdWrVar("str","c")
 assert(a.getVarName()=="c")
 #
 a.setSerializedContent(cPickle.dumps(st,cPickle.HIGHEST_PROTOCOL))
 assert(cPickle.loads(a.fetchSerializedContent())==st)
 assert(cPickle.loads(a.fetchSerializedContent())==st)
 assert(cPickle.loads(d2s.retrieveVar("c").fetchSerializedContent())==st)
-assert(isinstance(d2s.retrieveVar("c"),SALOME._objref_StringDataServer))
+assert(isinstance(d2s.retrieveVar("c"),SALOME._objref_PickelizedPyObjRdWrServer))
 assert(dsm.listScopes()==['Default','tonyy'])
 dsm.createDataScope("S2")
 assert(dsm.retriveDataScope("S2").getScopeName()=="S2")
@@ -48,12 +48,12 @@ dsm.removeDataScope("Default")
 assert(dsm.listScopes()==['tonyy','S2'])
 dsm.removeDataScope("tonyy")
 assert(dsm.listScopes()==['S2'])
-a=dsm.retriveDataScope("S2").createGlobalStringVar("int","a")
+a=dsm.retriveDataScope("S2").createRdWrVar("int","a")
 #
 sname="S7"
 dsm=salome.naming_service.Resolve("/DataServerManager")
 st=cPickle.dumps([],cPickle.HIGHEST_PROTOCOL)
-a=dsm.giveADataScopeCalled(sname).createGlobalStringVar("list","a")
+a=dsm.giveADataScopeCalled(sname).createRdWrVar("list","a")
 dsm.giveADataScopeCalled(sname)
 a.setSerializedContent(cPickle.dumps([0,],cPickle.HIGHEST_PROTOCOL))
 assert(cPickle.loads(a.fetchSerializedContent())==[0,])
@@ -68,7 +68,7 @@ dsm.removeDataScope(sname)
 #
 sname="S4"
 d2s=dsm.giveADataScopeCalled(sname)
-d2s.createGlobalStringVar("list","a")
+d2s.createRdWrVar("list","a")
 a=SalomeSDSClt.GetHandlerFromRef(dsm.retriveDataScope(sname).retrieveVar("a"))
 a.append(1)
 for i in xrange(1000):
@@ -80,7 +80,7 @@ assert(dsm.isAliveAndKicking(sname))
 dsm=salome.naming_service.Resolve("/DataServerManager")
 sname="S11"
 d2s=dsm.giveADataScopeCalled(sname)
-d2s.createGlobalStringVar("dict","a")
+d2s.createRdWrVar("dict","a")
 a=SalomeSDSClt.GetHandlerFromName(sname,"a")
 assert(isinstance(a,SalomeSDSClt.Dict))
 a.assign({})