Rename bt_ctf_X -> bt_X, maintain backward compat. for pre-2.0 CTF writer
[babeltrace.git] / bindings / python / bt2 / bt2 / native_bt.i
1 /*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2016 Philippe Proulx <pproulx@efficios.com>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24
25 #ifndef SWIGPYTHON
26 # error Unsupported output language
27 #endif
28
29 %module native_bt
30
31 %{
32 #define BT_LOG_TAG "PY-NATIVE"
33 #include "logging.h"
34
35 #include <babeltrace/babeltrace.h>
36
37 typedef const unsigned char *BTUUID;
38 %}
39
40 typedef int bt_bool;
41
42 /* For uint*_t/int*_t */
43 %include "stdint.i"
44
45 /* Remove `bt_` and `BT_` prefixes from function names and enumeration items */
46 %rename("%(strip:[bt_])s", %$isfunction) "";
47 %rename("%(strip:[BT_])s", %$isenumitem) "";
48
49 /* Output argument typemap for string output (always appends) */
50 %typemap(in, numinputs=0) const char **BTOUTSTR (char *temp_value = NULL) {
51 $1 = &temp_value;
52 }
53
54 %typemap(argout) const char **BTOUTSTR {
55 if (*$1) {
56 /* SWIG_Python_AppendOutput() steals the created object */
57 $result = SWIG_Python_AppendOutput($result, SWIG_Python_str_FromChar(*$1));
58 } else {
59 /* SWIG_Python_AppendOutput() steals Py_None */
60 Py_INCREF(Py_None);
61 $result = SWIG_Python_AppendOutput($result, Py_None);
62 }
63 }
64
65 /* Output argument typemap for field type output (always appends) */
66 %typemap(in, numinputs=0) struct bt_field_type **BTOUTFT (struct bt_field_type *temp_ft = NULL) {
67 $1 = &temp_ft;
68 }
69
70 %typemap(argout) struct bt_field_type **BTOUTFT {
71 if (*$1) {
72 /* SWIG_Python_AppendOutput() steals the created object */
73 $result = SWIG_Python_AppendOutput($result, SWIG_NewPointerObj(SWIG_as_voidptr(*$1), SWIGTYPE_p_bt_field_type, 0));
74 } else {
75 /* SWIG_Python_AppendOutput() steals Py_None */
76 Py_INCREF(Py_None);
77 $result = SWIG_Python_AppendOutput($result, Py_None);
78 }
79 }
80
81 /* Output argument typemap for component output (always appends) */
82 %typemap(in, numinputs=0) struct bt_component **BTOUTCOMP (struct bt_component *temp_comp = NULL) {
83 $1 = &temp_comp;
84 }
85
86 %typemap(argout) struct bt_component **BTOUTCOMP {
87 if (*$1) {
88 /* SWIG_Python_AppendOutput() steals the created object */
89 $result = SWIG_Python_AppendOutput($result, SWIG_NewPointerObj(SWIG_as_voidptr(*$1), SWIGTYPE_p_bt_component, 0));
90 } else {
91 /* SWIG_Python_AppendOutput() steals Py_None */
92 Py_INCREF(Py_None);
93 $result = SWIG_Python_AppendOutput($result, Py_None);
94 }
95 }
96
97 /* Output argument typemap for connection output (always appends) */
98 %typemap(in, numinputs=0) struct bt_connection **BTOUTCONN (struct bt_connection *temp_conn = NULL) {
99 $1 = &temp_conn;
100 }
101
102 %typemap(argout) struct bt_connection **BTOUTCONN {
103 if (*$1) {
104 /* SWIG_Python_AppendOutput() steals the created object */
105 $result = SWIG_Python_AppendOutput($result, SWIG_NewPointerObj(SWIG_as_voidptr(*$1), SWIGTYPE_p_bt_connection, 0));
106 } else {
107 /* SWIG_Python_AppendOutput() steals Py_None */
108 Py_INCREF(Py_None);
109 $result = SWIG_Python_AppendOutput($result, Py_None);
110 }
111 }
112
113 /* Output argument typemap for private port output (always appends) */
114 %typemap(in, numinputs=0) struct bt_private_port **BTOUTPRIVPORT (struct bt_private_port *temp_priv_port = NULL) {
115 $1 = &temp_priv_port;
116 }
117
118 %typemap(argout) struct bt_private_port **BTOUTPRIVPORT {
119 if (*$1) {
120 /* SWIG_Python_AppendOutput() steals the created object */
121 $result = SWIG_Python_AppendOutput($result, SWIG_NewPointerObj(SWIG_as_voidptr(*$1), SWIGTYPE_p_bt_private_port, 0));
122 } else {
123 /* SWIG_Python_AppendOutput() steals Py_None */
124 Py_INCREF(Py_None);
125 $result = SWIG_Python_AppendOutput($result, Py_None);
126 }
127 }
128
129 /* Output argument typemap for value output (always appends) */
130 %typemap(in, numinputs=0) struct bt_value **BTOUTVALUE (struct bt_value *temp_value = NULL) {
131 $1 = &temp_value;
132 }
133
134 %typemap(argout) struct bt_value **BTOUTVALUE {
135 if (*$1) {
136 /* SWIG_Python_AppendOutput() steals the created object */
137 $result = SWIG_Python_AppendOutput($result, SWIG_NewPointerObj(SWIG_as_voidptr(*$1), SWIGTYPE_p_bt_value, 0));
138 } else {
139 /* SWIG_Python_AppendOutput() steals Py_None */
140 Py_INCREF(Py_None);
141 $result = SWIG_Python_AppendOutput($result, Py_None);
142 }
143 }
144
145 /* Output argument typemap for initialized uint64_t output parameter (always appends) */
146 %typemap(in, numinputs=0) uint64_t *OUTPUTINIT (uint64_t temp = -1ULL) {
147 $1 = &temp;
148 }
149
150 %typemap(argout) uint64_t *OUTPUTINIT {
151 $result = SWIG_Python_AppendOutput(resultobj, SWIG_From_unsigned_SS_long_SS_long((*$1)));
152 }
153
154 /* Output argument typemap for initialized unsigned int output parameter (always appends) */
155 %typemap(in, numinputs=0) unsigned int *OUTPUTINIT (unsigned int temp = -1) {
156 $1 = &temp;
157 }
158
159 %typemap(argout) unsigned int *OUTPUTINIT {
160 $result = SWIG_Python_AppendOutput(resultobj, SWIG_From_unsigned_SS_long_SS_long((uint64_t) (*$1)));
161 }
162
163 /* Input argument typemap for UUID bytes */
164 %typemap(in) BTUUID {
165 $1 = (unsigned char *) PyBytes_AsString($input);
166 }
167
168 /* Output argument typemap for UUID bytes */
169 %typemap(out) BTUUID {
170 if (!$1) {
171 Py_INCREF(Py_None);
172 $result = Py_None;
173 } else {
174 $result = PyBytes_FromStringAndSize((const char *) $1, 16);
175 }
176 }
177
178 /*
179 * Input and output argument typemaps for raw Python objects (direct).
180 *
181 * Those typemaps honor the convention of Python C function calls with
182 * respect to reference counting: parameters are passed as borrowed
183 * references, and objects are returned as new references. The wrapped
184 * C function must ensure that the return value is always a new
185 * reference, and never steal parameter references.
186 */
187 %typemap(in) PyObject * {
188 $1 = $input;
189 }
190
191 %typemap(out) PyObject * {
192 $result = $1;
193 }
194
195 %{
196 static enum bt_notification_type *bt_py3_notif_types_from_py_list(
197 PyObject *py_notif_types)
198 {
199 enum bt_notification_type *notification_types = NULL;
200 size_t i;
201
202 assert(!PyErr_Occurred());
203
204 if (py_notif_types == Py_None) {
205 goto end;
206 }
207
208 assert(PyList_Check(py_notif_types));
209 notification_types = g_new0(enum bt_notification_type,
210 PyList_Size(py_notif_types) + 1);
211 assert(notification_types);
212 notification_types[PyList_Size(py_notif_types)] =
213 BT_NOTIFICATION_TYPE_SENTINEL;
214
215 for (i = 0; i < PyList_Size(py_notif_types); i++) {
216 PyObject *item = PyList_GetItem(py_notif_types, i);
217 long value;
218 int overflow;
219
220 assert(item);
221 assert(PyLong_Check(item));
222 value = PyLong_AsLongAndOverflow(item, &overflow);
223 assert(overflow == 0);
224 notification_types[i] = value;
225 }
226
227 end:
228 return notification_types;
229 }
230 %}
231
232 /* Per-module interface files */
233 %include "native_btccpriomap.i"
234 %include "native_btclockclass.i"
235 %include "native_btcomponent.i"
236 %include "native_btcomponentclass.i"
237 %include "native_btconnection.i"
238 %include "native_btctfwriter.i"
239 %include "native_btevent.i"
240 %include "native_bteventclass.i"
241 %include "native_btfields.i"
242 %include "native_btft.i"
243 %include "native_btgraph.i"
244 %include "native_btlogging.i"
245 %include "native_btnotification.i"
246 %include "native_btnotifiter.i"
247 %include "native_btpacket.i"
248 %include "native_btplugin.i"
249 %include "native_btport.i"
250 %include "native_btqueryexec.i"
251 %include "native_btref.i"
252 %include "native_btstream.i"
253 %include "native_btstreamclass.i"
254 %include "native_bttrace.i"
255 %include "native_btvalues.i"
256 %include "native_btversion.i"
This page took 0.035402 seconds and 4 git commands to generate.