| 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 | /* From trace-class-const.h */ |
| 26 | |
| 27 | typedef enum bt_trace_class_status { |
| 28 | BT_TRACE_CLASS_STATUS_OK = 0, |
| 29 | BT_TRACE_CLASS_STATUS_NOMEM = -12, |
| 30 | } bt_trace_class_status; |
| 31 | |
| 32 | typedef void (* bt_trace_class_destruction_listener_func)( |
| 33 | const bt_trace_class *trace_class, void *data); |
| 34 | |
| 35 | extern bt_bool bt_trace_class_assigns_automatic_stream_class_id( |
| 36 | const bt_trace_class *trace_class); |
| 37 | |
| 38 | extern const char *bt_trace_class_get_name( |
| 39 | const bt_trace_class *trace_class); |
| 40 | |
| 41 | extern bt_uuid bt_trace_class_get_uuid( |
| 42 | const bt_trace_class *trace_class); |
| 43 | |
| 44 | extern uint64_t bt_trace_class_get_environment_entry_count( |
| 45 | const bt_trace_class *trace_class); |
| 46 | |
| 47 | extern void bt_trace_class_borrow_environment_entry_by_index_const( |
| 48 | const bt_trace_class *trace_class, uint64_t index, |
| 49 | const char **OUT, const bt_value **OUT_VALUE); |
| 50 | |
| 51 | extern const bt_value * |
| 52 | bt_trace_class_borrow_environment_entry_value_by_name_const( |
| 53 | const bt_trace_class *trace_class, const char *name); |
| 54 | |
| 55 | extern uint64_t bt_trace_class_get_stream_class_count( |
| 56 | const bt_trace_class *trace_class); |
| 57 | |
| 58 | extern const bt_stream_class * |
| 59 | bt_trace_class_borrow_stream_class_by_index_const( |
| 60 | const bt_trace_class *trace_class, uint64_t index); |
| 61 | |
| 62 | extern const bt_stream_class *bt_trace_class_borrow_stream_class_by_id_const( |
| 63 | const bt_trace_class *trace_class, uint64_t id); |
| 64 | |
| 65 | extern bt_trace_class_status bt_trace_class_add_destruction_listener( |
| 66 | const bt_trace_class *trace_class, |
| 67 | bt_trace_class_destruction_listener_func listener, |
| 68 | void *data, uint64_t *listener_id); |
| 69 | |
| 70 | extern bt_trace_class_status bt_trace_class_remove_destruction_listener( |
| 71 | const bt_trace_class *trace_class, uint64_t listener_id); |
| 72 | |
| 73 | extern void bt_trace_class_get_ref(const bt_trace_class *trace_class); |
| 74 | |
| 75 | extern void bt_trace_class_put_ref(const bt_trace_class *trace_class); |
| 76 | |
| 77 | /* From trace-class.h */ |
| 78 | |
| 79 | extern bt_trace_class *bt_trace_class_create(bt_self_component *self_comp); |
| 80 | |
| 81 | extern void bt_trace_class_set_assigns_automatic_stream_class_id( |
| 82 | bt_trace_class *trace_class, bt_bool value); |
| 83 | |
| 84 | extern bt_trace_class_status bt_trace_class_set_name( |
| 85 | bt_trace_class *trace_class, const char *name); |
| 86 | |
| 87 | extern void bt_trace_class_set_uuid(bt_trace_class *trace_class, |
| 88 | bt_uuid uuid); |
| 89 | |
| 90 | extern bt_trace_class_status bt_trace_class_set_environment_entry_integer( |
| 91 | bt_trace_class *trace_class, |
| 92 | const char *name, int64_t value); |
| 93 | |
| 94 | extern bt_trace_class_status bt_trace_class_set_environment_entry_string( |
| 95 | bt_trace_class *trace_class, |
| 96 | const char *name, const char *value); |
| 97 | |
| 98 | extern bt_stream_class *bt_trace_class_borrow_stream_class_by_index( |
| 99 | bt_trace_class *trace_class, uint64_t index); |
| 100 | |
| 101 | extern bt_stream_class *bt_trace_class_borrow_stream_class_by_id( |
| 102 | bt_trace_class *trace_class, uint64_t id); |
| 103 | |
| 104 | /* Helper functions for Python */ |
| 105 | %{ |
| 106 | static void |
| 107 | trace_class_destroyed_listener(const bt_trace_class *trace_class, void *py_callable) |
| 108 | { |
| 109 | PyObject *py_trace_class_ptr = NULL; |
| 110 | PyObject *py_res = NULL; |
| 111 | |
| 112 | py_trace_class_ptr = SWIG_NewPointerObj(SWIG_as_voidptr(trace_class), |
| 113 | SWIGTYPE_p_bt_trace_class, 0); |
| 114 | if (!py_trace_class_ptr) { |
| 115 | BT_LOGF_STR("Failed to create a SWIG pointer object."); |
| 116 | abort(); |
| 117 | } |
| 118 | |
| 119 | py_res = PyObject_CallFunction(py_callable, "(O)", py_trace_class_ptr); |
| 120 | if (py_res != NULL) { |
| 121 | BT_ASSERT(py_res == Py_None); |
| 122 | } else { |
| 123 | bt2_py_loge_exception(); |
| 124 | } |
| 125 | |
| 126 | Py_DECREF(py_trace_class_ptr); |
| 127 | Py_XDECREF(py_res); |
| 128 | } |
| 129 | |
| 130 | uint64_t bt_py3_trace_class_add_destruction_listener(bt_trace_class *trace_class, |
| 131 | PyObject *py_callable) |
| 132 | { |
| 133 | uint64_t id = UINT64_C(-1); |
| 134 | bt_trace_class_status status; |
| 135 | |
| 136 | BT_ASSERT(trace_class); |
| 137 | BT_ASSERT(py_callable); |
| 138 | |
| 139 | status = bt_trace_class_add_destruction_listener( |
| 140 | trace_class, trace_class_destroyed_listener, py_callable, &id); |
| 141 | if (status != BT_TRACE_CLASS_STATUS_OK) { |
| 142 | BT_LOGF_STR("Failed to add trace class destruction listener."); |
| 143 | abort(); |
| 144 | } |
| 145 | |
| 146 | Py_INCREF(py_callable); |
| 147 | |
| 148 | return id; |
| 149 | } |
| 150 | %} |
| 151 | |
| 152 | uint64_t bt_py3_trace_class_add_destruction_listener(bt_trace_class *trace_class, |
| 153 | PyObject *py_callable); |