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