1 // Copyright (C) 2006-2008 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.
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
22 #define private public
23 #define protected public
24 #include <omniORB4/CORBA.h>
25 #include <omniORB4/internal/typecode.h>
28 #include "PythonCORBAConv.hxx"
29 #include "TypeConversions.hxx"
30 #include "RuntimeSALOME.hxx"
35 #include "YacsTrace.hxx"
37 using namespace YACS::ENGINE;
40 /*!Convert a PyObject (integer) to CORBA::Any (integer)
41 * It's only a wrapper around put(PyObject *data)
43 void PyCorbaInt::put(const void *data) throw(ConversionException)
45 put((PyObject *)data);
48 //!Convert a PyObject (integer) to CORBA::Any (integer)
50 * \param data : python object
52 void PyCorbaInt::put(PyObject *data) throw(ConversionException)
54 CORBA::Any *a= convertPyObjectCorba(_port->edGetType(),data);
59 //!Convert a PyObject (boolean) to CORBA::Any (boolean)
61 * It's only a wrapper around PyCorbaBool::put(PyObject *data)
63 * \param data : python object
65 void PyCorbaBool::put(const void *data) throw(ConversionException)
67 put((PyObject *)data);
70 //!Convert a PyObject (boolean) to CORBA::Any (boolean)
72 * Convert it and push it to proxy port
74 * \param data : python object
76 void PyCorbaBool::put(PyObject *data) throw(ConversionException)
78 CORBA::Any *a= convertPyObjectCorba(_port->edGetType(),data);
80 //delete Any that has been allocated by convertPyObjectCorba
84 void PyCorbaString::put(const void *data) throw(ConversionException)
86 put((PyObject *)data);
89 //!Convert a PyObject (string) to CORBA::Any (string)
91 * \param data : python object
94 void PyCorbaString::put(PyObject *data) throw(ConversionException)
96 CORBA::Any *a= convertPyObjectCorba(_port->edGetType(),data);
102 void PyCorbaDouble::put(const void *data) throw(ConversionException)
104 put((PyObject *)data);
107 //!Convert a PyObject (double) to CORBA::Any (double)
109 * \param data : python object
112 void PyCorbaDouble::put(PyObject *data) throw(ConversionException)
114 CORBA::Any *a= convertPyObjectCorba(_port->edGetType(),data);
119 //!Class PyCorbaSequence is a proxy port that converts a PyObject object (of type sequence) to a CORBA::Any object (of type sequence)
121 * \param p : the input CORBA port to adapt to Python output port
123 PyCorbaSequence::PyCorbaSequence(InputCorbaPort* p)
124 : ProxyPort(p), DataPort(p->getName(), p->getNode(), p->edGetType()), Port(p->getNode())
128 //!Convert a PyObject (sequence) to CORBA::Any (sequence)
130 * \param data : python object
133 void PyCorbaSequence::put(const void *data) throw(ConversionException)
135 put((PyObject *)data);
138 void PyCorbaSequence::put(PyObject *data) throw(ConversionException)
140 DEBTRACE("data refcnt: " << data->ob_refcnt);
142 PyObject_Print(data,stderr,Py_PRINT_RAW);
143 std::cerr << std::endl;
145 CORBA::Any *a= convertPyObjectCorba(_port->edGetType(),data);
148 DEBTRACE("refcount CORBA seqTC: " << ((omni::TypeCode_base*)a->pd_tc.in())->pd_ref_count);
150 //delete Any that has been allocated by convertPyObjectCorba
153 DEBTRACE("refcount CORBA seqTC: " << ((omni::TypeCode_base*)((InputCorbaPort*)_port)->getAny()->pd_tc.in())->pd_ref_count);
157 //!Class PyCorbaObjref is a proxy port that converts a PyObject object (of type objref) to a CORBA::Any object (of type objref)
159 * \param p : the input CORBA port to adapt to Python output port
161 PyCorbaObjref::PyCorbaObjref(InputCorbaPort* p)
162 : ProxyPort(p), DataPort(p->getName(), p->getNode(), p->edGetType()), Port(p->getNode())
164 _pyorb = getSALOMERuntime()->getPyOrb();
165 _orb = getSALOMERuntime()->getOrb();
166 // _dynFactory = getSALOMERuntime()->getDynFactory();
169 //!Convert a PyObject (Objref) to CORBA::Any (Objref)
171 * \param data : python object
174 void PyCorbaObjref::put(const void *data) throw(ConversionException)
176 put((PyObject *)data);
179 void PyCorbaObjref::put(PyObject *data) throw(ConversionException)
181 DEBTRACE("data refcnt: " << data->ob_refcnt);
183 PyObject_Print(data,stderr,Py_PRINT_RAW);
184 std::cerr << std::endl;
186 CORBA::Any *a= convertPyObjectCorba(_port->edGetType(),data);
191 //!Class PyCorbaStruct is a proxy port that converts a PyObject object (of type struct) to a CORBA::Any object (of type struct)
193 * \param p : the input CORBA port to adapt to Python output port
195 PyCorbaStruct::PyCorbaStruct(InputCorbaPort* p)
196 : ProxyPort(p), DataPort(p->getName(), p->getNode(), p->edGetType()), Port(p->getNode())
200 void PyCorbaStruct::put(const void *data) throw(ConversionException)
202 put((PyObject *)data);
205 //!Convert a PyObject (struct) to CORBA::Any (struct)
207 * \param data : python object
209 void PyCorbaStruct::put(PyObject *data) throw(ConversionException)
211 DEBTRACE("data refcnt: " << data->ob_refcnt);
213 PyObject_Print(data,stderr,Py_PRINT_RAW);
214 std::cerr << std::endl;
216 CORBA::Any *a= convertPyObjectCorba(_port->edGetType(),data);
219 DEBTRACE("refcount CORBA structTC: " << ((omni::TypeCode_base*)a->pd_tc.in())->pd_ref_count);
221 //delete Any that has been allocated by convertPyObjectCorba
224 DEBTRACE("refcount CORBA structTC: " << ((omni::TypeCode_base*)((InputCorbaPort*)_port)->getAny()->pd_tc.in())->pd_ref_count);