| 1 | /* |
| 2 | * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com> |
| 3 | * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
| 4 | * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | * of this software and associated documentation files (the "Software"), to deal |
| 7 | * in the Software without restriction, including without limitation the rights |
| 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | * copies of the Software, and to permit persons to whom the Software is |
| 10 | * furnished to do so, subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice shall be included in |
| 13 | * all copies or substantial portions of the Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 | * SOFTWARE. |
| 22 | */ |
| 23 | |
| 24 | #define BT_LOG_TAG "COMP-FILTER" |
| 25 | #include <babeltrace/lib-logging-internal.h> |
| 26 | |
| 27 | #include <babeltrace/compiler-internal.h> |
| 28 | #include <babeltrace/value.h> |
| 29 | #include <babeltrace/graph/self-component-filter.h> |
| 30 | #include <babeltrace/graph/component-filter-const.h> |
| 31 | #include <babeltrace/graph/component-filter-internal.h> |
| 32 | #include <babeltrace/graph/component-internal.h> |
| 33 | #include <babeltrace/graph/component-class-internal.h> |
| 34 | #include <babeltrace/graph/graph.h> |
| 35 | #include <babeltrace/object.h> |
| 36 | #include <babeltrace/assert-internal.h> |
| 37 | #include <babeltrace/assert-pre-internal.h> |
| 38 | |
| 39 | BT_HIDDEN |
| 40 | void bt_component_filter_destroy(struct bt_component *component) |
| 41 | { |
| 42 | } |
| 43 | |
| 44 | BT_HIDDEN |
| 45 | struct bt_component *bt_component_filter_create( |
| 46 | const struct bt_component_class *class) |
| 47 | { |
| 48 | struct bt_component_filter *filter = NULL; |
| 49 | |
| 50 | filter = g_new0(struct bt_component_filter, 1); |
| 51 | if (!filter) { |
| 52 | BT_LOGE_STR("Failed to allocate one filter component."); |
| 53 | goto end; |
| 54 | } |
| 55 | |
| 56 | end: |
| 57 | return (void *) filter; |
| 58 | } |
| 59 | |
| 60 | uint64_t bt_component_filter_get_output_port_count( |
| 61 | const struct bt_component_filter *comp) |
| 62 | { |
| 63 | return bt_component_get_output_port_count((void *) comp); |
| 64 | } |
| 65 | |
| 66 | const struct bt_port_output * |
| 67 | bt_component_filter_borrow_output_port_by_name_const( |
| 68 | const struct bt_component_filter *comp, const char *name) |
| 69 | { |
| 70 | return bt_component_borrow_output_port_by_name( |
| 71 | (void *) comp, name); |
| 72 | } |
| 73 | |
| 74 | struct bt_self_component_port_output * |
| 75 | bt_self_component_filter_borrow_output_port_by_name( |
| 76 | struct bt_self_component_filter *comp, const char *name) |
| 77 | { |
| 78 | return (void *) bt_component_borrow_output_port_by_name( |
| 79 | (void *) comp, name); |
| 80 | } |
| 81 | |
| 82 | const struct bt_port_output * |
| 83 | bt_component_filter_borrow_output_port_by_index_const( |
| 84 | const struct bt_component_filter *comp, uint64_t index) |
| 85 | { |
| 86 | return bt_component_borrow_output_port_by_index( |
| 87 | (void *) comp, index); |
| 88 | } |
| 89 | |
| 90 | struct bt_self_component_port_output * |
| 91 | bt_self_component_filter_borrow_output_port_by_index( |
| 92 | struct bt_self_component_filter *comp, uint64_t index) |
| 93 | { |
| 94 | return (void *) bt_component_borrow_output_port_by_index( |
| 95 | (void *) comp, index); |
| 96 | } |
| 97 | |
| 98 | enum bt_self_component_status bt_self_component_filter_add_output_port( |
| 99 | struct bt_self_component_filter *self_comp, |
| 100 | const char *name, void *user_data, |
| 101 | struct bt_self_component_port_output **self_port) |
| 102 | { |
| 103 | struct bt_component *comp = (void *) self_comp; |
| 104 | int status = BT_SELF_COMPONENT_STATUS_OK; |
| 105 | struct bt_port *port = NULL; |
| 106 | |
| 107 | /* bt_component_add_output_port() logs details and errors */ |
| 108 | port = (void *) bt_component_add_output_port(comp, name, user_data); |
| 109 | if (!port) { |
| 110 | status = BT_SELF_COMPONENT_STATUS_NOMEM; |
| 111 | goto end; |
| 112 | } |
| 113 | |
| 114 | if (self_port) { |
| 115 | /* Move reference to user */ |
| 116 | *self_port = (void *) port; |
| 117 | port = NULL; |
| 118 | } |
| 119 | |
| 120 | end: |
| 121 | bt_object_put_ref(port); |
| 122 | return status; |
| 123 | } |
| 124 | |
| 125 | uint64_t bt_component_filter_get_input_port_count( |
| 126 | const struct bt_component_filter *component) |
| 127 | { |
| 128 | /* bt_component_get_input_port_count() logs details/errors */ |
| 129 | return bt_component_get_input_port_count((void *) component); |
| 130 | } |
| 131 | |
| 132 | const struct bt_port_input *bt_component_filter_borrow_input_port_by_name_const( |
| 133 | const struct bt_component_filter *component, const char *name) |
| 134 | { |
| 135 | /* bt_component_borrow_input_port_by_name() logs details/errors */ |
| 136 | return bt_component_borrow_input_port_by_name( |
| 137 | (void *) component, name); |
| 138 | } |
| 139 | |
| 140 | struct bt_self_component_port_input * |
| 141 | bt_self_component_filter_borrow_input_port_by_name( |
| 142 | struct bt_self_component_filter *component, const char *name) |
| 143 | { |
| 144 | /* bt_component_borrow_input_port_by_name() logs details/errors */ |
| 145 | return (void *) bt_component_borrow_input_port_by_name( |
| 146 | (void *) component, name); |
| 147 | } |
| 148 | |
| 149 | const struct bt_port_input * |
| 150 | bt_component_filter_borrow_input_port_by_index_const( |
| 151 | const struct bt_component_filter *component, uint64_t index) |
| 152 | { |
| 153 | /* bt_component_borrow_input_port_by_index() logs details/errors */ |
| 154 | return bt_component_borrow_input_port_by_index( |
| 155 | (void *) component, index); |
| 156 | } |
| 157 | |
| 158 | struct bt_self_component_port_input * |
| 159 | bt_self_component_filter_borrow_input_port_by_index( |
| 160 | struct bt_self_component_filter *component, uint64_t index) |
| 161 | { |
| 162 | /* bt_component_borrow_input_port_by_index() logs details/errors */ |
| 163 | return (void *) bt_component_borrow_input_port_by_index( |
| 164 | (void *) component, index); |
| 165 | } |
| 166 | |
| 167 | enum bt_self_component_status bt_self_component_filter_add_input_port( |
| 168 | struct bt_self_component_filter *self_comp, |
| 169 | const char *name, void *user_data, |
| 170 | struct bt_self_component_port_input **self_port) |
| 171 | { |
| 172 | int status = BT_SELF_COMPONENT_STATUS_OK; |
| 173 | struct bt_port *port = NULL; |
| 174 | struct bt_component *comp = (void *) self_comp; |
| 175 | |
| 176 | /* bt_component_add_input_port() logs details/errors */ |
| 177 | port = (void *) bt_component_add_input_port(comp, name, user_data); |
| 178 | if (!port) { |
| 179 | status = BT_SELF_COMPONENT_STATUS_NOMEM; |
| 180 | goto end; |
| 181 | } |
| 182 | |
| 183 | if (self_port) { |
| 184 | /* Move reference to user */ |
| 185 | *self_port = (void *) port; |
| 186 | port = NULL; |
| 187 | } |
| 188 | |
| 189 | end: |
| 190 | bt_object_put_ref(port); |
| 191 | return status; |
| 192 | } |