1 // Copyright (C) 2007-2023 CEA/DEN, EDF R&D
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 (CEA/DEN)
21 template<class TServant>
22 static PyObject *buildServantAndActivateCore(const typename TServant::CppType *pt, std::string& iorOut)
25 TServant *serv=new TServant(pt);
26 CORBA::ORB_var orb=CORBA::ORB_init(argc,0);
27 CORBA::Object_var obj=orb->resolve_initial_references("RootPOA");
28 PortableServer::POA_var poa=PortableServer::POA::_narrow(obj);
29 PortableServer::POAManager_var mgr=poa->the_POAManager();
31 CORBA::Object_var ret=serv->_this();
32 char *ior=orb->object_to_string(ret);
34 PyObject *iorPython=PyString_FromString(ior);
35 PyObject* pdict=PyDict_New();
36 PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
37 PyRun_String("import MEDCouplingCorbaServant_idl", Py_single_input, pdict, pdict);
38 PyRun_String("import CORBA", Py_single_input, pdict, pdict);
39 PyRun_String("orbTmp15634=CORBA.ORB_init([''])",Py_single_input,pdict, pdict);
40 PyObject* orbPython=PyDict_GetItemString(pdict,"orbTmp15634");
41 PyObject *corbaObj=PyObject_CallMethod(orbPython,const_cast<char*>("string_to_object"),const_cast<char*>("O"),iorPython);
44 CORBA::string_free(ior);
48 template<class TServant>
49 static PyObject *buildServantAndActivate(const typename TServant::CppType *pt)
52 return buildServantAndActivateCore<TServant>(pt,dummy);
55 template<class TServant>
56 static PyObject *buildServantAndActivate2(const typename TServant::CppType *pt)
59 PyObject *ret0Py=buildServantAndActivateCore<TServant>(pt,ret1Cpp);
60 PyObject *ret=PyTuple_New(2);
61 PyTuple_SetItem(ret,0,ret0Py);
62 PyTuple_SetItem(ret,1,PyString_FromString(ret1Cpp.c_str()));