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 | ||
7 | static void | |
8 | trace_class_destroyed_listener(const bt_trace_class *trace_class, void *py_callable) | |
9 | { | |
10 | PyObject *py_trace_class_ptr = NULL; | |
11 | PyObject *py_res = NULL; | |
12 | ||
13 | py_trace_class_ptr = SWIG_NewPointerObj(SWIG_as_voidptr(trace_class), | |
14 | SWIGTYPE_p_bt_trace_class, 0); | |
15 | if (!py_trace_class_ptr) { | |
16 | BT_LOGF_STR("Failed to create a SWIG pointer object."); | |
498e7994 | 17 | bt_common_abort(); |
4212232c PP |
18 | } |
19 | ||
20 | py_res = PyObject_CallFunction(py_callable, "(O)", py_trace_class_ptr); | |
6dbc1938 | 21 | if (!py_res) { |
981f33dd | 22 | logw_exception_clear(BT_LOG_OUTPUT_LEVEL); |
6dbc1938 | 23 | goto end; |
4212232c PP |
24 | } |
25 | ||
6dbc1938 SM |
26 | BT_ASSERT(py_res == Py_None); |
27 | ||
28 | end: | |
4212232c PP |
29 | Py_DECREF(py_trace_class_ptr); |
30 | Py_XDECREF(py_res); | |
31 | } | |
32 | ||
33 | static | |
34 | int bt_bt2_trace_class_add_destruction_listener( | |
35 | bt_trace_class *trace_class, PyObject *py_callable, | |
36 | bt_listener_id *id) | |
37 | { | |
38 | bt_trace_class_add_listener_status status; | |
39 | ||
40 | BT_ASSERT(trace_class); | |
41 | BT_ASSERT(py_callable); | |
6dbc1938 | 42 | |
4212232c PP |
43 | status = bt_trace_class_add_destruction_listener( |
44 | trace_class, trace_class_destroyed_listener, py_callable, id); | |
45 | if (status == __BT_FUNC_STATUS_OK) { | |
46 | Py_INCREF(py_callable); | |
47 | } | |
48 | ||
49 | return status; | |
50 | } |