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