Move to kernel style SPDX license identifiers
[babeltrace.git] / src / bindings / python / bt2 / bt2 / native_bt.i
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright (c) 2016 Philippe Proulx <pproulx@efficios.com>
5 */
6
7 #ifndef SWIGPYTHON
8 # error Unsupported output language
9 #endif
10
11 %module native_bt
12
13 %{
14 #define BT_LOG_TAG "BT2-PY"
15 #include "logging.h"
16
17 /*
18 * Include before `<babeltrace2/func-status.h>` because
19 * `<babeltrace2/babeltrace.h>` removes the `__BT_IN_BABELTRACE_H`
20 * definition.
21 */
22 #include <babeltrace2/babeltrace.h>
23
24 /*
25 * This is not part of the API, but because those bindings reside within
26 * the project, we take the liberty to use them.
27 */
28 #define __BT_IN_BABELTRACE_H
29 #include <babeltrace2/func-status.h>
30
31 #include "common/assert.h"
32 #include "py-common/py-common.h"
33
34 /* Used by some interface files */
35 #include "native_bt_bt2_objects.h"
36 #include "native_bt_log_and_append_error.h"
37 %}
38
39 typedef int bt_bool;
40 typedef uint64_t bt_listener_id;
41
42 /* For uint*_t/int*_t */
43 %include "stdint.i"
44
45 /*
46 * Remove `bt_` and `BT_` prefixes from function names, global variables and
47 * enumeration items
48 */
49 %rename("%(strip:[bt_])s", %$isfunction) "";
50 %rename("%(strip:[bt_])s", %$isvariable) "";
51 %rename("%(strip:[BT_])s", %$isenumitem) "";
52
53 /*
54 * Output argument typemap for string output (always appends)
55 *
56 * We initialize the output parameter `temp_value` to an invalid but non-zero
57 * pointer value. This is to make sure we don't rely on its initial value in
58 * the epilogue (where we call SWIG_Python_str_FromChar). When they fail,
59 * functions on which we apply this typemap don't guarantee that the value of
60 * `temp_value` will be unchanged or valid.
61 */
62 %typemap(in, numinputs=0) (const char **) (char *temp_value = (void *) 1) {
63 $1 = &temp_value;
64 }
65
66 %typemap(argout) (const char **) {
67 if (*$1) {
68 /* SWIG_Python_AppendOutput() steals the created object */
69 $result = SWIG_Python_AppendOutput($result, SWIG_Python_str_FromChar(*$1));
70 } else {
71 /* SWIG_Python_AppendOutput() steals Py_None */
72 Py_INCREF(Py_None);
73 $result = SWIG_Python_AppendOutput($result, Py_None);
74 }
75 }
76
77 /* Output argument typemap for value output (always appends) */
78 %typemap(in, numinputs=0) (bt_value **) (struct bt_value *temp_value = NULL) {
79 $1 = &temp_value;
80 }
81
82 %typemap(argout) (bt_value **) {
83 if (*$1) {
84 /* SWIG_Python_AppendOutput() steals the created object */
85 $result = SWIG_Python_AppendOutput($result,
86 SWIG_NewPointerObj(SWIG_as_voidptr(*$1),
87 SWIGTYPE_p_bt_value, 0));
88 } else {
89 /* SWIG_Python_AppendOutput() steals Py_None */
90 Py_INCREF(Py_None);
91 $result = SWIG_Python_AppendOutput($result, Py_None);
92 }
93 }
94
95 /* Output argument typemap for initialized uint64_t output parameter (always appends) */
96 %typemap(in, numinputs=0) (uint64_t *) (uint64_t temp) {
97 $1 = &temp;
98 }
99
100 %typemap(argout) uint64_t * {
101 $result = SWIG_Python_AppendOutput(resultobj,
102 SWIG_From_unsigned_SS_long_SS_long((*$1)));
103 }
104
105 /* Output argument typemap for initialized int64_t output parameter (always appends) */
106 %typemap(in, numinputs=0) (int64_t *) (int64_t temp) {
107 $1 = &temp;
108 }
109
110 %typemap(argout) (int64_t *) {
111 $result = SWIG_Python_AppendOutput(resultobj, SWIG_From_long_SS_long((*$1)));
112 }
113
114 /* Output argument typemap for initialized unsigned int output parameter (always appends) */
115 %typemap(in, numinputs=0) (unsigned int *) (unsigned int temp) {
116 $1 = &temp;
117 }
118
119 %typemap(argout) (unsigned int *) {
120 $result = SWIG_Python_AppendOutput(resultobj,
121 SWIG_From_unsigned_SS_long_SS_long((uint64_t) (*$1)));
122 }
123
124 /* Output argument typemap for initialized bt_boot output parameter (always appends) */
125 %typemap(in, numinputs=0) (bt_bool *) (bt_bool temp) {
126 $1 = &temp;
127 }
128
129 %typemap(argout) bt_bool * {
130 $result = SWIG_Python_AppendOutput(resultobj,
131 SWIG_From_bool(*$1));
132 }
133
134 /* Input argument typemap for UUID bytes */
135 %typemap(in) bt_uuid {
136 $1 = (unsigned char *) PyBytes_AsString($input);
137 }
138
139 /* Output argument typemap for UUID bytes */
140 %typemap(out) bt_uuid {
141 if (!$1) {
142 Py_INCREF(Py_None);
143 $result = Py_None;
144 } else {
145 $result = PyBytes_FromStringAndSize((const char *) $1, 16);
146 }
147 }
148
149 /* Input argument typemap for bt_bool */
150 %typemap(in) bt_bool {
151 $1 = PyObject_IsTrue($input);
152 }
153
154 /* Output argument typemap for bt_bool */
155 %typemap(out) bt_bool {
156 if ($1 > 0) {
157 $result = Py_True;
158 } else {
159 $result = Py_False;
160 }
161 Py_INCREF($result);
162 }
163
164 /*
165 * Input and output argument typemaps for raw Python objects (direct).
166 *
167 * Those typemaps honor the convention of Python C function calls with
168 * respect to reference counting: parameters are passed as borrowed
169 * references, and objects are returned as new references. The wrapped
170 * C function must ensure that the return value is always a new
171 * reference, and never steal parameter references.
172 */
173 %typemap(in) PyObject * {
174 $1 = $input;
175 }
176
177 %typemap(out) PyObject * {
178 $result = $1;
179 }
180
181 /* Native part initialization and finalization */
182 void bt_bt2_init_from_bt2(void);
183 void bt_bt2_exit_handler(void);
184
185 /*
186 * Define `__BT_IN_BABELTRACE_H` to allow specific headers to be
187 * included. This remains defined as long as we don't include the main
188 * header, `<babeltrace2/babeltrace.h>`.
189 */
190 #define __BT_IN_BABELTRACE_H
191
192 /*
193 * Define `__BT_ATTR_FORMAT_PRINTF` to nothing, otherwise SWIG fails to parse
194 * the included header files that use it.
195 */
196 #define __BT_ATTR_FORMAT_PRINTF(_string_index, _first_to_check)
197
198 /* Common types */
199 %include <babeltrace2/types.h>
200
201 /* Common function status codes */
202 %include <babeltrace2/func-status.h>
203
204 /* Per-module interface files */
205 %include "native_bt_autodisc.i"
206 %include "native_bt_clock_class.i"
207 %include "native_bt_clock_snapshot.i"
208 %include "native_bt_component.i"
209 %include "native_bt_component_class.i"
210 %include "native_bt_connection.i"
211 %include "native_bt_error.i"
212 %include "native_bt_event.i"
213 %include "native_bt_event_class.i"
214 %include "native_bt_field.i"
215 %include "native_bt_field_class.i"
216 %include "native_bt_field_path.i"
217 %include "native_bt_graph.i"
218 %include "native_bt_integer_range_set.i"
219 %include "native_bt_interrupter.i"
220 %include "native_bt_logging.i"
221 %include "native_bt_message.i"
222 %include "native_bt_message_iterator.i"
223 %include "native_bt_mip.i"
224 %include "native_bt_packet.i"
225 %include "native_bt_plugin.i"
226 %include "native_bt_port.i"
227 %include "native_bt_query_exec.i"
228 %include "native_bt_stream.i"
229 %include "native_bt_stream_class.i"
230 %include "native_bt_trace.i"
231 %include "native_bt_trace_class.i"
232 %include "native_bt_value.i"
233 %include "native_bt_version.i"
234
235 %{
236
237 /*
238 * This function is defined by SWIG. Declare here to avoid a
239 * -Wmissing-prototypes warning.
240 */
241 PyObject *SWIG_init(void);
242
243 %}
This page took 0.038917 seconds and 4 git commands to generate.