From cb35368390b8b2f3741f5321838b1ede8fc99708 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Wed, 7 Jan 2015 17:52:49 +0100 Subject: [PATCH] on the road of read only and read ext. coming soon \! --- idl/SALOME_SDS.idl | 25 +- src/SALOMESDS/CMakeLists.txt | 5 +- src/SALOMESDS/SALOMESDS_BasicDataServer.cxx | 24 +- src/SALOMESDS/SALOMESDS_BasicDataServer.hxx | 7 - src/SALOMESDS/SALOMESDS_DataScopeServer.cxx | 52 +-- src/SALOMESDS/SALOMESDS_DataScopeServer.hxx | 5 +- .../SALOMESDS_PickelizedPyObjRdExtServer.cxx | 74 ++++ .../SALOMESDS_PickelizedPyObjRdExtServer.hxx | 43 +++ .../SALOMESDS_PickelizedPyObjRdOnlyServer.cxx | 35 ++ .../SALOMESDS_PickelizedPyObjRdOnlyServer.hxx | 42 ++ .../SALOMESDS_PickelizedPyObjRdWrServer.cxx | 87 +++++ .../SALOMESDS_PickelizedPyObjRdWrServer.hxx | 45 +++ ...xx => SALOMESDS_PickelizedPyObjServer.cxx} | 85 +---- ...xx => SALOMESDS_PickelizedPyObjServer.hxx} | 18 +- src/SALOMESDS/SalomeSDSClt.py | 360 +++++++++++++++++- src/SALOMESDS/TestSalomeSDS1.py | 12 +- 16 files changed, 760 insertions(+), 159 deletions(-) create mode 100644 src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.cxx create mode 100644 src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.hxx create mode 100644 src/SALOMESDS/SALOMESDS_PickelizedPyObjRdOnlyServer.cxx create mode 100644 src/SALOMESDS/SALOMESDS_PickelizedPyObjRdOnlyServer.hxx create mode 100644 src/SALOMESDS/SALOMESDS_PickelizedPyObjRdWrServer.cxx create mode 100644 src/SALOMESDS/SALOMESDS_PickelizedPyObjRdWrServer.hxx rename src/SALOMESDS/{SALOMESDS_StringDataServer.cxx => SALOMESDS_PickelizedPyObjServer.cxx} (52%) rename src/SALOMESDS/{SALOMESDS_StringDataServer.hxx => SALOMESDS_PickelizedPyObjServer.hxx} (75%) diff --git a/idl/SALOME_SDS.idl b/idl/SALOME_SDS.idl index 9fcc3ec85..27b930687 100644 --- a/idl/SALOME_SDS.idl +++ b/idl/SALOME_SDS.idl @@ -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(); }; diff --git a/src/SALOMESDS/CMakeLists.txt b/src/SALOMESDS/CMakeLists.txt index 421c27f60..b86b57676 100644 --- a/src/SALOMESDS/CMakeLists.txt +++ b/src/SALOMESDS/CMakeLists.txt @@ -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}) diff --git a/src/SALOMESDS/SALOMESDS_BasicDataServer.cxx b/src/SALOMESDS/SALOMESDS_BasicDataServer.cxx index d002d2fb9..4d3e89151 100644 --- a/src/SALOMESDS/SALOMESDS_BasicDataServer.cxx +++ b/src/SALOMESDS/SALOMESDS_BasicDataServer.cxx @@ -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); -} diff --git a/src/SALOMESDS/SALOMESDS_BasicDataServer.hxx b/src/SALOMESDS/SALOMESDS_BasicDataServer.hxx index d6139aabc..e0ed15dbf 100644 --- a/src/SALOMESDS/SALOMESDS_BasicDataServer.hxx +++ b/src/SALOMESDS/SALOMESDS_BasicDataServer.hxx @@ -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; }; } diff --git a/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx b/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx index a1a109496..8f9aabcbc 100644 --- a/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx +++ b/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx @@ -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 allNames(getAllVarNames()); - std::vector::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 tmp(new StringDataServer(this,typeNameCpp,varNameCpp)); + std::string varNameCpp(varName); + checkNotAlreadyExistingVar(varNameCpp); + AutoRefCountPtr tmp(new PickelizedPyObjRdOnlyServer(this,varNameCpp,constValue)); CORBA::Object_var ret(activateWithDedicatedPOA(tmp)); - std::pair< SALOME::BasicDataServer_var, AutoRefCountPtr > p(SALOME::BasicDataServer::_narrow(ret),DynamicCastSafe(tmp)); + std::pair< SALOME::BasicDataServer_var, AutoRefCountPtr > p(SALOME::BasicDataServer::_narrow(ret),DynamicCastSafe(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 tmp(new PickelizedPyObjRdWrServer(this,typeNameCpp,varNameCpp)); + CORBA::Object_var ret(activateWithDedicatedPOA(tmp)); + std::pair< SALOME::BasicDataServer_var, AutoRefCountPtr > p(SALOME::BasicDataServer::_narrow(ret),DynamicCastSafe(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 allNames(getAllVarNames()); + std::vector::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()); + } +} diff --git a/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx b/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx index cf80fee60..8a06052c7 100644 --- a/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx +++ b/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx @@ -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 index 000000000..ff381642f --- /dev/null +++ b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.cxx @@ -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 +#include + +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 index 000000000..100d1c550 --- /dev/null +++ b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.hxx @@ -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 + +#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 index 000000000..4626d00da --- /dev/null +++ b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdOnlyServer.cxx @@ -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 index 000000000..68924a737 --- /dev/null +++ b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdOnlyServer.hxx @@ -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 + +#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 index 000000000..34872047e --- /dev/null +++ b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdWrServer.cxx @@ -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 +#include + +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 index 000000000..fe33ca229 --- /dev/null +++ b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdWrServer.hxx @@ -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 + +#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_StringDataServer.cxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.cxx similarity index 52% rename from src/SALOMESDS/SALOMESDS_StringDataServer.cxx rename to src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.cxx index 8bece7749..53c0b1ad4 100644 --- a/src/SALOMESDS/SALOMESDS_StringDataServer.cxx +++ b/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.cxx @@ -18,7 +18,7 @@ // // Author : Anthony GEAY (EDF R&D) -#include "SALOMESDS_StringDataServer.hxx" +#include "SALOMESDS_PickelizedPyObjServer.hxx" #include "SALOMESDS_DataScopeServer.hxx" #include "SALOMESDS_Exception.hxx" @@ -27,83 +27,37 @@ 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) +PickelizedPyObjServer::PickelizedPyObjServer(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) +PickelizedPyObjServer::PickelizedPyObjServer(DataScopeServer *father, const std::string& varName, PyObject *obj):BasicDataServer(father,varName),_self(obj) { } -StringDataServer::~StringDataServer() +PickelizedPyObjServer::~PickelizedPyObjServer() { - std::cerr << "~~~~~~~~~~ StringDataServer : " << getVarNameCpp() << std::endl; + std::cerr << "~~~~~~~~~~ PickelizedPyObjServer : " << 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() +SALOME::ByteVec *PickelizedPyObjServer::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() +PortableServer::POA_var PickelizedPyObjServer::getPOA() { return _poa; } -void StringDataServer::FromByteSeqToCpp(const SALOME::ByteVec& bsToBeConv, std::string& ret) +void PickelizedPyObjServer::FromByteSeqToCpp(const SALOME::ByteVec& bsToBeConv, std::string& ret) { std::size_t sz(bsToBeConv.length()); ret.resize(sz,' '); @@ -112,7 +66,7 @@ void StringDataServer::FromByteSeqToCpp(const SALOME::ByteVec& bsToBeConv, std:: buf[i]=bsToBeConv[i]; } -SALOME::ByteVec *StringDataServer::FromCppToByteSeq(const std::string& strToBeConv) +SALOME::ByteVec *PickelizedPyObjServer::FromCppToByteSeq(const std::string& strToBeConv) { SALOME::ByteVec *ret(new SALOME::ByteVec); const char *buf(strToBeConv.c_str()); @@ -124,7 +78,7 @@ SALOME::ByteVec *StringDataServer::FromCppToByteSeq(const std::string& strToBeCo } //! New reference returned -PyObject *StringDataServer::getPyObjFromPickled(const std::string& pickledData) +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. @@ -140,7 +94,7 @@ PyObject *StringDataServer::getPyObjFromPickled(const std::string& pickledData) } //! obj is consumed by this method. -std::string StringDataServer::pickelize(PyObject *obj) +std::string PickelizedPyObjServer::pickelize(PyObject *obj) { PyObject *args(PyTuple_New(2)); PyTuple_SetItem(args,0,obj); @@ -160,10 +114,10 @@ std::string StringDataServer::pickelize(PyObject *obj) } //! obj is consumed by this method. -void StringDataServer::setNewPyObj(PyObject *obj) +void PickelizedPyObjServer::setNewPyObj(PyObject *obj) { if(!obj) - throw Exception("StringDataServer::setNewPyObj : trying to assign a NULL pyobject in this !"); + throw Exception("PickelizedPyObjServer::setNewPyObj : trying to assign a NULL pyobject in this !"); if(obj==_self) return ; if(_self) @@ -173,7 +127,7 @@ void StringDataServer::setNewPyObj(PyObject *obj) { Py_XDECREF(obj); Py_XDECREF(selfType); - throw Exception("StringDataServer::setNewPyObj : type of new object is not the same than those previously set !"); + throw Exception("PickelizedPyObjServer::setNewPyObj : type of new object is not the same than those previously set !"); } else Py_XDECREF(selfType); @@ -182,26 +136,25 @@ void StringDataServer::setNewPyObj(PyObject *obj) _self=obj; } -void StringDataServer::setSerializedContentInternal(const SALOME::ByteVec& newValue) +void PickelizedPyObjServer::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 *PickelizedPyObjServer::CreateDftObjFromType(PyObject *globals, const std::string& typeName) { PyObject *builtins(PyDict_GetItemString(globals,"__builtins__")); if(!builtins) - throw Exception("StringDataServer constructor : no __builtins__ in globals !"); + throw Exception("PickelizedPyObjServer constructor : no __builtins__ in globals !"); PyObject *builtins2(PyModule_GetDict(builtins)); if(!builtins2) - throw Exception("StringDataServer constructor : internal error fail to invoke __dict__ on __builtins__ !"); + 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 << "StringDataServer::CreateDftObjFromType : Invalid type name \"" << typeName << "\" !"; + std::ostringstream oss; oss << "PickelizedPyObjServer::CreateDftObjFromType : Invalid type name \"" << typeName << "\" !"; throw Exception(oss.str()); } PyObject *args(PyTuple_New(0)); diff --git a/src/SALOMESDS/SALOMESDS_StringDataServer.hxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.hxx similarity index 75% rename from src/SALOMESDS/SALOMESDS_StringDataServer.hxx rename to src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.hxx index 0385cebaf..cc691bdb8 100644 --- a/src/SALOMESDS/SALOMESDS_StringDataServer.hxx +++ b/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.hxx @@ -18,8 +18,8 @@ // // Author : Anthony GEAY (EDF R&D) -#ifndef __SALOMESDS_STRINGDATASERVER_HXX__ -#define __SALOMESDS_STRINGDATASERVER_HXX__ +#ifndef __SALOMESDS_PICKELIZEDPYOBJSERVER_HXX__ +#define __SALOMESDS_PICKELIZEDPYOBJSERVER_HXX__ #include "SALOMEconfig.h" #include CORBA_SERVER_HEADER(SALOME_SDS) @@ -30,19 +30,17 @@ namespace SALOMESDS { - class StringDataServer : public BasicDataServer, public virtual POA_SALOME::StringDataServer + class PickelizedPyObjServer : public BasicDataServer, public virtual POA_SALOME::PickelizedPyObjServer { 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(); + 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(); - SALOME::StringDataServer_ptr invokePythonMethodOn(const char *method, const SALOME::ByteVec& args); public: void setPOA(PortableServer::POA_var poa) { _poa=poa; } - private: + protected: PortableServer::POA_var getPOA(); static void FromByteSeqToCpp(const SALOME::ByteVec& bsToBeConv, std::string& ret); static SALOME::ByteVec *FromCppToByteSeq(const std::string& strToBeConv); @@ -51,7 +49,7 @@ namespace SALOMESDS void setNewPyObj(PyObject *obj); void setSerializedContentInternal(const SALOME::ByteVec& newValue); static PyObject *CreateDftObjFromType(PyObject *globals, const std::string& typeName); - private: + protected: static const char FAKE_VAR_NAME_FOR_WORK[]; PyObject *_self; PortableServer::POA_var _poa; diff --git a/src/SALOMESDS/SalomeSDSClt.py b/src/SALOMESDS/SalomeSDSClt.py index 5a12f11b9..e2fec5879 100644 --- a/src/SALOMESDS/SalomeSDSClt.py +++ b/src/SALOMESDS/SalomeSDSClt.py @@ -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 diff --git a/src/SALOMESDS/TestSalomeSDS1.py b/src/SALOMESDS/TestSalomeSDS1.py index 44ab8edb3..af0732827 100644 --- a/src/SALOMESDS/TestSalomeSDS1.py +++ b/src/SALOMESDS/TestSalomeSDS1.py @@ -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({}) -- 2.39.2