Version: 8.3.0
PythonCORBAConv.cxx
Go to the documentation of this file.
1 // Copyright (C) 2006-2016 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 //#define REFCNT
21 //
22 #ifdef REFCNT
23 #define private public
24 #define protected public
25 #include <omniORB4/CORBA.h>
26 #include <omniORB4/internal/typecode.h>
27 #endif
28 
29 #include "PythonCORBAConv.hxx"
30 #include "TypeConversions.hxx"
31 #include "RuntimeSALOME.hxx"
32 #include "PythonPorts.hxx"
33 
34 #include <iostream>
35 
36 //#define _DEVDEBUG_
37 #include "YacsTrace.hxx"
38 
39 using namespace YACS::ENGINE;
40 using namespace std;
41 
45 void PyCorbaInt::put(const void *data) throw(ConversionException)
46 {
47  put((PyObject *)data);
48 }
49 
51 
54 void PyCorbaInt::put(PyObject *data) throw(ConversionException)
55 {
56  CORBA::Any *a= convertPyObjectCorba(_port->edGetType(),data);
58  _port->put(a);
59  delete a;
60 }
61 
63 
68 void PyCorbaBool::put(const void *data) throw(ConversionException)
69 {
70  put((PyObject *)data);
71 }
72 
74 
79 void PyCorbaBool::put(PyObject *data) throw(ConversionException)
80 {
81  CORBA::Any *a= convertPyObjectCorba(_port->edGetType(),data);
83  _port->put(a);
84  //delete Any that has been allocated by convertPyObjectCorba
85  delete a;
86 }
87 
88 void PyCorbaString::put(const void *data) throw(ConversionException)
89 {
90  put((PyObject *)data);
91 }
92 
94 
98 void PyCorbaString::put(PyObject *data) throw(ConversionException)
99 {
100  CORBA::Any *a= convertPyObjectCorba(_port->edGetType(),data);
102  _port->put(a);
103  delete a;
104 }
105 
106 
107 void PyCorbaDouble::put(const void *data) throw(ConversionException)
108 {
109  put((PyObject *)data);
110 }
111 
113 
117 void PyCorbaDouble::put(PyObject *data) throw(ConversionException)
118 {
119  CORBA::Any *a= convertPyObjectCorba(_port->edGetType(),data);
121  _port->put(a);
122  delete a;
123 }
124 
126 
130  : ProxyPort(p), DataPort(p->getName(), p->getNode(), p->edGetType()), Port(p->getNode())
131 {
132 }
133 
135 
139 void PyCorbaSequence::put(const void *data) throw(ConversionException)
140 {
141  put((PyObject *)data);
142 }
143 
144 void PyCorbaSequence::put(PyObject *data) throw(ConversionException)
145 {
146  DEBTRACE("data refcnt: " << data->ob_refcnt);
147 #ifdef _DEVDEBUG_
148  PyObject_Print(data,stderr,Py_PRINT_RAW);
149  std::cerr << std::endl;
150 #endif
151  CORBA::Any *a= convertPyObjectCorba(_port->edGetType(),data);
153  _port->put(a);
154 #ifdef REFCNT
155  DEBTRACE("refcount CORBA seqTC: " << ((omni::TypeCode_base*)a->pd_tc.in())->pd_ref_count);
156 #endif
157  //delete Any that has been allocated by convertPyObjectCorba
158  delete a;
159 #ifdef REFCNT
160  DEBTRACE("refcount CORBA seqTC: " << ((omni::TypeCode_base*)((InputCorbaPort*)_port)->getAny()->pd_tc.in())->pd_ref_count);
161 #endif
162 }
163 
165 
169  : ProxyPort(p), DataPort(p->getName(), p->getNode(), p->edGetType()), Port(p->getNode())
170 {
173  // _dynFactory = getSALOMERuntime()->getDynFactory();
174 }
175 
177 
181 void PyCorbaObjref::put(const void *data) throw(ConversionException)
182 {
183  put((PyObject *)data);
184 }
185 
186 void PyCorbaObjref::put(PyObject *data) throw(ConversionException)
187 {
188  DEBTRACE("data refcnt: " << data->ob_refcnt);
189 #ifdef _DEVDEBUG_
190  PyObject_Print(data,stderr,Py_PRINT_RAW);
191  std::cerr << std::endl;
192 #endif
193  CORBA::Any *a= convertPyObjectCorba(_port->edGetType(),data);
195  _port->put(a);
196  delete a;
197 }
198 
200 
204  : ProxyPort(p), DataPort(p->getName(), p->getNode(), p->edGetType()), Port(p->getNode())
205 {
206 }
207 
208 void PyCorbaStruct::put(const void *data) throw(ConversionException)
209 {
210  put((PyObject *)data);
211 }
212 
214 
217 void PyCorbaStruct::put(PyObject *data) throw(ConversionException)
218 {
219  DEBTRACE("data refcnt: " << data->ob_refcnt);
220 #ifdef _DEVDEBUG_
221  PyObject_Print(data,stderr,Py_PRINT_RAW);
222  std::cerr << std::endl;
223 #endif
224  CORBA::Any *a= convertPyObjectCorba(_port->edGetType(),data);
226  _port->put(a);
227 #ifdef REFCNT
228  DEBTRACE("refcount CORBA structTC: " << ((omni::TypeCode_base*)a->pd_tc.in())->pd_ref_count);
229 #endif
230  //delete Any that has been allocated by convertPyObjectCorba
231  delete a;
232 #ifdef REFCNT
233  DEBTRACE("refcount CORBA structTC: " << ((omni::TypeCode_base*)((InputCorbaPort*)_port)->getAny()->pd_tc.in())->pd_ref_count);
234 #endif
235 }
236