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 | %{ |
811644b8 PP |
32 | #define BT_LOG_TAG "PY-NATIVE" |
33 | #include "logging.h" | |
34 | ||
3fadfbc0 MJ |
35 | #include <babeltrace2/babeltrace.h> |
36 | #include <babeltrace2/property.h> | |
37 | #include <babeltrace2/assert-internal.h> | |
811644b8 | 38 | |
6945df9a | 39 | typedef const uint8_t *bt_uuid; |
81447b5b PP |
40 | %} |
41 | ||
811644b8 | 42 | typedef int bt_bool; |
81447b5b PP |
43 | |
44 | /* For uint*_t/int*_t */ | |
45 | %include "stdint.i" | |
46 | ||
6945df9a SM |
47 | /* |
48 | * Remove `bt_` and `BT_` prefixes from function names, global variables and | |
49 | * enumeration items | |
50 | */ | |
81447b5b | 51 | %rename("%(strip:[bt_])s", %$isfunction) ""; |
6945df9a | 52 | %rename("%(strip:[bt_])s", %$isvariable) ""; |
81447b5b PP |
53 | %rename("%(strip:[BT_])s", %$isenumitem) ""; |
54 | ||
fdfb7f17 SM |
55 | /* |
56 | * Output argument typemap for string output (always appends) | |
57 | * | |
58 | * We initialize the output parameter `temp_value` to an invalid but non-zero | |
59 | * pointer value. This is to make sure we don't rely on its initial value in | |
60 | * the epilogue (where we call SWIG_Python_str_FromChar). When they fail, | |
61 | * functions on which we apply this typemap don't guarantee that the value of | |
62 | * `temp_value` will be unchanged or valid. | |
63 | */ | |
64 | %typemap(in, numinputs=0) (const char **OUT) (char *temp_value = (void *) 1) { | |
81447b5b PP |
65 | $1 = &temp_value; |
66 | } | |
67 | ||
6945df9a | 68 | %typemap(argout) (const char **OUT) { |
81447b5b PP |
69 | if (*$1) { |
70 | /* SWIG_Python_AppendOutput() steals the created object */ | |
71 | $result = SWIG_Python_AppendOutput($result, SWIG_Python_str_FromChar(*$1)); | |
72 | } else { | |
73 | /* SWIG_Python_AppendOutput() steals Py_None */ | |
74 | Py_INCREF(Py_None); | |
75 | $result = SWIG_Python_AppendOutput($result, Py_None); | |
76 | } | |
77 | } | |
78 | ||
6945df9a SM |
79 | /* Output argument typemap for value output (always appends) */ |
80 | %typemap(in, numinputs=0) (bt_value **OUT) (struct bt_value *temp_value = NULL) { | |
81 | $1 = &temp_value; | |
811644b8 PP |
82 | } |
83 | ||
6945df9a | 84 | %typemap(argout) (bt_value **OUT) { |
811644b8 PP |
85 | if (*$1) { |
86 | /* SWIG_Python_AppendOutput() steals the created object */ | |
6945df9a SM |
87 | $result = SWIG_Python_AppendOutput($result, |
88 | SWIG_NewPointerObj(SWIG_as_voidptr(*$1), | |
89 | SWIGTYPE_p_bt_value, 0)); | |
811644b8 PP |
90 | } else { |
91 | /* SWIG_Python_AppendOutput() steals Py_None */ | |
92 | Py_INCREF(Py_None); | |
93 | $result = SWIG_Python_AppendOutput($result, Py_None); | |
94 | } | |
95 | } | |
96 | ||
6945df9a SM |
97 | /* Output argument typemap for initialized uint64_t output parameter (always appends) */ |
98 | %typemap(in, numinputs=0) (uint64_t *OUT) (uint64_t temp) { | |
99 | $1 = &temp; | |
811644b8 PP |
100 | } |
101 | ||
6945df9a SM |
102 | %typemap(argout) uint64_t *OUT { |
103 | $result = SWIG_Python_AppendOutput(resultobj, | |
104 | SWIG_From_unsigned_SS_long_SS_long((*$1))); | |
811644b8 PP |
105 | } |
106 | ||
6945df9a SM |
107 | /* Output argument typemap for initialized int64_t output parameter (always appends) */ |
108 | %typemap(in, numinputs=0) (int64_t *OUT) (int64_t temp) { | |
109 | $1 = &temp; | |
c7eee084 PP |
110 | } |
111 | ||
6945df9a SM |
112 | %typemap(argout) (int64_t *OUT) { |
113 | $result = SWIG_Python_AppendOutput(resultobj, SWIG_From_long_SS_long((*$1))); | |
c7eee084 PP |
114 | } |
115 | ||
6945df9a SM |
116 | /* Output argument typemap for initialized unsigned int output parameter (always appends) */ |
117 | %typemap(in, numinputs=0) (unsigned int *OUT) (unsigned int temp) { | |
811644b8 PP |
118 | $1 = &temp; |
119 | } | |
120 | ||
6945df9a SM |
121 | %typemap(argout) (unsigned int *OUT) { |
122 | $result = SWIG_Python_AppendOutput(resultobj, | |
123 | SWIG_From_unsigned_SS_long_SS_long((uint64_t) (*$1))); | |
811644b8 | 124 | } |
6945df9a SM |
125 | /* Output argument typemap for initialized double output parameter (always appends) */ |
126 | %typemap(in, numinputs=0) (double *OUT) (double temp) { | |
811644b8 PP |
127 | $1 = &temp; |
128 | } | |
129 | ||
6945df9a SM |
130 | %typemap(argout) (double *OUT) { |
131 | $result = SWIG_Python_AppendOutput(resultobj, SWIG_From_int((*$1))); | |
811644b8 PP |
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); | |
162 | return $result; | |
163 | } | |
164 | ||
81447b5b PP |
165 | /* |
166 | * Input and output argument typemaps for raw Python objects (direct). | |
167 | * | |
168 | * Those typemaps honor the convention of Python C function calls with | |
169 | * respect to reference counting: parameters are passed as borrowed | |
170 | * references, and objects are returned as new references. The wrapped | |
171 | * C function must ensure that the return value is always a new | |
172 | * reference, and never steal parameter references. | |
173 | */ | |
174 | %typemap(in) PyObject * { | |
175 | $1 = $input; | |
176 | } | |
177 | ||
178 | %typemap(out) PyObject * { | |
179 | $result = $1; | |
180 | } | |
181 | ||
6945df9a | 182 | /* From property.h */ |
dc43190b | 183 | |
6945df9a SM |
184 | typedef enum bt_property_availability { |
185 | BT_PROPERTY_AVAILABILITY_AVAILABLE, | |
186 | BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE, | |
187 | } bt_property_availability; | |
dc43190b | 188 | |
81447b5b | 189 | /* Per-module interface files */ |
6945df9a SM |
190 | %include "native_bt_clock_class.i" |
191 | %include "native_bt_clock_snapshot.i" | |
192 | %include "native_bt_component.i" | |
193 | %include "native_bt_component_class.i" | |
194 | %include "native_bt_connection.i" | |
195 | %include "native_bt_event.i" | |
196 | %include "native_bt_event_class.i" | |
197 | %include "native_bt_field.i" | |
198 | %include "native_bt_field_class.i" | |
199 | %include "native_bt_field_path.i" | |
200 | %include "native_bt_graph.i" | |
201 | %include "native_bt_logging.i" | |
202 | %include "native_bt_message.i" | |
203 | %include "native_bt_notifier.i" | |
204 | %include "native_bt_packet.i" | |
205 | %include "native_bt_plugin.i" | |
206 | %include "native_bt_port.i" | |
207 | %include "native_bt_query_exec.i" | |
208 | %include "native_bt_stream.i" | |
209 | %include "native_bt_stream_class.i" | |
210 | %include "native_bt_trace.i" | |
211 | %include "native_bt_trace_class.i" | |
212 | %include "native_bt_value.i" | |
213 | %include "native_bt_version.i" |