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