X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSALOMESDS%2FSALOMESDS_PickelizedPyObjServer.cxx;fp=src%2FSALOMESDS%2FSALOMESDS_PickelizedPyObjServer.cxx;h=baba4b55dada2a18f7d72449e0e7da638e2f7cfd;hb=8a89a50b36a47cba1839646c0623562f30af9c28;hp=0000000000000000000000000000000000000000;hpb=755e4a1a2d81db80a3a46d3c2d55d74e1853d5bf;p=modules%2Fkernel.git diff --git a/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.cxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.cxx new file mode 100644 index 000000000..baba4b55d --- /dev/null +++ b/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.cxx @@ -0,0 +1,161 @@ +// 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 +#include + +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(0) +{ + setNewPyObj(obj); +} + +PickelizedPyObjServer::~PickelizedPyObjServer() +{ + Py_XDECREF(_self); +} + +/*! + * Called remotely -> to protect against throw + */ +SALOME::ByteVec *PickelizedPyObjServer::fetchSerializedContent() +{ + Py_XINCREF(_self);//because pickelize consume _self + return FromCppToByteSeq(pickelize(_self)); +} + +void PickelizedPyObjServer::FromByteSeqToCpp(const SALOME::ByteVec& bsToBeConv, std::string& ret) +{ + std::size_t sz(bsToBeConv.length()); + ret.resize(sz,' '); + char *buf(const_cast(ret.c_str())); + for(std::size_t i=0;ilength(sz); + for(std::size_t i=0;igetPickler(),"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(ret.c_str())); + for(std::size_t i=0;i