From: Anthony Geay Date: Thu, 30 Oct 2014 15:19:09 +0000 (+0100) Subject: A good version. TODO : 1 - multi levels management 2 - clean exception handling X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6031b8623629f32d54eb31d07317ec41e802611a;p=modules%2Fkernel.git A good version. TODO : 1 - multi levels management 2 - clean exception handling --- diff --git a/src/SALOMESDS/SALOMEGlobalVarHelper.py b/src/SALOMESDS/SALOMEGlobalVarHelper.py new file mode 100644 index 000000000..d551f788a --- /dev/null +++ b/src/SALOMESDS/SALOMEGlobalVarHelper.py @@ -0,0 +1,61 @@ +# -*- coding: iso-8859-1 -*- +# Copyright (C) 2007-2014 CEA/DEN, EDF R&D +# +# 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 + +import SALOME +import cPickle + +class SALOMEGlobalVarMethodHelper: + def __init__(self,varPtr,meth): + assert(isinstance(varPtr,SALOME._objref_StringDataServer)) + self._var_ptr=varPtr + self._meth=meth + pass + + def __call__(self,*args): + #print "__call__ %s : %s"%(self._meth,str(args)) + ret=self._var_ptr.invokePythonMethodOn(self._meth,cPickle.dumps(args,cPickle.HIGHEST_PROTOCOL)) + return cPickle.loads(ret) + pass + +class SALOMEGlobalVarHelper: + def __init__(self,varPtr): + assert(isinstance(varPtr,SALOME._objref_StringDataServer)) + self._var_ptr=varPtr + pass + + def assign(self,elt): + st=cPickle.dumps(elt,cPickle.HIGHEST_PROTOCOL) + self._var_ptr.setValueOf(st) + pass + + def __getattr__(self,*args): + #print "__getattr__,%s"%(str(args)) + return SALOMEGlobalVarMethodHelper(self._var_ptr,args[0]) + + def __str__(self): + return self.local_copy().__str__() + + def __repr__(self): + return self.local_copy().__repr__() + + def local_copy(self): + return cPickle.loads(self._var_ptr.getValueOf()) + pass diff --git a/src/SALOMESDS/SALOMESDS_StringDataServer.cxx b/src/SALOMESDS/SALOMESDS_StringDataServer.cxx index 805a2153b..40da23cf3 100644 --- a/src/SALOMESDS/SALOMESDS_StringDataServer.cxx +++ b/src/SALOMESDS/SALOMESDS_StringDataServer.cxx @@ -68,6 +68,11 @@ SALOME::ByteVec *StringDataServer::invokePythonMethodOn(const char *method, cons throw Exception(oss.str()); } PyObject *res(PyObject_CallObject(selfMeth,argsPy)); + if(!res) + { + std::ostringstream oss; oss << "StringDataServer::invokePythonMethodOn : Problem during invokation serverside of Method \"" << method << "\" !"; + throw Exception(oss.str()); + } _data=pickelize(self);// if it is a non const method ! std::string retCpp(pickelize(res)); // to test : res and self