bt2: include "py-common/py-common.h" where used
[babeltrace.git] / src / bindings / python / bt2 / bt2 / native_bt.i
... / ...
CommitLineData
1/*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright (c) 2016 Philippe Proulx <pproulx@efficios.com>
5 */
6
7#ifndef SWIGPYTHON
8# error Unsupported output language
9#endif
10
11%module native_bt
12
13%{
14#define BT_LOG_TAG "BT2-PY"
15#include "logging.hpp"
16
17/*
18 * Include before `<babeltrace2/func-status.h>` because
19 * `<babeltrace2/babeltrace.h>` removes the `__BT_IN_BABELTRACE_H`
20 * definition.
21 */
22#include <babeltrace2/babeltrace.h>
23
24/*
25 * This is not part of the API, but because those bindings reside within
26 * the project, we take the liberty to use them.
27 */
28#define __BT_IN_BABELTRACE_H
29#include <babeltrace2/func-status.h>
30
31#include "common/assert.h"
32
33/* Used by some interface files */
34#include "native_bt_bt2_objects.hpp"
35#include "native_bt_log_and_append_error.hpp"
36%}
37
38typedef int bt_bool;
39typedef uint64_t bt_listener_id;
40
41/* For uint*_t/int*_t */
42%include "stdint.i"
43
44/*
45 * Remove `bt_` and `BT_` prefixes from function names, global variables and
46 * enumeration items
47 */
48%rename("%(strip:[bt_])s", %$isfunction) "";
49%rename("%(strip:[bt_])s", %$isvariable) "";
50%rename("%(strip:[BT_])s", %$isenumitem) "";
51
52/*
53 * Output argument typemap for string output (always appends)
54 *
55 * We initialize the output parameter `temp_value` to an invalid but non-zero
56 * pointer value. This is to make sure we don't rely on its initial value in
57 * the epilogue (where we call SWIG_Python_str_FromChar). When they fail,
58 * functions on which we apply this typemap don't guarantee that the value of
59 * `temp_value` will be unchanged or valid.
60 */
61%typemap(in, numinputs=0) (const char **) (char *temp_value = reinterpret_cast<char *>(1)) {
62 $1 = &temp_value;
63}
64
65%typemap(argout) (const char **) {
66 if (*$1) {
67 /* SWIG_AppendOutput() steals the created object */
68 $result = SWIG_AppendOutput($result, SWIG_Python_str_FromChar(*$1));
69 } else {
70 /* SWIG_AppendOutput() steals Py_None */
71 Py_INCREF(Py_None);
72 $result = SWIG_AppendOutput($result, Py_None);
73 }
74}
75
76/* Output argument typemap for value output (always appends) */
77%typemap(in, numinputs=0) (bt_value **) (struct bt_value *temp_value = NULL) {
78 $1 = &temp_value;
79}
80
81%typemap(argout) (bt_value **) {
82 if (*$1) {
83 /* SWIG_AppendOutput() steals the created object */
84 $result = SWIG_AppendOutput($result,
85 SWIG_NewPointerObj(SWIG_as_voidptr(*$1),
86 SWIGTYPE_p_bt_value, 0));
87 } else {
88 /* SWIG_AppendOutput() steals Py_None */
89 Py_INCREF(Py_None);
90 $result = SWIG_AppendOutput($result, Py_None);
91 }
92}
93
94/* Output argument typemap for initialized uint64_t output parameter (always appends) */
95%typemap(in, numinputs=0) (uint64_t *) (uint64_t temp) {
96 $1 = &temp;
97}
98
99%typemap(argout) uint64_t * {
100 $result = SWIG_AppendOutput(resultobj,
101 SWIG_From_unsigned_SS_long_SS_long((*$1)));
102}
103
104/* Output argument typemap for initialized int64_t output parameter (always appends) */
105%typemap(in, numinputs=0) (int64_t *) (int64_t temp) {
106 $1 = &temp;
107}
108
109%typemap(argout) (int64_t *) {
110 $result = SWIG_AppendOutput(resultobj, SWIG_From_long_SS_long((*$1)));
111}
112
113/* Output argument typemap for initialized unsigned int output parameter (always appends) */
114%typemap(in, numinputs=0) (unsigned int *) (unsigned int temp) {
115 $1 = &temp;
116}
117
118%typemap(argout) (unsigned int *) {
119 $result = SWIG_AppendOutput(resultobj,
120 SWIG_From_unsigned_SS_long_SS_long((uint64_t) (*$1)));
121}
122
123/* Output argument typemap for initialized bt_boot output parameter (always appends) */
124%typemap(in, numinputs=0) (bt_bool *) (bt_bool temp) {
125 $1 = &temp;
126}
127
128%typemap(argout) bt_bool * {
129 $result = SWIG_AppendOutput(resultobj,
130 SWIG_From_bool(*$1));
131}
132
133/* Input argument typemap for UUID bytes */
134%typemap(in) bt_uuid {
135 $1 = (unsigned char *) PyBytes_AsString($input);
136}
137
138/* Output argument typemap for UUID bytes */
139%typemap(out) bt_uuid {
140 if (!$1) {
141 Py_INCREF(Py_None);
142 $result = Py_None;
143 } else {
144 $result = PyBytes_FromStringAndSize((const char *) $1, 16);
145 }
146}
147
148/* Input argument typemap for bt_bool */
149%typemap(in) bt_bool {
150 $1 = PyObject_IsTrue($input);
151}
152
153/* Output argument typemap for bt_bool */
154%typemap(out) bt_bool {
155 if ($1 > 0) {
156 $result = Py_True;
157 } else {
158 $result = Py_False;
159 }
160 Py_INCREF($result);
161}
162
163/*
164 * Input and output argument typemaps for raw Python objects (direct).
165 *
166 * Those typemaps honor the convention of Python C function calls with
167 * respect to reference counting: parameters are passed as borrowed
168 * references, and objects are returned as new references. The wrapped
169 * C function must ensure that the return value is always a new
170 * reference, and never steal parameter references.
171 */
172%typemap(in) PyObject * {
173 $1 = $input;
174}
175
176%typemap(out) PyObject * {
177 $result = $1;
178}
179
180/* Native part initialization and finalization */
181void bt_bt2_init_from_bt2(void);
182void bt_bt2_exit_handler(void);
183
184/*
185 * These functions cause some -Wformat-nonliteral warnings, but we don't need
186 * them. Ignore them, so that we can keep the warning turned on.
187 */
188%ignore bt_current_thread_error_append_cause_from_component;
189%ignore bt_current_thread_error_append_cause_from_component_class;
190%ignore bt_current_thread_error_append_cause_from_message_iterator;
191%ignore bt_current_thread_error_append_cause_from_unknown;
192
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
200/*
201 * Define `__BT_ATTR_FORMAT_PRINTF` and `__BT_NOEXCEPT` to nothing,
202 * otherwise SWIG fails to parse the included header files that use it.
203 */
204#define __BT_ATTR_FORMAT_PRINTF(_string_index, _first_to_check)
205#define __BT_NOEXCEPT
206
207/* Common types */
208%include <babeltrace2/types.h>
209
210/* Common function status codes */
211%include <babeltrace2/func-status.h>
212
213/* Per-module interface files */
214%include "native_bt_autodisc.i"
215%include "native_bt_clock_class.i"
216%include "native_bt_clock_snapshot.i"
217%include "native_bt_component.i"
218%include "native_bt_component_class.i"
219%include "native_bt_connection.i"
220%include "native_bt_error.i"
221%include "native_bt_event.i"
222%include "native_bt_event_class.i"
223%include "native_bt_field.i"
224%include "native_bt_field_class.i"
225%include "native_bt_field_path.i"
226%include "native_bt_graph.i"
227%include "native_bt_integer_range_set.i"
228%include "native_bt_interrupter.i"
229%include "native_bt_logging.i"
230%include "native_bt_message.i"
231%include "native_bt_message_iterator.i"
232%include "native_bt_mip.i"
233%include "native_bt_packet.i"
234%include "native_bt_plugin.i"
235%include "native_bt_port.i"
236%include "native_bt_query_exec.i"
237%include "native_bt_stream.i"
238%include "native_bt_stream_class.i"
239%include "native_bt_trace.i"
240%include "native_bt_trace_class.i"
241%include "native_bt_value.i"
242%include "native_bt_version.i"
243
244%{
245
246/*
247 * This function is defined by SWIG. Declare here to avoid a
248 * -Wmissing-prototypes warning.
249 */
250extern "C" {
251 PyObject *SWIG_init(void);
252}
253
254%}
This page took 0.024543 seconds and 5 git commands to generate.