Visibility hidden by default
[babeltrace.git] / src / lib / graph / component-filter.c
CommitLineData
d94d92ac 1/*
0235b0db
MJ
2 * SPDX-License-Identifier: MIT
3 *
e2f7325d 4 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
d94d92ac 5 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
d94d92ac
PP
6 */
7
350ad6c1 8#define BT_LOG_TAG "LIB/COMPONENT-FILTER"
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-filter.h"
20#include "component.h"
21#include "component-class.h"
d24d5663 22#include "lib/func-status.h"
578e048b 23
d94d92ac
PP
24void bt_component_filter_destroy(struct bt_component *component)
25{
26}
27
d94d92ac 28struct bt_component *bt_component_filter_create(
0d72b8c3 29 const struct bt_component_class *class)
d94d92ac
PP
30{
31 struct bt_component_filter *filter = NULL;
32
33 filter = g_new0(struct bt_component_filter, 1);
34 if (!filter) {
870631a2
PP
35 BT_LIB_LOGE_APPEND_CAUSE(
36 "Failed to allocate one filter component.");
d94d92ac
PP
37 goto end;
38 }
39
40end:
41 return (void *) filter;
42}
43
1353b066 44BT_EXPORT
752d0e47
SM
45const bt_component_class_filter *
46bt_component_filter_borrow_class_const(
47 const bt_component_filter *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_FILTER);
752d0e47
SM
57
58 return (bt_component_class_filter *) cls;
59}
60
1353b066 61BT_EXPORT
d94d92ac 62uint64_t bt_component_filter_get_output_port_count(
0d72b8c3 63 const struct bt_component_filter *comp)
d94d92ac 64{
1778c2a4
PP
65 /* bt_component_get_output_port_count() checks preconditions */
66 return bt_component_get_output_port_count((void *) comp, __func__);
d94d92ac
PP
67}
68
1353b066 69BT_EXPORT
0d72b8c3
PP
70const struct bt_port_output *
71bt_component_filter_borrow_output_port_by_name_const(
72 const struct bt_component_filter *comp, const char *name)
d94d92ac 73{
1778c2a4
PP
74 /*
75 * bt_component_borrow_output_port_by_name() logs details/errors
76 * and checks preconditions.
77 */
d94d92ac 78 return bt_component_borrow_output_port_by_name(
1778c2a4 79 (void *) comp, name, __func__);
d94d92ac
PP
80}
81
1353b066 82BT_EXPORT
d94d92ac
PP
83struct bt_self_component_port_output *
84bt_self_component_filter_borrow_output_port_by_name(
85 struct bt_self_component_filter *comp, const char *name)
86{
1778c2a4
PP
87 /*
88 * bt_component_borrow_output_port_by_name() logs details/errors
89 * and checks preconditions.
90 */
d94d92ac 91 return (void *) bt_component_borrow_output_port_by_name(
1778c2a4 92 (void *) comp, name, __func__);
d94d92ac
PP
93}
94
1353b066 95BT_EXPORT
0d72b8c3
PP
96const struct bt_port_output *
97bt_component_filter_borrow_output_port_by_index_const(
98 const struct bt_component_filter *comp, uint64_t index)
d94d92ac 99{
1778c2a4
PP
100 /*
101 * bt_component_borrow_output_port_by_index() logs
102 * details/errors and checks preconditions.
103 */
d94d92ac 104 return bt_component_borrow_output_port_by_index(
1778c2a4 105 (void *) comp, index, __func__);
d94d92ac
PP
106}
107
1353b066 108BT_EXPORT
d94d92ac
PP
109struct bt_self_component_port_output *
110bt_self_component_filter_borrow_output_port_by_index(
111 struct bt_self_component_filter *comp, uint64_t index)
112{
1778c2a4
PP
113 /*
114 * bt_component_borrow_output_port_by_index() logs
115 * details/errors and checks preconditions.
116 */
d94d92ac 117 return (void *) bt_component_borrow_output_port_by_index(
1778c2a4 118 (void *) comp, index, __func__);
d94d92ac
PP
119}
120
1353b066 121BT_EXPORT
d24d5663 122enum bt_self_component_add_port_status bt_self_component_filter_add_output_port(
d94d92ac
PP
123 struct bt_self_component_filter *self_comp,
124 const char *name, void *user_data,
125 struct bt_self_component_port_output **self_port)
126{
127 struct bt_component *comp = (void *) self_comp;
d24d5663 128 enum bt_self_component_add_port_status status;
d94d92ac
PP
129 struct bt_port *port = NULL;
130
17f3083a
SM
131 BT_ASSERT_PRE_NO_ERROR();
132
1778c2a4
PP
133 /*
134 * bt_component_add_output_port() logs details/errors and checks
135 * preconditions.
136 */
137 status = bt_component_add_output_port(comp, name, user_data, &port,
138 __func__);
d24d5663 139 if (status != BT_FUNC_STATUS_OK) {
d94d92ac
PP
140 goto end;
141 }
142
143 if (self_port) {
144 /* Move reference to user */
145 *self_port = (void *) port;
d94d92ac
PP
146 }
147
148end:
149 bt_object_put_ref(port);
150 return status;
151}
152
1353b066 153BT_EXPORT
d94d92ac 154uint64_t bt_component_filter_get_input_port_count(
0d72b8c3 155 const struct bt_component_filter *component)
d94d92ac 156{
1778c2a4
PP
157 /* bt_component_get_input_port_count() checks preconditions */
158 return bt_component_get_input_port_count((void *) component, __func__);
d94d92ac
PP
159}
160
1353b066 161BT_EXPORT
0d72b8c3
PP
162const struct bt_port_input *bt_component_filter_borrow_input_port_by_name_const(
163 const struct bt_component_filter *component, const char *name)
d94d92ac 164{
1778c2a4
PP
165 /*
166 * bt_component_borrow_input_port_by_name() logs details/errors
167 * and checks preconditions.
168 */
d94d92ac 169 return bt_component_borrow_input_port_by_name(
1778c2a4 170 (void *) component, name, __func__);
d94d92ac
PP
171}
172
1353b066 173BT_EXPORT
d94d92ac
PP
174struct bt_self_component_port_input *
175bt_self_component_filter_borrow_input_port_by_name(
176 struct bt_self_component_filter *component, const char *name)
177{
1778c2a4
PP
178 /*
179 * bt_component_borrow_input_port_by_name() logs details/errors
180 * and checks preconditions.
181 */
d94d92ac 182 return (void *) bt_component_borrow_input_port_by_name(
1778c2a4 183 (void *) component, name, __func__);
d94d92ac
PP
184}
185
1353b066 186BT_EXPORT
0d72b8c3
PP
187const struct bt_port_input *
188bt_component_filter_borrow_input_port_by_index_const(
189 const struct bt_component_filter *component, uint64_t index)
d94d92ac 190{
1778c2a4
PP
191 /*
192 * bt_component_borrow_input_port_by_index() logs details/errors
193 * and checks preconditions.
194 */
d94d92ac 195 return bt_component_borrow_input_port_by_index(
1778c2a4 196 (void *) component, index, __func__);
d94d92ac
PP
197}
198
1353b066 199BT_EXPORT
d94d92ac
PP
200struct bt_self_component_port_input *
201bt_self_component_filter_borrow_input_port_by_index(
202 struct bt_self_component_filter *component, uint64_t index)
203{
1778c2a4
PP
204 /*
205 * bt_component_borrow_input_port_by_index() logs details/errors
206 * and checks preconditions.
207 */
d94d92ac 208 return (void *) bt_component_borrow_input_port_by_index(
1778c2a4 209 (void *) component, index, __func__);
d94d92ac
PP
210}
211
1353b066 212BT_EXPORT
d24d5663 213enum bt_self_component_add_port_status bt_self_component_filter_add_input_port(
d94d92ac
PP
214 struct bt_self_component_filter *self_comp,
215 const char *name, void *user_data,
216 struct bt_self_component_port_input **self_port)
217{
d24d5663 218 enum bt_self_component_add_port_status status;
d94d92ac
PP
219 struct bt_port *port = NULL;
220 struct bt_component *comp = (void *) self_comp;
221
17f3083a
SM
222 BT_ASSERT_PRE_NO_ERROR();
223
1778c2a4
PP
224 /*
225 * bt_component_add_input_port() logs details/errors and checks
226 * preconditions.
227 */
228 status = bt_component_add_input_port(comp, name, user_data, &port,
229 __func__);
d24d5663 230 if (status != BT_FUNC_STATUS_OK) {
d94d92ac
PP
231 goto end;
232 }
233
234 if (self_port) {
235 /* Move reference to user */
236 *self_port = (void *) port;
d94d92ac
PP
237 }
238
239end:
240 bt_object_put_ref(port);
241 return status;
242}
c5b9b441 243
1353b066 244BT_EXPORT
c5b9b441
PP
245void bt_component_filter_get_ref(
246 const struct bt_component_filter *component_filter)
247{
248 bt_object_get_ref(component_filter);
249}
250
1353b066 251BT_EXPORT
c5b9b441
PP
252void bt_component_filter_put_ref(
253 const struct bt_component_filter *component_filter)
254{
255 bt_object_put_ref(component_filter);
256}
This page took 0.076548 seconds and 4 git commands to generate.