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