Commit | Line | Data |
---|---|---|
4212232c | 1 | /* |
0235b0db | 2 | * SPDX-License-Identifier: MIT |
4212232c PP |
3 | * |
4 | * Copyright (c) 2016 Philippe Proulx <pproulx@efficios.com> | |
4212232c PP |
5 | */ |
6 | ||
ae2be88d SM |
7 | #ifndef BABELTRACE_BINDINGS_PYTHON_BT2_BT2_NATIVE_BT_TRACE_CLASS_I_H |
8 | #define BABELTRACE_BINDINGS_PYTHON_BT2_BT2_NATIVE_BT_TRACE_CLASS_I_H | |
9 | ||
4212232c PP |
10 | static void |
11 | trace_class_destroyed_listener(const bt_trace_class *trace_class, void *py_callable) | |
12 | { | |
13 | PyObject *py_trace_class_ptr = NULL; | |
14 | PyObject *py_res = NULL; | |
15 | ||
16 | py_trace_class_ptr = SWIG_NewPointerObj(SWIG_as_voidptr(trace_class), | |
17 | SWIGTYPE_p_bt_trace_class, 0); | |
18 | if (!py_trace_class_ptr) { | |
19 | BT_LOGF_STR("Failed to create a SWIG pointer object."); | |
498e7994 | 20 | bt_common_abort(); |
4212232c PP |
21 | } |
22 | ||
23 | py_res = PyObject_CallFunction(py_callable, "(O)", py_trace_class_ptr); | |
6dbc1938 | 24 | if (!py_res) { |
981f33dd | 25 | logw_exception_clear(BT_LOG_OUTPUT_LEVEL); |
6dbc1938 | 26 | goto end; |
4212232c PP |
27 | } |
28 | ||
6dbc1938 SM |
29 | BT_ASSERT(py_res == Py_None); |
30 | ||
31 | end: | |
4212232c PP |
32 | Py_DECREF(py_trace_class_ptr); |
33 | Py_XDECREF(py_res); | |
34 | } | |
35 | ||
36 | static | |
37 | int bt_bt2_trace_class_add_destruction_listener( | |
38 | bt_trace_class *trace_class, PyObject *py_callable, | |
39 | bt_listener_id *id) | |
40 | { | |
41 | bt_trace_class_add_listener_status status; | |
42 | ||
43 | BT_ASSERT(trace_class); | |
44 | BT_ASSERT(py_callable); | |
6dbc1938 | 45 | |
4212232c PP |
46 | status = bt_trace_class_add_destruction_listener( |
47 | trace_class, trace_class_destroyed_listener, py_callable, id); | |
48 | if (status == __BT_FUNC_STATUS_OK) { | |
49 | Py_INCREF(py_callable); | |
50 | } | |
51 | ||
52 | return status; | |
53 | } | |
ae2be88d SM |
54 | |
55 | #endif /* BABELTRACE_BINDINGS_PYTHON_BT2_BT2_NATIVE_BT_TRACE_CLASS_I_H */ |