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