1 // Copyright (C) 2007-2020 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 const char PickelizedPyObjRdWrServer::ACCESS_REPR[]="RdWr";
32 PickelizedPyObjRdWrServer::PickelizedPyObjRdWrServer(DataScopeServerBase *father, const std::string& typeName, const std::string& varName):PickelizedPyObjServerModifiable(father,varName,CreateDftObjFromType(father->getGlobals(),typeName))
36 PickelizedPyObjRdWrServer::PickelizedPyObjRdWrServer(DataScopeServerBase *father, const std::string& varName, const SALOME::ByteVec& value):PickelizedPyObjServerModifiable(father,varName,value)
41 PickelizedPyObjRdWrServer::PickelizedPyObjRdWrServer(DataScopeServerBase *father, const std::string& varName, PyObject *obj):PickelizedPyObjServerModifiable(father,varName,obj)
45 PickelizedPyObjRdWrServer::~PickelizedPyObjRdWrServer()
50 * Called remotely -> to protect against throw
52 void PickelizedPyObjRdWrServer::setSerializedContent(const SALOME::ByteVec& newValue)
54 setSerializedContentInternal(newValue);
57 SALOME::PickelizedPyObjRdWrServer_ptr PickelizedPyObjRdWrServer::invokePythonMethodOn(const char *method, const SALOME::ByteVec& args)
60 throw Exception("PickelizedPyObjRdWrServer::invokePythonMethodOn : self is NULL !");
62 FromByteSeqToCpp(args,argsCpp);
63 PyObject *argsPy(getPyObjFromPickled(argsCpp));
65 PyObject *selfMeth(PyObject_GetAttrString(_self,method));
68 std::ostringstream oss; oss << "PickelizedPyObjRdWrServer::invokePythonMethodOn : Method \"" << method << "\" is not available !";
69 throw Exception(oss.str());
71 PyObject *res(PyObject_CallObject(selfMeth,argsPy));// self can have been modified by this call !
76 std::ostringstream oss,oss2,oss3;
77 PyObject *errTyp(0),*errValue(0),*errTB(0);
78 PyErr_Fetch(&errTyp,&errValue,&errTB);
82 PyObject *ob(PyObject_Str(errTyp));
83 oss2 << " type : \"" << (const char *)PyUnicode_AsUTF8(ob) << "\"";
84 Py_XDECREF(ob); Py_XDECREF(errTyp);
88 PyObject *ob(PyObject_Str(errValue));
89 oss2 << " value : \"" << (const char *)PyUnicode_AsUTF8(ob) << "\"";
90 Py_XDECREF(ob); Py_XDECREF(errValue);
95 PyObject *ob(PyObject_Str(errTB));
96 oss2 << "( traceback : \"" << (const char *)PyUnicode_AsUTF8(ob) << "\"";
97 Py_XDECREF(ob); Py_XDECREF(errTB);
101 oss << "PickelizedPyObjRdWrServer::invokePythonMethodOn : Problem during invocation serverside of Method \"" << method << "\" ! Details are : " << oss2.str() << "\n\n" << "TraceBack is : " << oss3.str();
102 throw Exception(oss.str());
104 PickelizedPyObjRdWrServer *ret(new PickelizedPyObjRdWrServer(_father,DataScopeServer::BuildTmpVarNameFrom(getVarNameCpp()),res));
105 PortableServer::POA_var poa(_father->getPOA());
106 PortableServer::ObjectId_var id(poa->activate_object(ret));
107 CORBA::Object_var obj(poa->id_to_reference(id));
108 return SALOME::PickelizedPyObjRdWrServer::_narrow(obj);
111 void PickelizedPyObjRdWrServer::addKeyValueHard(PyObject *key, PyObject *value)
113 bool isOK(PyDict_SetItem(_self,key,value)==0);
115 throw Exception("PickelizedPyObjRdWrServer::addKeyValueHard : error when trying to add key,value to dict !");
118 std::string PickelizedPyObjRdWrServer::getAccessStr() const
120 return std::string(ACCESS_REPR);