fb006f98186b0d2a88f0d3f390a8e85a33c3abb2
[babeltrace.git] / src / lib / graph / component-sink.c
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 void bt_component_sink_destroy(struct bt_component *component)
25 {
26 }
27
28 struct bt_component *bt_component_sink_create(
29 const struct bt_component_class *class)
30 {
31 struct bt_component_sink *sink = NULL;
32
33 sink = g_new0(struct bt_component_sink, 1);
34 if (!sink) {
35 BT_LIB_LOGE_APPEND_CAUSE(
36 "Failed to allocate one sink component.");
37 goto end;
38 }
39
40 end:
41 return (void *) sink;
42 }
43
44 BT_EXPORT
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
51 BT_ASSERT_PRE_DEV_COMP_NON_NULL(component);
52
53 cls = component->parent.class;
54
55 BT_ASSERT_DBG(cls);
56 BT_ASSERT_DBG(cls->type == BT_COMPONENT_CLASS_TYPE_SINK);
57
58 return (bt_component_class_sink *) cls;
59 }
60
61 BT_EXPORT
62 uint64_t bt_component_sink_get_input_port_count(
63 const struct bt_component_sink *component)
64 {
65 /* bt_component_get_input_port_count() checks preconditions */
66 return bt_component_get_input_port_count((void *) component, __func__);
67 }
68
69 BT_EXPORT
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)
73 {
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__);
80 }
81
82 BT_EXPORT
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 {
87 /*
88 * bt_component_borrow_input_port_by_name() logs details/errors
89 * and checks preconditions.
90 */
91 return (void *) bt_component_borrow_input_port_by_name(
92 (void *) component, name, __func__);
93 }
94
95 BT_EXPORT
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)
98 {
99 /*
100 * bt_component_borrow_input_port_by_index() logs details/errors
101 * and checks preconditions.
102 */
103 return bt_component_borrow_input_port_by_index(
104 (void *) component, index, __func__);
105 }
106
107 BT_EXPORT
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 {
112 /*
113 * bt_component_borrow_input_port_by_index() logs details/errors
114 * and checks preconditions.
115 */
116 return (void *) bt_component_borrow_input_port_by_index(
117 (void *) component, index, __func__);
118 }
119
120 BT_EXPORT
121 enum bt_self_component_add_port_status bt_self_component_sink_add_input_port(
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 {
126 enum bt_self_component_add_port_status status;
127 struct bt_port *port = NULL;
128 struct bt_component *comp = (void *) self_comp;
129
130 BT_ASSERT_PRE_NO_ERROR();
131
132 /*
133 * bt_component_add_input_port() logs details/errors and checks
134 * preconditions.
135 */
136 status = bt_component_add_input_port(comp, name, user_data, &port,
137 __func__);
138 if (status != BT_FUNC_STATUS_OK) {
139 goto end;
140 }
141
142 if (self_port) {
143 /* Move reference to user */
144 *self_port = (void *) port;
145 }
146
147 end:
148 bt_object_put_ref(port);
149 return status;
150 }
151
152 BT_EXPORT
153 bt_bool bt_self_component_sink_is_interrupted(
154 const struct bt_self_component_sink *self_comp)
155 {
156 struct bt_component *comp = (void *) self_comp;
157
158 BT_ASSERT_PRE_COMP_NON_NULL(comp);
159 return (bt_bool) bt_graph_is_interrupted(
160 bt_component_borrow_graph(comp));
161 }
162
163 BT_EXPORT
164 void bt_component_sink_get_ref(
165 const struct bt_component_sink *component_sink)
166 {
167 bt_object_get_ref(component_sink);
168 }
169
170 BT_EXPORT
171 void bt_component_sink_put_ref(
172 const struct bt_component_sink *component_sink)
173 {
174 bt_object_put_ref(component_sink);
175 }
This page took 0.031353 seconds and 3 git commands to generate.