2 * The MIT License (MIT)
4 * Copyright (c) 2016 Philippe Proulx <pproulx@efficios.com>
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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
25 /* From trace-const.h */
27 typedef enum bt_trace_status {
28 BT_TRACE_STATUS_OK = 0,
29 BT_TRACE_STATUS_NOMEM = -12,
32 typedef void (* bt_trace_destruction_listener_func)(
33 const bt_trace *trace, void *data);
35 extern const bt_trace_class *bt_trace_borrow_class_const(
36 const bt_trace *trace);
38 extern const char *bt_trace_get_name(const bt_trace *trace);
40 extern uint64_t bt_trace_get_stream_count(const bt_trace *trace);
42 extern const bt_stream *bt_trace_borrow_stream_by_index_const(
43 const bt_trace *trace, uint64_t index);
45 extern const bt_stream *bt_trace_borrow_stream_by_id_const(
46 const bt_trace *trace, uint64_t id);
48 extern bt_trace_status bt_trace_add_destruction_listener(
49 const bt_trace *trace,
50 bt_trace_destruction_listener_func listener,
51 void *data, uint64_t *listener_id);
53 extern bt_trace_status bt_trace_remove_destruction_listener(
54 const bt_trace *trace, uint64_t listener_id);
56 extern void bt_trace_get_ref(const bt_trace *trace);
58 extern void bt_trace_put_ref(const bt_trace *trace);
62 extern bt_trace_class *bt_trace_borrow_class(bt_trace *trace);
64 extern bt_trace *bt_trace_create(bt_trace_class *trace_class);
66 extern bt_trace_status bt_trace_set_name(bt_trace *trace,
69 extern bt_stream *bt_trace_borrow_stream_by_index(bt_trace *trace,
72 extern bt_stream *bt_trace_borrow_stream_by_id(bt_trace *trace,
77 trace_destroyed_listener(const bt_trace *trace, void *py_callable)
79 PyObject *py_trace_ptr = NULL;
80 PyObject *py_res = NULL;
82 py_trace_ptr = SWIG_NewPointerObj(SWIG_as_voidptr(trace),
83 SWIGTYPE_p_bt_trace, 0);
85 BT_LOGF_STR("Failed to create a SWIG pointer object.");
89 py_res = PyObject_CallFunction(py_callable, "(O)", py_trace_ptr);
91 BT_ASSERT(py_res == Py_None);
93 bt2_py_loge_exception();
96 Py_DECREF(py_trace_ptr);
100 uint64_t bt_py3_trace_add_destruction_listener(bt_trace *trace, PyObject *py_callable)
102 uint64_t id = UINT64_C(-1);
103 bt_trace_status status;
106 BT_ASSERT(py_callable);
108 status = bt_trace_add_destruction_listener(
109 trace, trace_destroyed_listener, py_callable, &id);
110 if (status != BT_TRACE_STATUS_OK) {
111 BT_LOGF_STR("Failed to add trace destruction listener.");
115 Py_INCREF(py_callable);
121 uint64_t bt_py3_trace_add_destruction_listener(bt_trace *trace,
122 PyObject *py_callable);