Commit | Line | Data |
---|---|---|
81447b5b PP |
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 | ||
f6a5e476 PP |
25 | #ifndef SWIGPYTHON |
26 | # error Unsupported output language | |
27 | #endif | |
28 | ||
09ef660c MJ |
29 | %module native_bt |
30 | ||
81447b5b | 31 | %{ |
b03487ab | 32 | #define BT_LOG_TAG "BT2-PY" |
f6a5e476 PP |
33 | #include "logging.h" |
34 | ||
9df34b44 PP |
35 | /* |
36 | * Include before `<babeltrace2/func-status.h>` because | |
37 | * `<babeltrace2/babeltrace.h>` removes the `__BT_IN_BABELTRACE_H` | |
38 | * definition. | |
39 | */ | |
71c5da58 | 40 | #include <babeltrace2/babeltrace.h> |
fb25b9e3 PP |
41 | |
42 | /* | |
43 | * This is not part of the API, but because those bindings reside within | |
44 | * the project, we take the liberty to use them. | |
45 | */ | |
9df34b44 | 46 | #define __BT_IN_BABELTRACE_H |
fb25b9e3 | 47 | #include <babeltrace2/func-status.h> |
fb25b9e3 | 48 | |
57952005 | 49 | #include "common/assert.h" |
2d7aa9b6 | 50 | #include "py-common/py-common.h" |
65e28173 PP |
51 | |
52 | /* Used by some interface files */ | |
53 | #include "native_bt_bt2_objects.h" | |
54 | #include "native_bt_log_and_append_error.h" | |
81447b5b PP |
55 | %} |
56 | ||
f6a5e476 | 57 | typedef int bt_bool; |
eba7ea21 | 58 | typedef uint64_t bt_listener_id; |
81447b5b PP |
59 | |
60 | /* For uint*_t/int*_t */ | |
61 | %include "stdint.i" | |
62 | ||
6fa6bfa1 SM |
63 | /* |
64 | * Remove `bt_` and `BT_` prefixes from function names, global variables and | |
65 | * enumeration items | |
66 | */ | |
81447b5b | 67 | %rename("%(strip:[bt_])s", %$isfunction) ""; |
6fa6bfa1 | 68 | %rename("%(strip:[bt_])s", %$isvariable) ""; |
81447b5b PP |
69 | %rename("%(strip:[BT_])s", %$isenumitem) ""; |
70 | ||
ec656f03 SM |
71 | /* |
72 | * Output argument typemap for string output (always appends) | |
73 | * | |
74 | * We initialize the output parameter `temp_value` to an invalid but non-zero | |
75 | * pointer value. This is to make sure we don't rely on its initial value in | |
76 | * the epilogue (where we call SWIG_Python_str_FromChar). When they fail, | |
77 | * functions on which we apply this typemap don't guarantee that the value of | |
78 | * `temp_value` will be unchanged or valid. | |
79 | */ | |
e4b56bb9 | 80 | %typemap(in, numinputs=0) (const char **) (char *temp_value = (void *) 1) { |
81447b5b PP |
81 | $1 = &temp_value; |
82 | } | |
83 | ||
e4b56bb9 | 84 | %typemap(argout) (const char **) { |
81447b5b PP |
85 | if (*$1) { |
86 | /* SWIG_Python_AppendOutput() steals the created object */ | |
87 | $result = SWIG_Python_AppendOutput($result, SWIG_Python_str_FromChar(*$1)); | |
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 | ||
6fa6bfa1 | 95 | /* Output argument typemap for value output (always appends) */ |
e4b56bb9 | 96 | %typemap(in, numinputs=0) (bt_value **) (struct bt_value *temp_value = NULL) { |
6fa6bfa1 | 97 | $1 = &temp_value; |
f6a5e476 PP |
98 | } |
99 | ||
e4b56bb9 | 100 | %typemap(argout) (bt_value **) { |
f6a5e476 PP |
101 | if (*$1) { |
102 | /* SWIG_Python_AppendOutput() steals the created object */ | |
6fa6bfa1 SM |
103 | $result = SWIG_Python_AppendOutput($result, |
104 | SWIG_NewPointerObj(SWIG_as_voidptr(*$1), | |
105 | SWIGTYPE_p_bt_value, 0)); | |
f6a5e476 PP |
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 | ||
6fa6bfa1 | 113 | /* Output argument typemap for initialized uint64_t output parameter (always appends) */ |
e4b56bb9 | 114 | %typemap(in, numinputs=0) (uint64_t *) (uint64_t temp) { |
6fa6bfa1 | 115 | $1 = &temp; |
f6a5e476 PP |
116 | } |
117 | ||
e4b56bb9 | 118 | %typemap(argout) uint64_t * { |
6fa6bfa1 SM |
119 | $result = SWIG_Python_AppendOutput(resultobj, |
120 | SWIG_From_unsigned_SS_long_SS_long((*$1))); | |
f6a5e476 PP |
121 | } |
122 | ||
6fa6bfa1 | 123 | /* Output argument typemap for initialized int64_t output parameter (always appends) */ |
e4b56bb9 | 124 | %typemap(in, numinputs=0) (int64_t *) (int64_t temp) { |
6fa6bfa1 | 125 | $1 = &temp; |
1286dcbb PP |
126 | } |
127 | ||
e4b56bb9 | 128 | %typemap(argout) (int64_t *) { |
6fa6bfa1 | 129 | $result = SWIG_Python_AppendOutput(resultobj, SWIG_From_long_SS_long((*$1))); |
1286dcbb PP |
130 | } |
131 | ||
6fa6bfa1 | 132 | /* Output argument typemap for initialized unsigned int output parameter (always appends) */ |
e4b56bb9 | 133 | %typemap(in, numinputs=0) (unsigned int *) (unsigned int temp) { |
f6a5e476 PP |
134 | $1 = &temp; |
135 | } | |
136 | ||
e4b56bb9 | 137 | %typemap(argout) (unsigned int *) { |
6fa6bfa1 SM |
138 | $result = SWIG_Python_AppendOutput(resultobj, |
139 | SWIG_From_unsigned_SS_long_SS_long((uint64_t) (*$1))); | |
f6a5e476 | 140 | } |
f6a5e476 | 141 | |
81447b5b | 142 | /* Input argument typemap for UUID bytes */ |
6fa6bfa1 | 143 | %typemap(in) bt_uuid { |
81447b5b PP |
144 | $1 = (unsigned char *) PyBytes_AsString($input); |
145 | } | |
146 | ||
147 | /* Output argument typemap for UUID bytes */ | |
6fa6bfa1 | 148 | %typemap(out) bt_uuid { |
81447b5b PP |
149 | if (!$1) { |
150 | Py_INCREF(Py_None); | |
151 | $result = Py_None; | |
152 | } else { | |
153 | $result = PyBytes_FromStringAndSize((const char *) $1, 16); | |
154 | } | |
155 | } | |
156 | ||
6fa6bfa1 SM |
157 | /* Input argument typemap for bt_bool */ |
158 | %typemap(in) bt_bool { | |
159 | $1 = PyObject_IsTrue($input); | |
160 | } | |
161 | ||
162 | /* Output argument typemap for bt_bool */ | |
163 | %typemap(out) bt_bool { | |
164 | if ($1 > 0) { | |
165 | $result = Py_True; | |
166 | } else { | |
167 | $result = Py_False; | |
168 | } | |
169 | Py_INCREF($result); | |
6fa6bfa1 SM |
170 | } |
171 | ||
81447b5b PP |
172 | /* |
173 | * Input and output argument typemaps for raw Python objects (direct). | |
174 | * | |
175 | * Those typemaps honor the convention of Python C function calls with | |
176 | * respect to reference counting: parameters are passed as borrowed | |
177 | * references, and objects are returned as new references. The wrapped | |
178 | * C function must ensure that the return value is always a new | |
179 | * reference, and never steal parameter references. | |
180 | */ | |
181 | %typemap(in) PyObject * { | |
182 | $1 = $input; | |
183 | } | |
184 | ||
185 | %typemap(out) PyObject * { | |
186 | $result = $1; | |
187 | } | |
188 | ||
65e28173 PP |
189 | /* Native part initialization and finalization */ |
190 | void bt_bt2_init_from_bt2(void); | |
191 | void bt_bt2_exit_handler(void); | |
192 | ||
9df34b44 PP |
193 | /* |
194 | * Define `__BT_IN_BABELTRACE_H` to allow specific headers to be | |
195 | * included. This remains defined as long as we don't include the main | |
196 | * header, `<babeltrace2/babeltrace.h>`. | |
197 | */ | |
198 | #define __BT_IN_BABELTRACE_H | |
199 | ||
fb25b9e3 | 200 | /* Property enumeration */ |
e4b56bb9 | 201 | %include <babeltrace2/property.h> |
26c5273a | 202 | |
fb25b9e3 | 203 | /* Common function status codes */ |
fb25b9e3 PP |
204 | %include <babeltrace2/func-status.h> |
205 | ||
81447b5b | 206 | /* Per-module interface files */ |
6fa6bfa1 SM |
207 | %include "native_bt_clock_class.i" |
208 | %include "native_bt_clock_snapshot.i" | |
209 | %include "native_bt_component.i" | |
210 | %include "native_bt_component_class.i" | |
211 | %include "native_bt_connection.i" | |
3b2be708 | 212 | %include "native_bt_error.i" |
6fa6bfa1 SM |
213 | %include "native_bt_event.i" |
214 | %include "native_bt_event_class.i" | |
215 | %include "native_bt_field.i" | |
216 | %include "native_bt_field_class.i" | |
217 | %include "native_bt_field_path.i" | |
218 | %include "native_bt_graph.i" | |
78ab137b PP |
219 | %include "native_bt_integer_range_set.i" |
220 | %include "native_bt_interrupter.i" | |
6fa6bfa1 SM |
221 | %include "native_bt_logging.i" |
222 | %include "native_bt_message.i" | |
11673185 | 223 | %include "native_bt_message_iterator.i" |
6fa6bfa1 SM |
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" |