2 * SPDX-License-Identifier: MIT
4 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
5 * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 #define BT_LOG_TAG "LIB/COMPONENT-SINK"
9 #include "lib/logging.h"
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>
19 #include "component-sink.h"
20 #include "component.h"
22 #include "lib/func-status.h"
25 void bt_component_sink_destroy(struct bt_component
*component
)
30 struct bt_component
*bt_component_sink_create(
31 const struct bt_component_class
*class)
33 struct bt_component_sink
*sink
= NULL
;
35 BT_ASSERT_PRE_NO_ERROR();
37 sink
= g_new0(struct bt_component_sink
, 1);
39 BT_LIB_LOGE_APPEND_CAUSE(
40 "Failed to allocate one sink component.");
48 const bt_component_class_sink
*
49 bt_component_sink_borrow_class_const(
50 const bt_component_sink
*component
)
52 struct bt_component_class
*cls
;
54 BT_ASSERT_PRE_DEV_COMP_NON_NULL(component
);
56 cls
= component
->parent
.class;
59 BT_ASSERT_DBG(cls
->type
== BT_COMPONENT_CLASS_TYPE_SINK
);
61 return (bt_component_class_sink
*) cls
;
64 uint64_t bt_component_sink_get_input_port_count(
65 const struct bt_component_sink
*component
)
67 /* bt_component_get_input_port_count() logs details/errors */
68 return bt_component_get_input_port_count((void *) component
);
71 const struct bt_port_input
*
72 bt_component_sink_borrow_input_port_by_name_const(
73 const struct bt_component_sink
*component
, const char *name
)
75 /* bt_component_borrow_input_port_by_name() logs details/errors */
76 return bt_component_borrow_input_port_by_name((void *) component
, name
);
79 struct bt_self_component_port_input
*
80 bt_self_component_sink_borrow_input_port_by_name(
81 struct bt_self_component_sink
*component
, const char *name
)
83 /* bt_component_borrow_input_port_by_name() logs details/errors */
84 return (void *) bt_component_borrow_input_port_by_name(
85 (void *) component
, name
);
88 const struct bt_port_input
*bt_component_sink_borrow_input_port_by_index_const(
89 const struct bt_component_sink
*component
, uint64_t index
)
91 /* bt_component_borrow_input_port_by_index() logs details/errors */
92 return bt_component_borrow_input_port_by_index(
93 (void *) component
, index
);
96 struct bt_self_component_port_input
*
97 bt_self_component_sink_borrow_input_port_by_index(
98 struct bt_self_component_sink
*component
, uint64_t index
)
100 /* bt_component_borrow_input_port_by_index() logs details/errors */
101 return (void *) bt_component_borrow_input_port_by_index(
102 (void *) component
, index
);
105 enum bt_self_component_add_port_status
bt_self_component_sink_add_input_port(
106 struct bt_self_component_sink
*self_comp
,
107 const char *name
, void *user_data
,
108 struct bt_self_component_port_input
**self_port
)
110 enum bt_self_component_add_port_status status
;
111 struct bt_port
*port
= NULL
;
112 struct bt_component
*comp
= (void *) self_comp
;
114 BT_ASSERT_PRE_NO_ERROR();
115 BT_ASSERT_PRE_INPUT_PORT_NAME_UNIQUE(comp
, name
);
117 /* bt_component_add_input_port() logs details/errors */
118 status
= bt_component_add_input_port(comp
, name
, user_data
, &port
);
119 if (status
!= BT_FUNC_STATUS_OK
) {
124 /* Move reference to user */
125 *self_port
= (void *) port
;
129 bt_object_put_ref(port
);
133 bt_bool
bt_self_component_sink_is_interrupted(
134 const struct bt_self_component_sink
*self_comp
)
136 struct bt_component
*comp
= (void *) self_comp
;
138 BT_ASSERT_PRE_COMP_NON_NULL(comp
);
139 return (bt_bool
) bt_graph_is_interrupted(
140 bt_component_borrow_graph(comp
));
143 void bt_component_sink_get_ref(
144 const struct bt_component_sink
*component_sink
)
146 bt_object_get_ref(component_sink
);
149 void bt_component_sink_put_ref(
150 const struct bt_component_sink
*component_sink
)
152 bt_object_put_ref(component_sink
);