Salome HOME
66ee4bedbe1b741c7b2a466bf52e958c1d0a1bb5
[modules/yacs.git] / src / runtime / CORBAPythonConv.cxx
1 //  Copyright (C) 2006-2008  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 #include "TypeConversions.hxx"
20 #include "RuntimeSALOME.hxx"
21 #include "CORBAPythonConv.hxx"
22 #include "PythonPorts.hxx"
23
24 #include <iostream>
25
26 //#define _DEVDEBUG_
27 #include "YacsTrace.hxx"
28
29 using namespace YACS::ENGINE;
30 using namespace std;
31
32 CorbaPyDouble::CorbaPyDouble(InputPyPort* p)
33     : ProxyPort(p), DataPort(p->getName(), p->getNode(), p->edGetType()), Port(p->getNode()) 
34 {}
35
36 void CorbaPyDouble::put(const void *data) throw(ConversionException)
37 {
38   put((CORBA::Any *)data);
39 }
40
41 //!Convert a CORBA::Any double to PyObject Double
42 /*!
43  *   \param data : CORBA::Any object
44  */
45 void CorbaPyDouble::put(CORBA::Any *data) throw(ConversionException)
46 {
47   InterpreterUnlocker loc;
48   PyObject* ob=convertCorbaPyObject(edGetType(),data);
49   DEBTRACE("ob refcnt: " << ob->ob_refcnt );
50   _port->put(ob);
51   Py_DECREF(ob);
52 }
53
54
55 CorbaPyInt::CorbaPyInt(InputPyPort* p)
56     : ProxyPort(p), DataPort(p->getName(), p->getNode(), p->edGetType()), Port(p->getNode()) 
57 {}
58
59 void CorbaPyInt::put(const void *data) throw(ConversionException)
60 {
61   put((CORBA::Any *)data);
62 }
63
64 //!Convert a CORBA::Any long to a PyObject Int
65 /*!
66  *   \param data : CORBA::Any object
67  */
68 void CorbaPyInt::put(CORBA::Any *data) throw(ConversionException)
69 {
70   InterpreterUnlocker loc;
71   PyObject* ob=convertCorbaPyObject(edGetType(),data);
72   DEBTRACE("ob refcnt: " << ob->ob_refcnt );
73   _port->put(ob);
74   Py_DECREF(ob);
75 }
76
77 CorbaPyString::CorbaPyString(InputPyPort* p)
78     : ProxyPort(p), DataPort(p->getName(), p->getNode(), p->edGetType()), Port(p->getNode()) 
79 {}
80 void CorbaPyString::put(const void *data) throw(ConversionException)
81 {
82   put((CORBA::Any *)data);
83 }
84
85 //!Convert a CORBA::Any string to a PyObject String
86 /*!
87  *   \param data : CORBA::Any object
88  */
89 void CorbaPyString::put(CORBA::Any *data) throw(ConversionException)
90 {
91   InterpreterUnlocker loc;
92   PyObject* ob=convertCorbaPyObject(edGetType(),data);
93   DEBTRACE("ob refcnt: " << ob->ob_refcnt );
94   _port->put(ob);
95   Py_DECREF(ob);
96 }
97
98 CorbaPyBool::CorbaPyBool(InputPyPort* p)
99     : ProxyPort(p), DataPort(p->getName(), p->getNode(), p->edGetType()), Port(p->getNode()) 
100 {}
101
102 /*!Convert a CORBA::Any boolean to a PyObject boolean
103  * It's only a wrapper around put(CORBA::Any *data)
104  */
105 void CorbaPyBool::put(const void *data) throw(ConversionException)
106 {
107   put((CORBA::Any *)data);
108 }
109
110 //!Convert a CORBA::Any boolean to a PyObject boolean
111 /*!
112  *   \param data : CORBA::Any object
113  */
114 void CorbaPyBool::put(CORBA::Any *data) throw(ConversionException)
115 {
116   InterpreterUnlocker loc;
117   PyObject* ob=convertCorbaPyObject(edGetType(),data);
118   DEBTRACE("ob refcnt: " << ob->ob_refcnt );
119   _port->put(ob);
120   Py_DECREF(ob);
121 }
122
123 CorbaPyObjref::CorbaPyObjref(InputPyPort* p)
124     : ProxyPort(p), DataPort(p->getName(), p->getNode(), p->edGetType()), Port(p->getNode()) 
125 {}
126
127 void CorbaPyObjref::put(const void *data) throw(ConversionException)
128 {
129   put((CORBA::Any *)data);
130 }
131
132 //!Convert a CORBA::Any Objref to PyObject Objref
133 /*!
134  *   \param data : CORBA::Any object
135  */
136 void CorbaPyObjref::put(CORBA::Any *data) throw(ConversionException)
137 {
138   InterpreterUnlocker loc;
139   PyObject* ob=convertCorbaPyObject(edGetType(),data);
140   DEBTRACE("ob refcnt: " << ob->ob_refcnt );
141   _port->put(ob);
142   Py_DECREF(ob);
143 }
144
145 //!Class to convert a CORBA::Any sequence to a PyObject Sequence
146 /*!
147  *   \param p : input Python port to adapt to Corba output port
148  */
149 CorbaPySequence::CorbaPySequence(InputPyPort* p)
150   : ProxyPort(p), DataPort(p->getName(), p->getNode(), p->edGetType()), Port(p->getNode())
151 {
152   _dynfactory = getSALOMERuntime()->getDynFactory();
153 }
154
155 void CorbaPySequence::put(const void *data) throw(ConversionException)
156 {
157   put((CORBA::Any *)data);
158 }
159
160 //!Convert a CORBA::Any sequence to PyObject Sequence
161 /*!
162  *   \param data : CORBA::Any object
163  */
164 void CorbaPySequence::put(CORBA::Any *data) throw(ConversionException)
165 {
166   InterpreterUnlocker loc;
167   PyObject* ob=convertCorbaPyObject(edGetType(),data);
168   DEBTRACE("ob refcnt: " << ob->ob_refcnt );
169   _port->put(ob);
170   Py_DECREF(ob);
171 }
172
173 //!Class to convert a CORBA::Any struct into a PyObject struct
174 /*!
175  *   \param p : input Python port to adapt to Corba output port
176  */
177 CorbaPyStruct::CorbaPyStruct(InputPyPort* p)
178   : ProxyPort(p), DataPort(p->getName(), p->getNode(), p->edGetType()), Port(p->getNode())
179 {
180 }
181
182 void CorbaPyStruct::put(const void *data) throw(ConversionException)
183 {
184   put((CORBA::Any *)data);
185 }
186
187 //!Convert a CORBA::Any sequence to PyObject Sequence
188 /*!
189  *   \param data : CORBA::Any object
190  */
191 void CorbaPyStruct::put(CORBA::Any *data) throw(ConversionException)
192 {
193   InterpreterUnlocker loc;
194   PyObject* ob=convertCorbaPyObject(edGetType(),data);
195   DEBTRACE("ob refcnt: " << ob->ob_refcnt );
196   _port->put(ob);
197   Py_DECREF(ob);
198 }