1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony GEAY (EDF R&D)
21 #include "SALOMESDS_PickelizedPyObjRdWrServer.hxx"
22 #include "SALOMESDS_DataScopeServer.hxx"
23 #include "SALOMESDS_Exception.hxx"
28 using namespace SALOMESDS;
30 PickelizedPyObjRdWrServer::PickelizedPyObjRdWrServer(DataScopeServer *father, const std::string& typeName, const std::string& varName):PickelizedPyObjServer(father,varName,CreateDftObjFromType(father->getGlobals(),typeName))
34 PickelizedPyObjRdWrServer::PickelizedPyObjRdWrServer(DataScopeServer *father, const std::string& varName, const SALOME::ByteVec& value):PickelizedPyObjServer(father,varName,value)
39 PickelizedPyObjRdWrServer::PickelizedPyObjRdWrServer(DataScopeServer *father, const std::string& varName, PyObject *obj):PickelizedPyObjServer(father,varName,obj)
43 PickelizedPyObjRdWrServer::~PickelizedPyObjRdWrServer()
48 * Called remotely -> to protect against throw
50 void PickelizedPyObjRdWrServer::setSerializedContent(const SALOME::ByteVec& newValue)
52 setSerializedContentInternal(newValue);
56 * Called remotely -> to protect against throw
58 SALOME::PickelizedPyObjRdWrServer_ptr PickelizedPyObjRdWrServer::invokePythonMethodOn(const char *method, const SALOME::ByteVec& args)
61 throw Exception("PickelizedPyObjRdWrServer::invokePythonMethodOn : self is NULL !");
63 FromByteSeqToCpp(args,argsCpp);
64 PyObject *argsPy(getPyObjFromPickled(argsCpp));
66 PyObject *selfMeth(PyObject_GetAttrString(_self,method));
69 std::ostringstream oss; oss << "PickelizedPyObjRdWrServer::invokePythonMethodOn : Method \"" << method << "\" is not available !";
70 throw Exception(oss.str());
72 PyObject *res(PyObject_CallObject(selfMeth,argsPy));// self can have been modified by this call !
77 std::ostringstream oss,oss2,oss3;
78 PyObject *errTyp(0),*errValue(0),*errTB(0);
79 PyErr_Fetch(&errTyp,&errValue,&errTB);
83 PyObject *ob(PyObject_Str(errTyp));
84 oss2 << " type : \"" << (const char *)PyString_AsString(ob) << "\"";
85 Py_XDECREF(ob); Py_XDECREF(errTyp);
89 PyObject *ob(PyObject_Str(errValue));
90 oss2 << " value : \"" << (const char *)PyString_AsString(ob) << "\"";
91 Py_XDECREF(ob); Py_XDECREF(errValue);
96 PyObject *ob(PyObject_Str(errTB));
97 oss2 << "( traceback : \"" << (const char *)PyString_AsString(ob) << "\"";
98 Py_XDECREF(ob); Py_XDECREF(errTB);
102 oss << "PickelizedPyObjRdWrServer::invokePythonMethodOn : Problem during invokation serverside of Method \"" << method << "\" ! Details are : " << oss2.str() << "\n\n" << "TraceBack is : " << oss3.str();
103 throw Exception(oss.str());
105 PickelizedPyObjRdWrServer *ret(new PickelizedPyObjRdWrServer(_father,DataScopeServer::BuildTmpVarNameFrom(getVarNameCpp()),res));
106 PortableServer::POA_var poa(_father->getPOA());
107 PortableServer::ObjectId_var id(poa->activate_object(ret));
108 CORBA::Object_var obj(poa->id_to_reference(id));
109 return SALOME::PickelizedPyObjRdWrServer::_narrow(obj);