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