4 * Babeltrace Sink Component
6 * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 #define BT_LOG_TAG "COMP-SINK"
30 #include <babeltrace/lib-logging-internal.h>
32 #include <babeltrace/compiler-internal.h>
33 #include <babeltrace/values.h>
34 #include <babeltrace/graph/component-sink-internal.h>
35 #include <babeltrace/graph/component-internal.h>
36 #include <babeltrace/graph/notification.h>
37 #include <babeltrace/graph/graph.h>
38 #include <babeltrace/assert-internal.h>
39 #include <babeltrace/assert-internal.h>
42 void bt_component_sink_destroy(struct bt_component
*component
)
47 struct bt_component
*bt_component_sink_create(
48 struct bt_component_class
*class)
50 struct bt_component_sink
*sink
= NULL
;
52 sink
= g_new0(struct bt_component_sink
, 1);
54 BT_LOGE_STR("Failed to allocate one sink component.");
59 return sink
? &sink
->parent
: NULL
;
63 enum bt_component_status
bt_component_sink_consume(
64 struct bt_component
*component
)
66 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
67 struct bt_component_class_sink
*sink_class
= NULL
;
70 BT_ASSERT(bt_component_get_class_type(component
) == BT_COMPONENT_CLASS_TYPE_SINK
);
71 sink_class
= container_of(component
->class, struct bt_component_class_sink
, parent
);
72 BT_ASSERT(sink_class
->methods
.consume
);
73 BT_LOGD("Calling user's consume method: "
74 "comp-addr=%p, comp-name=\"%s\"",
75 component
, bt_component_get_name(component
));
76 ret
= sink_class
->methods
.consume(bt_private_component_from_component(component
));
77 BT_LOGD("User method returned: status=%s",
78 bt_component_status_string(ret
));
80 BT_LOGW_STR("Consume method failed.");
86 int64_t bt_component_sink_get_input_port_count(struct bt_component
*component
)
91 BT_LOGW_STR("Invalid parameter: component is NULL.");
96 if (component
->class->type
!= BT_COMPONENT_CLASS_TYPE_SINK
) {
97 BT_LOGW("Invalid parameter: component's class is not a sink component class: "
98 "comp-addr=%p, comp-name=\"%s\", comp-class-type=%s",
99 component
, bt_component_get_name(component
),
100 bt_component_class_type_string(component
->class->type
));
105 /* bt_component_get_input_port_count() logs details/errors */
106 ret
= bt_component_get_input_port_count(component
);
112 struct bt_port
*bt_component_sink_get_input_port_by_name(
113 struct bt_component
*component
, const char *name
)
115 struct bt_port
*port
= NULL
;
118 BT_LOGW_STR("Invalid parameter: component is NULL.");
123 BT_LOGW_STR("Invalid parameter: name is NULL.");
127 if (component
->class->type
!= BT_COMPONENT_CLASS_TYPE_SINK
) {
128 BT_LOGW("Invalid parameter: component's class is not a sink component class: "
129 "comp-addr=%p, comp-name=\"%s\", comp-class-type=%s",
130 component
, bt_component_get_name(component
),
131 bt_component_class_type_string(component
->class->type
));
135 /* bt_component_get_input_port_by_name() logs details/errors */
136 port
= bt_component_get_input_port_by_name(component
, name
);
142 struct bt_port
*bt_component_sink_get_input_port_by_index(
143 struct bt_component
*component
, uint64_t index
)
145 struct bt_port
*port
= NULL
;
148 BT_LOGW_STR("Invalid parameter: component is NULL.");
152 if (component
->class->type
!= BT_COMPONENT_CLASS_TYPE_SINK
) {
153 BT_LOGW("Invalid parameter: component's class is not a sink component class: "
154 "comp-addr=%p, comp-name=\"%s\", comp-class-type=%s",
155 component
, bt_component_get_name(component
),
156 bt_component_class_type_string(component
->class->type
));
160 /* bt_component_get_input_port_by_index() logs details/errors */
161 port
= bt_component_get_input_port_by_index(component
, index
);
167 struct bt_private_port
*
168 bt_private_component_sink_get_input_private_port_by_index(
169 struct bt_private_component
*private_component
, uint64_t index
)
171 /* bt_component_sink_get_input_port_by_index() logs details/errors */
172 return bt_private_port_from_port(
173 bt_component_sink_get_input_port_by_index(
174 bt_component_borrow_from_private(private_component
), index
));
177 struct bt_private_port
*
178 bt_private_component_sink_get_input_private_port_by_name(
179 struct bt_private_component
*private_component
,
182 /* bt_component_sink_get_input_port_by_name() logs details/errors */
183 return bt_private_port_from_port(
184 bt_component_sink_get_input_port_by_name(
185 bt_component_borrow_from_private(private_component
), name
));
188 enum bt_component_status
bt_private_component_sink_add_input_private_port(
189 struct bt_private_component
*private_component
,
190 const char *name
, void *user_data
,
191 struct bt_private_port
**user_priv_port
)
193 enum bt_component_status status
= BT_COMPONENT_STATUS_OK
;
194 struct bt_port
*port
= NULL
;
195 struct bt_component
*component
=
196 bt_component_borrow_from_private(private_component
);
197 struct bt_graph
*graph
;
200 BT_LOGW_STR("Invalid parameter: component is NULL.");
201 status
= BT_COMPONENT_STATUS_INVALID
;
205 if (component
->class->type
!= BT_COMPONENT_CLASS_TYPE_SINK
) {
206 BT_LOGW("Invalid parameter: component's class is not a sink component class: "
207 "comp-addr=%p, comp-name=\"%s\", comp-class-type=%s",
208 component
, bt_component_get_name(component
),
209 bt_component_class_type_string(component
->class->type
));
210 status
= BT_COMPONENT_STATUS_INVALID
;
214 graph
= bt_component_borrow_graph(component
);
216 if (graph
&& bt_graph_is_canceled(graph
)) {
217 BT_LOGW("Cannot add input port to sink component: graph is canceled: "
218 "comp-addr=%p, comp-name=\"%s\", graph-addr=%p",
219 component
, bt_component_get_name(component
),
220 bt_component_borrow_graph(component
));
221 status
= BT_COMPONENT_STATUS_GRAPH_IS_CANCELED
;
225 /* bt_component_add_input_port() logs details/errors */
226 port
= bt_component_add_input_port(component
, name
, user_data
);
228 status
= BT_COMPONENT_STATUS_NOMEM
;
232 if (user_priv_port
) {
233 /* Move reference to user */
234 *user_priv_port
= bt_private_port_from_port(port
);