1 // Copyright (C) 2006-2019 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
23 #define private public
24 #define protected public
25 #include <omniORB4/CORBA.h>
26 #include <omniORB4/internal/typecode.h>
29 #include "PythonCORBAConv.hxx"
30 #include "TypeConversions.hxx"
31 #include "RuntimeSALOME.hxx"
32 #include "PythonPorts.hxx"
37 #include "YacsTrace.hxx"
39 using namespace YACS::ENGINE;
42 /*!Convert a PyObject (integer) to CORBA::Any (integer)
43 * It's only a wrapper around put(PyObject *data)
45 void PyCorbaInt::put(const void *data) throw(ConversionException)
47 put((PyObject *)data);
50 //!Convert a PyObject (integer) to CORBA::Any (integer)
52 * \param data : python object
54 void PyCorbaInt::put(PyObject *data) throw(ConversionException)
56 CORBA::Any *a= convertPyObjectCorba(_port->edGetType(),data);
57 YACS::ENGINE::InterpreterSaveThread _loc;
62 //!Convert a PyObject (boolean) to CORBA::Any (boolean)
64 * It's only a wrapper around PyCorbaBool::put(PyObject *data)
66 * \param data : python object
68 void PyCorbaBool::put(const void *data) throw(ConversionException)
70 put((PyObject *)data);
73 //!Convert a PyObject (boolean) to CORBA::Any (boolean)
75 * Convert it and push it to proxy port
77 * \param data : python object
79 void PyCorbaBool::put(PyObject *data) throw(ConversionException)
81 CORBA::Any *a= convertPyObjectCorba(_port->edGetType(),data);
82 YACS::ENGINE::InterpreterSaveThread _loc;
84 //delete Any that has been allocated by convertPyObjectCorba
88 void PyCorbaString::put(const void *data) throw(ConversionException)
90 put((PyObject *)data);
93 //!Convert a PyObject (string) to CORBA::Any (string)
95 * \param data : python object
98 void PyCorbaString::put(PyObject *data) throw(ConversionException)
100 CORBA::Any *a= convertPyObjectCorba(_port->edGetType(),data);
101 YACS::ENGINE::InterpreterSaveThread _loc;
107 void PyCorbaDouble::put(const void *data) throw(ConversionException)
109 put((PyObject *)data);
112 //!Convert a PyObject (double) to CORBA::Any (double)
114 * \param data : python object
117 void PyCorbaDouble::put(PyObject *data) throw(ConversionException)
119 CORBA::Any *a= convertPyObjectCorba(_port->edGetType(),data);
120 YACS::ENGINE::InterpreterSaveThread _loc;
125 //!Class PyCorbaSequence is a proxy port that converts a PyObject object (of type sequence) to a CORBA::Any object (of type sequence)
127 * \param p : the input CORBA port to adapt to Python output port
129 PyCorbaSequence::PyCorbaSequence(InputCorbaPort* p)
130 : ProxyPort(p), DataPort(p->getName(), p->getNode(), p->edGetType()), Port(p->getNode())
134 //!Convert a PyObject (sequence) to CORBA::Any (sequence)
136 * \param data : python object
139 void PyCorbaSequence::put(const void *data) throw(ConversionException)
141 put((PyObject *)data);
144 void PyCorbaSequence::put(PyObject *data) throw(ConversionException)
146 DEBTRACE("data refcnt: " << data->ob_refcnt);
148 PyObject_Print(data,stderr,Py_PRINT_RAW);
149 std::cerr << std::endl;
151 CORBA::Any *a= convertPyObjectCorba(_port->edGetType(),data);
152 YACS::ENGINE::InterpreterSaveThread _loc;
155 DEBTRACE("refcount CORBA seqTC: " << ((omni::TypeCode_base*)a->pd_tc.in())->pd_ref_count);
157 //delete Any that has been allocated by convertPyObjectCorba
160 DEBTRACE("refcount CORBA seqTC: " << ((omni::TypeCode_base*)((InputCorbaPort*)_port)->getAny()->pd_tc.in())->pd_ref_count);
164 //!Class PyCorbaObjref is a proxy port that converts a PyObject object (of type objref) to a CORBA::Any object (of type objref)
166 * \param p : the input CORBA port to adapt to Python output port
168 PyCorbaObjref::PyCorbaObjref(InputCorbaPort* p)
169 : ProxyPort(p), DataPort(p->getName(), p->getNode(), p->edGetType()), Port(p->getNode())
171 _pyorb = getSALOMERuntime()->getPyOrb();
172 _orb = getSALOMERuntime()->getOrb();
173 // _dynFactory = getSALOMERuntime()->getDynFactory();
176 //!Convert a PyObject (Objref) to CORBA::Any (Objref)
178 * \param data : python object
181 void PyCorbaObjref::put(const void *data) throw(ConversionException)
183 put((PyObject *)data);
186 void PyCorbaObjref::put(PyObject *data) throw(ConversionException)
188 DEBTRACE("data refcnt: " << data->ob_refcnt);
190 PyObject_Print(data,stderr,Py_PRINT_RAW);
191 std::cerr << std::endl;
193 CORBA::Any *a= convertPyObjectCorba(_port->edGetType(),data);
194 YACS::ENGINE::InterpreterSaveThread _loc;
199 //!Class PyCorbaStruct is a proxy port that converts a PyObject object (of type struct) to a CORBA::Any object (of type struct)
201 * \param p : the input CORBA port to adapt to Python output port
203 PyCorbaStruct::PyCorbaStruct(InputCorbaPort* p)
204 : ProxyPort(p), DataPort(p->getName(), p->getNode(), p->edGetType()), Port(p->getNode())
208 void PyCorbaStruct::put(const void *data) throw(ConversionException)
210 put((PyObject *)data);
213 //!Convert a PyObject (struct) to CORBA::Any (struct)
215 * \param data : python object
217 void PyCorbaStruct::put(PyObject *data) throw(ConversionException)
219 DEBTRACE("data refcnt: " << data->ob_refcnt);
221 PyObject_Print(data,stderr,Py_PRINT_RAW);
222 std::cerr << std::endl;
224 CORBA::Any *a= convertPyObjectCorba(_port->edGetType(),data);
225 YACS::ENGINE::InterpreterSaveThread _loc;
228 DEBTRACE("refcount CORBA structTC: " << ((omni::TypeCode_base*)a->pd_tc.in())->pd_ref_count);
230 //delete Any that has been allocated by convertPyObjectCorba
233 DEBTRACE("refcount CORBA structTC: " << ((omni::TypeCode_base*)((InputCorbaPort*)_port)->getAny()->pd_tc.in())->pd_ref_count);