Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/med.git] / src / MEDCouplingCorba_Swig / MEDCouplingCorbaTypemaps.i
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 template<class TServant>
21 static PyObject *buildServantAndActivate(const typename TServant::CppType *pt)
22 {
23   int argc=0;
24   TServant *serv=new TServant(pt);
25   CORBA::ORB_var orb=CORBA::ORB_init(argc,0);
26   CORBA::Object_var obj=orb->resolve_initial_references("RootPOA");
27   PortableServer::POA_var poa=PortableServer::POA::_narrow(obj);
28   PortableServer::POAManager_var mgr=poa->the_POAManager();
29   mgr->activate();
30   CORBA::Object_var ret=serv->_this();
31   char *ior=orb->object_to_string(ret);
32   PyObject *iorPython=PyString_FromString(ior);
33   PyObject* pdict=PyDict_New();
34   PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
35   PyRun_String("import MEDCouplingCorbaServant_idl", Py_single_input, pdict, pdict);
36   PyRun_String("import CORBA", Py_single_input, pdict, pdict);
37   PyRun_String("orbTmp15634=CORBA.ORB_init([''])",Py_single_input,pdict, pdict);
38   PyObject* orbPython=PyDict_GetItemString(pdict,"orbTmp15634");
39   PyObject *corbaObj=PyObject_CallMethod(orbPython,(char*)"string_to_object",(char*)"O",iorPython);
40   Py_DECREF(pdict);
41   Py_DECREF(iorPython);
42   CORBA::string_free(ior);
43   return corbaObj;
44 }
45