cpp-common/bt2c/fmt.hpp: use `wise_enum::string_type` in `EnableIfIsWiseEnum` definition
[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
c8515511 24struct bt_component *bt_component_filter_create(void)
d94d92ac
PP
25{
26 struct bt_component_filter *filter = NULL;
27
28 filter = g_new0(struct bt_component_filter, 1);
29 if (!filter) {
870631a2
PP
30 BT_LIB_LOGE_APPEND_CAUSE(
31 "Failed to allocate one filter component.");
d94d92ac
PP
32 goto end;
33 }
34
35end:
36 return (void *) filter;
37}
38
1353b066 39BT_EXPORT
752d0e47
SM
40const bt_component_class_filter *
41bt_component_filter_borrow_class_const(
42 const bt_component_filter *component)
43{
44 struct bt_component_class *cls;
45
d5b13b9b 46 BT_ASSERT_PRE_DEV_COMP_NON_NULL(component);
752d0e47
SM
47
48 cls = component->parent.class;
49
98b15851
PP
50 BT_ASSERT_DBG(cls);
51 BT_ASSERT_DBG(cls->type == BT_COMPONENT_CLASS_TYPE_FILTER);
752d0e47
SM
52
53 return (bt_component_class_filter *) cls;
54}
55
1353b066 56BT_EXPORT
d94d92ac 57uint64_t bt_component_filter_get_output_port_count(
0d72b8c3 58 const struct bt_component_filter *comp)
d94d92ac 59{
1778c2a4
PP
60 /* bt_component_get_output_port_count() checks preconditions */
61 return bt_component_get_output_port_count((void *) comp, __func__);
d94d92ac
PP
62}
63
1353b066 64BT_EXPORT
0d72b8c3
PP
65const struct bt_port_output *
66bt_component_filter_borrow_output_port_by_name_const(
67 const struct bt_component_filter *comp, const char *name)
d94d92ac 68{
1778c2a4
PP
69 /*
70 * bt_component_borrow_output_port_by_name() logs details/errors
71 * and checks preconditions.
72 */
d94d92ac 73 return bt_component_borrow_output_port_by_name(
1778c2a4 74 (void *) comp, name, __func__);
d94d92ac
PP
75}
76
1353b066 77BT_EXPORT
d94d92ac
PP
78struct bt_self_component_port_output *
79bt_self_component_filter_borrow_output_port_by_name(
80 struct bt_self_component_filter *comp, const char *name)
81{
1778c2a4
PP
82 /*
83 * bt_component_borrow_output_port_by_name() logs details/errors
84 * and checks preconditions.
85 */
d94d92ac 86 return (void *) bt_component_borrow_output_port_by_name(
1778c2a4 87 (void *) comp, name, __func__);
d94d92ac
PP
88}
89
1353b066 90BT_EXPORT
0d72b8c3
PP
91const struct bt_port_output *
92bt_component_filter_borrow_output_port_by_index_const(
93 const struct bt_component_filter *comp, uint64_t index)
d94d92ac 94{
1778c2a4
PP
95 /*
96 * bt_component_borrow_output_port_by_index() logs
97 * details/errors and checks preconditions.
98 */
d94d92ac 99 return bt_component_borrow_output_port_by_index(
1778c2a4 100 (void *) comp, index, __func__);
d94d92ac
PP
101}
102
1353b066 103BT_EXPORT
d94d92ac
PP
104struct bt_self_component_port_output *
105bt_self_component_filter_borrow_output_port_by_index(
106 struct bt_self_component_filter *comp, uint64_t index)
107{
1778c2a4
PP
108 /*
109 * bt_component_borrow_output_port_by_index() logs
110 * details/errors and checks preconditions.
111 */
d94d92ac 112 return (void *) bt_component_borrow_output_port_by_index(
1778c2a4 113 (void *) comp, index, __func__);
d94d92ac
PP
114}
115
1353b066 116BT_EXPORT
d24d5663 117enum bt_self_component_add_port_status bt_self_component_filter_add_output_port(
d94d92ac
PP
118 struct bt_self_component_filter *self_comp,
119 const char *name, void *user_data,
120 struct bt_self_component_port_output **self_port)
121{
122 struct bt_component *comp = (void *) self_comp;
d24d5663 123 enum bt_self_component_add_port_status status;
d94d92ac
PP
124 struct bt_port *port = NULL;
125
1778c2a4
PP
126 /*
127 * bt_component_add_output_port() logs details/errors and checks
128 * preconditions.
129 */
130 status = bt_component_add_output_port(comp, name, user_data, &port,
131 __func__);
d24d5663 132 if (status != BT_FUNC_STATUS_OK) {
d94d92ac
PP
133 goto end;
134 }
135
136 if (self_port) {
137 /* Move reference to user */
138 *self_port = (void *) port;
d94d92ac
PP
139 }
140
141end:
142 bt_object_put_ref(port);
143 return status;
144}
145
1353b066 146BT_EXPORT
d94d92ac 147uint64_t bt_component_filter_get_input_port_count(
0d72b8c3 148 const struct bt_component_filter *component)
d94d92ac 149{
1778c2a4
PP
150 /* bt_component_get_input_port_count() checks preconditions */
151 return bt_component_get_input_port_count((void *) component, __func__);
d94d92ac
PP
152}
153
1353b066 154BT_EXPORT
0d72b8c3
PP
155const struct bt_port_input *bt_component_filter_borrow_input_port_by_name_const(
156 const struct bt_component_filter *component, const char *name)
d94d92ac 157{
1778c2a4
PP
158 /*
159 * bt_component_borrow_input_port_by_name() logs details/errors
160 * and checks preconditions.
161 */
d94d92ac 162 return bt_component_borrow_input_port_by_name(
1778c2a4 163 (void *) component, name, __func__);
d94d92ac
PP
164}
165
1353b066 166BT_EXPORT
d94d92ac
PP
167struct bt_self_component_port_input *
168bt_self_component_filter_borrow_input_port_by_name(
169 struct bt_self_component_filter *component, const char *name)
170{
1778c2a4
PP
171 /*
172 * bt_component_borrow_input_port_by_name() logs details/errors
173 * and checks preconditions.
174 */
d94d92ac 175 return (void *) bt_component_borrow_input_port_by_name(
1778c2a4 176 (void *) component, name, __func__);
d94d92ac
PP
177}
178
1353b066 179BT_EXPORT
0d72b8c3
PP
180const struct bt_port_input *
181bt_component_filter_borrow_input_port_by_index_const(
182 const struct bt_component_filter *component, uint64_t index)
d94d92ac 183{
1778c2a4
PP
184 /*
185 * bt_component_borrow_input_port_by_index() logs details/errors
186 * and checks preconditions.
187 */
d94d92ac 188 return bt_component_borrow_input_port_by_index(
1778c2a4 189 (void *) component, index, __func__);
d94d92ac
PP
190}
191
1353b066 192BT_EXPORT
d94d92ac
PP
193struct bt_self_component_port_input *
194bt_self_component_filter_borrow_input_port_by_index(
195 struct bt_self_component_filter *component, uint64_t index)
196{
1778c2a4
PP
197 /*
198 * bt_component_borrow_input_port_by_index() logs details/errors
199 * and checks preconditions.
200 */
d94d92ac 201 return (void *) bt_component_borrow_input_port_by_index(
1778c2a4 202 (void *) component, index, __func__);
d94d92ac
PP
203}
204
1353b066 205BT_EXPORT
d24d5663 206enum bt_self_component_add_port_status bt_self_component_filter_add_input_port(
d94d92ac
PP
207 struct bt_self_component_filter *self_comp,
208 const char *name, void *user_data,
209 struct bt_self_component_port_input **self_port)
210{
d24d5663 211 enum bt_self_component_add_port_status status;
d94d92ac
PP
212 struct bt_port *port = NULL;
213 struct bt_component *comp = (void *) self_comp;
214
1778c2a4
PP
215 /*
216 * bt_component_add_input_port() logs details/errors and checks
217 * preconditions.
218 */
219 status = bt_component_add_input_port(comp, name, user_data, &port,
220 __func__);
d24d5663 221 if (status != BT_FUNC_STATUS_OK) {
d94d92ac
PP
222 goto end;
223 }
224
225 if (self_port) {
226 /* Move reference to user */
227 *self_port = (void *) port;
d94d92ac
PP
228 }
229
230end:
231 bt_object_put_ref(port);
232 return status;
233}
c5b9b441 234
1353b066 235BT_EXPORT
c5b9b441
PP
236void bt_component_filter_get_ref(
237 const struct bt_component_filter *component_filter)
238{
239 bt_object_get_ref(component_filter);
240}
241
1353b066 242BT_EXPORT
c5b9b441
PP
243void bt_component_filter_put_ref(
244 const struct bt_component_filter *component_filter)
245{
246 bt_object_put_ref(component_filter);
247}
This page took 0.091685 seconds and 5 git commands to generate.