Commit | Line | Data |
---|---|---|
81447b5b | 1 | /* |
0235b0db | 2 | * SPDX-License-Identifier: MIT |
81447b5b PP |
3 | * |
4 | * Copyright (c) 2016 Philippe Proulx <pproulx@efficios.com> | |
81447b5b PP |
5 | */ |
6 | ||
811644b8 PP |
7 | #ifndef SWIGPYTHON |
8 | # error Unsupported output language | |
9 | #endif | |
10 | ||
1b8fb862 MJ |
11 | %module native_bt |
12 | ||
81447b5b | 13 | %{ |
350ad6c1 | 14 | #define BT_LOG_TAG "BT2-PY" |
811644b8 PP |
15 | #include "logging.h" |
16 | ||
4fa90f32 PP |
17 | /* |
18 | * Include before `<babeltrace2/func-status.h>` because | |
19 | * `<babeltrace2/babeltrace.h>` removes the `__BT_IN_BABELTRACE_H` | |
20 | * definition. | |
21 | */ | |
3fadfbc0 | 22 | #include <babeltrace2/babeltrace.h> |
d24d5663 PP |
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 | */ | |
4fa90f32 | 28 | #define __BT_IN_BABELTRACE_H |
d24d5663 | 29 | #include <babeltrace2/func-status.h> |
d24d5663 | 30 | |
578e048b | 31 | #include "common/assert.h" |
7085eeaa | 32 | #include "py-common/py-common.h" |
612a9870 PP |
33 | |
34 | /* Used by some interface files */ | |
35 | #include "native_bt_bt2_objects.h" | |
36 | #include "native_bt_log_and_append_error.h" | |
81447b5b PP |
37 | %} |
38 | ||
811644b8 | 39 | typedef int bt_bool; |
2054a0d1 | 40 | typedef uint64_t bt_listener_id; |
81447b5b PP |
41 | |
42 | /* For uint*_t/int*_t */ | |
43 | %include "stdint.i" | |
44 | ||
6945df9a SM |
45 | /* |
46 | * Remove `bt_` and `BT_` prefixes from function names, global variables and | |
47 | * enumeration items | |
48 | */ | |
81447b5b | 49 | %rename("%(strip:[bt_])s", %$isfunction) ""; |
6945df9a | 50 | %rename("%(strip:[bt_])s", %$isvariable) ""; |
81447b5b PP |
51 | %rename("%(strip:[BT_])s", %$isenumitem) ""; |
52 | ||
fdfb7f17 SM |
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 | */ | |
d6bb425c | 62 | %typemap(in, numinputs=0) (const char **) (char *temp_value = (void *) 1) { |
81447b5b PP |
63 | $1 = &temp_value; |
64 | } | |
65 | ||
d6bb425c | 66 | %typemap(argout) (const char **) { |
81447b5b PP |
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 | ||
6945df9a | 77 | /* Output argument typemap for value output (always appends) */ |
d6bb425c | 78 | %typemap(in, numinputs=0) (bt_value **) (struct bt_value *temp_value = NULL) { |
6945df9a | 79 | $1 = &temp_value; |
811644b8 PP |
80 | } |
81 | ||
d6bb425c | 82 | %typemap(argout) (bt_value **) { |
811644b8 PP |
83 | if (*$1) { |
84 | /* SWIG_Python_AppendOutput() steals the created object */ | |
6945df9a SM |
85 | $result = SWIG_Python_AppendOutput($result, |
86 | SWIG_NewPointerObj(SWIG_as_voidptr(*$1), | |
87 | SWIGTYPE_p_bt_value, 0)); | |
811644b8 PP |
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 | ||
6945df9a | 95 | /* Output argument typemap for initialized uint64_t output parameter (always appends) */ |
d6bb425c | 96 | %typemap(in, numinputs=0) (uint64_t *) (uint64_t temp) { |
6945df9a | 97 | $1 = &temp; |
811644b8 PP |
98 | } |
99 | ||
d6bb425c | 100 | %typemap(argout) uint64_t * { |
6945df9a SM |
101 | $result = SWIG_Python_AppendOutput(resultobj, |
102 | SWIG_From_unsigned_SS_long_SS_long((*$1))); | |
811644b8 PP |
103 | } |
104 | ||
6945df9a | 105 | /* Output argument typemap for initialized int64_t output parameter (always appends) */ |
d6bb425c | 106 | %typemap(in, numinputs=0) (int64_t *) (int64_t temp) { |
6945df9a | 107 | $1 = &temp; |
c7eee084 PP |
108 | } |
109 | ||
d6bb425c | 110 | %typemap(argout) (int64_t *) { |
6945df9a | 111 | $result = SWIG_Python_AppendOutput(resultobj, SWIG_From_long_SS_long((*$1))); |
c7eee084 PP |
112 | } |
113 | ||
6945df9a | 114 | /* Output argument typemap for initialized unsigned int output parameter (always appends) */ |
d6bb425c | 115 | %typemap(in, numinputs=0) (unsigned int *) (unsigned int temp) { |
811644b8 PP |
116 | $1 = &temp; |
117 | } | |
118 | ||
d6bb425c | 119 | %typemap(argout) (unsigned int *) { |
6945df9a SM |
120 | $result = SWIG_Python_AppendOutput(resultobj, |
121 | SWIG_From_unsigned_SS_long_SS_long((uint64_t) (*$1))); | |
811644b8 | 122 | } |
811644b8 | 123 | |
f2fb1b32 SM |
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 | ||
81447b5b | 134 | /* Input argument typemap for UUID bytes */ |
6945df9a | 135 | %typemap(in) bt_uuid { |
81447b5b PP |
136 | $1 = (unsigned char *) PyBytes_AsString($input); |
137 | } | |
138 | ||
139 | /* Output argument typemap for UUID bytes */ | |
6945df9a | 140 | %typemap(out) bt_uuid { |
81447b5b PP |
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 | ||
6945df9a SM |
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); | |
6945df9a SM |
162 | } |
163 | ||
81447b5b PP |
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 | ||
612a9870 PP |
181 | /* Native part initialization and finalization */ |
182 | void bt_bt2_init_from_bt2(void); | |
183 | void bt_bt2_exit_handler(void); | |
184 | ||
900eef73 SM |
185 | /* |
186 | * These functions cause some -Wformat-nonliteral warnings, but we don't need | |
187 | * them. Ignore them, so that we can keep the warning turned on. | |
188 | */ | |
189 | %ignore bt_current_thread_error_append_cause_from_component; | |
190 | %ignore bt_current_thread_error_append_cause_from_component_class; | |
191 | %ignore bt_current_thread_error_append_cause_from_message_iterator; | |
192 | %ignore bt_current_thread_error_append_cause_from_unknown; | |
193 | ||
4fa90f32 PP |
194 | /* |
195 | * Define `__BT_IN_BABELTRACE_H` to allow specific headers to be | |
196 | * included. This remains defined as long as we don't include the main | |
197 | * header, `<babeltrace2/babeltrace.h>`. | |
198 | */ | |
199 | #define __BT_IN_BABELTRACE_H | |
200 | ||
8b305066 | 201 | /* |
4c81a2b7 PP |
202 | * Define `__BT_ATTR_FORMAT_PRINTF` and `__BT_NOEXCEPT` to nothing, |
203 | * otherwise SWIG fails to parse the included header files that use it. | |
8b305066 SM |
204 | */ |
205 | #define __BT_ATTR_FORMAT_PRINTF(_string_index, _first_to_check) | |
4c81a2b7 | 206 | #define __BT_NOEXCEPT |
8b305066 | 207 | |
43c59509 PP |
208 | /* Common types */ |
209 | %include <babeltrace2/types.h> | |
dc43190b | 210 | |
d24d5663 | 211 | /* Common function status codes */ |
d24d5663 PP |
212 | %include <babeltrace2/func-status.h> |
213 | ||
81447b5b | 214 | /* Per-module interface files */ |
f3c9a159 | 215 | %include "native_bt_autodisc.i" |
6945df9a SM |
216 | %include "native_bt_clock_class.i" |
217 | %include "native_bt_clock_snapshot.i" | |
218 | %include "native_bt_component.i" | |
219 | %include "native_bt_component_class.i" | |
220 | %include "native_bt_connection.i" | |
ce4923b0 | 221 | %include "native_bt_error.i" |
6945df9a SM |
222 | %include "native_bt_event.i" |
223 | %include "native_bt_event_class.i" | |
224 | %include "native_bt_field.i" | |
225 | %include "native_bt_field_class.i" | |
226 | %include "native_bt_field_path.i" | |
227 | %include "native_bt_graph.i" | |
1e920353 PP |
228 | %include "native_bt_integer_range_set.i" |
229 | %include "native_bt_interrupter.i" | |
6945df9a SM |
230 | %include "native_bt_logging.i" |
231 | %include "native_bt_message.i" | |
a0207a9c | 232 | %include "native_bt_message_iterator.i" |
f1f74173 | 233 | %include "native_bt_mip.i" |
6945df9a SM |
234 | %include "native_bt_packet.i" |
235 | %include "native_bt_plugin.i" | |
236 | %include "native_bt_port.i" | |
237 | %include "native_bt_query_exec.i" | |
238 | %include "native_bt_stream.i" | |
239 | %include "native_bt_stream_class.i" | |
240 | %include "native_bt_trace.i" | |
241 | %include "native_bt_trace_class.i" | |
242 | %include "native_bt_value.i" | |
243 | %include "native_bt_version.i" | |
7c7301d5 SM |
244 | |
245 | %{ | |
246 | ||
247 | /* | |
248 | * This function is defined by SWIG. Declare here to avoid a | |
249 | * -Wmissing-prototypes warning. | |
250 | */ | |
251 | PyObject *SWIG_init(void); | |
252 | ||
253 | %} |