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