| 1 | /* |
| 2 | * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com> |
| 3 | * Copyright 2015 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 "LIB/COMPONENT-SINK" |
| 25 | #include "lib/logging.h" |
| 26 | |
| 27 | #include "common/assert.h" |
| 28 | #include "lib/assert-pre.h" |
| 29 | #include "lib/assert-post.h" |
| 30 | #include "compat/compiler.h" |
| 31 | #include <babeltrace2/value.h> |
| 32 | #include <babeltrace2/graph/self-component.h> |
| 33 | #include <babeltrace2/graph/component.h> |
| 34 | #include <babeltrace2/graph/graph.h> |
| 35 | |
| 36 | #include "component-sink.h" |
| 37 | #include "component.h" |
| 38 | #include "graph.h" |
| 39 | #include "lib/func-status.h" |
| 40 | |
| 41 | BT_HIDDEN |
| 42 | void bt_component_sink_destroy(struct bt_component *component) |
| 43 | { |
| 44 | } |
| 45 | |
| 46 | BT_HIDDEN |
| 47 | struct bt_component *bt_component_sink_create( |
| 48 | const struct bt_component_class *class) |
| 49 | { |
| 50 | struct bt_component_sink *sink = NULL; |
| 51 | |
| 52 | BT_ASSERT_PRE_NO_ERROR(); |
| 53 | |
| 54 | sink = g_new0(struct bt_component_sink, 1); |
| 55 | if (!sink) { |
| 56 | BT_LIB_LOGE_APPEND_CAUSE( |
| 57 | "Failed to allocate one sink component."); |
| 58 | goto end; |
| 59 | } |
| 60 | |
| 61 | end: |
| 62 | return (void *) sink; |
| 63 | } |
| 64 | |
| 65 | const bt_component_class_sink * |
| 66 | bt_component_sink_borrow_class_const( |
| 67 | const bt_component_sink *component) |
| 68 | { |
| 69 | struct bt_component_class *cls; |
| 70 | |
| 71 | BT_ASSERT_PRE_DEV_NON_NULL(component, "Component"); |
| 72 | |
| 73 | cls = component->parent.class; |
| 74 | |
| 75 | BT_ASSERT_DBG(cls); |
| 76 | BT_ASSERT_DBG(cls->type == BT_COMPONENT_CLASS_TYPE_SINK); |
| 77 | |
| 78 | return (bt_component_class_sink *) cls; |
| 79 | } |
| 80 | |
| 81 | uint64_t bt_component_sink_get_input_port_count( |
| 82 | const struct bt_component_sink *component) |
| 83 | { |
| 84 | /* bt_component_get_input_port_count() logs details/errors */ |
| 85 | return bt_component_get_input_port_count((void *) component); |
| 86 | } |
| 87 | |
| 88 | const struct bt_port_input * |
| 89 | bt_component_sink_borrow_input_port_by_name_const( |
| 90 | const struct bt_component_sink *component, const char *name) |
| 91 | { |
| 92 | /* bt_component_borrow_input_port_by_name() logs details/errors */ |
| 93 | return bt_component_borrow_input_port_by_name((void *) component, name); |
| 94 | } |
| 95 | |
| 96 | struct bt_self_component_port_input * |
| 97 | bt_self_component_sink_borrow_input_port_by_name( |
| 98 | struct bt_self_component_sink *component, const char *name) |
| 99 | { |
| 100 | /* bt_component_borrow_input_port_by_name() logs details/errors */ |
| 101 | return (void *) bt_component_borrow_input_port_by_name( |
| 102 | (void *) component, name); |
| 103 | } |
| 104 | |
| 105 | const struct bt_port_input *bt_component_sink_borrow_input_port_by_index_const( |
| 106 | const struct bt_component_sink *component, uint64_t index) |
| 107 | { |
| 108 | /* bt_component_borrow_input_port_by_index() logs details/errors */ |
| 109 | return bt_component_borrow_input_port_by_index( |
| 110 | (void *) component, index); |
| 111 | } |
| 112 | |
| 113 | struct bt_self_component_port_input * |
| 114 | bt_self_component_sink_borrow_input_port_by_index( |
| 115 | struct bt_self_component_sink *component, uint64_t index) |
| 116 | { |
| 117 | /* bt_component_borrow_input_port_by_index() logs details/errors */ |
| 118 | return (void *) bt_component_borrow_input_port_by_index( |
| 119 | (void *) component, index); |
| 120 | } |
| 121 | |
| 122 | enum bt_self_component_add_port_status bt_self_component_sink_add_input_port( |
| 123 | struct bt_self_component_sink *self_comp, |
| 124 | const char *name, void *user_data, |
| 125 | struct bt_self_component_port_input **self_port) |
| 126 | { |
| 127 | enum bt_self_component_add_port_status status; |
| 128 | struct bt_port *port = NULL; |
| 129 | struct bt_component *comp = (void *) self_comp; |
| 130 | |
| 131 | BT_ASSERT_PRE_NO_ERROR(); |
| 132 | |
| 133 | /* bt_component_add_input_port() logs details/errors */ |
| 134 | status = bt_component_add_input_port(comp, name, user_data, &port); |
| 135 | if (status != BT_FUNC_STATUS_OK) { |
| 136 | goto end; |
| 137 | } |
| 138 | |
| 139 | if (self_port) { |
| 140 | /* Move reference to user */ |
| 141 | *self_port = (void *) port; |
| 142 | } |
| 143 | |
| 144 | end: |
| 145 | bt_object_put_ref(port); |
| 146 | return status; |
| 147 | } |
| 148 | |
| 149 | bt_bool bt_self_component_sink_is_interrupted( |
| 150 | const struct bt_self_component_sink *self_comp) |
| 151 | { |
| 152 | struct bt_component *comp = (void *) self_comp; |
| 153 | |
| 154 | BT_ASSERT_PRE_NON_NULL(comp, "Component"); |
| 155 | return (bt_bool) bt_graph_is_interrupted( |
| 156 | bt_component_borrow_graph(comp)); |
| 157 | } |
| 158 | |
| 159 | void bt_component_sink_get_ref( |
| 160 | const struct bt_component_sink *component_sink) |
| 161 | { |
| 162 | bt_object_get_ref(component_sink); |
| 163 | } |
| 164 | |
| 165 | void bt_component_sink_put_ref( |
| 166 | const struct bt_component_sink *component_sink) |
| 167 | { |
| 168 | bt_object_put_ref(component_sink); |
| 169 | } |