2 * SPDX-License-Identifier: MIT
4 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
5 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 #define BT_LOG_TAG "LIB/COMPONENT-FILTER"
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-filter.h"
20 #include "component.h"
21 #include "component-class.h"
22 #include "lib/func-status.h"
24 void bt_component_filter_destroy(
25 struct bt_component
*component
__attribute__((unused
)))
29 struct bt_component
*bt_component_filter_create(
30 const struct bt_component_class
*class __attribute__((unused
)))
32 struct bt_component_filter
*filter
= NULL
;
34 filter
= g_new0(struct bt_component_filter
, 1);
36 BT_LIB_LOGE_APPEND_CAUSE(
37 "Failed to allocate one filter component.");
42 return (void *) filter
;
46 const bt_component_class_filter
*
47 bt_component_filter_borrow_class_const(
48 const bt_component_filter
*component
)
50 struct bt_component_class
*cls
;
52 BT_ASSERT_PRE_DEV_COMP_NON_NULL(component
);
54 cls
= component
->parent
.class;
57 BT_ASSERT_DBG(cls
->type
== BT_COMPONENT_CLASS_TYPE_FILTER
);
59 return (bt_component_class_filter
*) cls
;
63 uint64_t bt_component_filter_get_output_port_count(
64 const struct bt_component_filter
*comp
)
66 /* bt_component_get_output_port_count() checks preconditions */
67 return bt_component_get_output_port_count((void *) comp
, __func__
);
71 const struct bt_port_output
*
72 bt_component_filter_borrow_output_port_by_name_const(
73 const struct bt_component_filter
*comp
, const char *name
)
76 * bt_component_borrow_output_port_by_name() logs details/errors
77 * and checks preconditions.
79 return bt_component_borrow_output_port_by_name(
80 (void *) comp
, name
, __func__
);
84 struct bt_self_component_port_output
*
85 bt_self_component_filter_borrow_output_port_by_name(
86 struct bt_self_component_filter
*comp
, const char *name
)
89 * bt_component_borrow_output_port_by_name() logs details/errors
90 * and checks preconditions.
92 return (void *) bt_component_borrow_output_port_by_name(
93 (void *) comp
, name
, __func__
);
97 const struct bt_port_output
*
98 bt_component_filter_borrow_output_port_by_index_const(
99 const struct bt_component_filter
*comp
, uint64_t index
)
102 * bt_component_borrow_output_port_by_index() logs
103 * details/errors and checks preconditions.
105 return bt_component_borrow_output_port_by_index(
106 (void *) comp
, index
, __func__
);
110 struct bt_self_component_port_output
*
111 bt_self_component_filter_borrow_output_port_by_index(
112 struct bt_self_component_filter
*comp
, uint64_t index
)
115 * bt_component_borrow_output_port_by_index() logs
116 * details/errors and checks preconditions.
118 return (void *) bt_component_borrow_output_port_by_index(
119 (void *) comp
, index
, __func__
);
123 enum bt_self_component_add_port_status
bt_self_component_filter_add_output_port(
124 struct bt_self_component_filter
*self_comp
,
125 const char *name
, void *user_data
,
126 struct bt_self_component_port_output
**self_port
)
128 struct bt_component
*comp
= (void *) self_comp
;
129 enum bt_self_component_add_port_status status
;
130 struct bt_port
*port
= NULL
;
133 * bt_component_add_output_port() logs details/errors and checks
136 status
= bt_component_add_output_port(comp
, name
, user_data
, &port
,
138 if (status
!= BT_FUNC_STATUS_OK
) {
143 /* Move reference to user */
144 *self_port
= (void *) port
;
148 bt_object_put_ref(port
);
153 uint64_t bt_component_filter_get_input_port_count(
154 const struct bt_component_filter
*component
)
156 /* bt_component_get_input_port_count() checks preconditions */
157 return bt_component_get_input_port_count((void *) component
, __func__
);
161 const struct bt_port_input
*bt_component_filter_borrow_input_port_by_name_const(
162 const struct bt_component_filter
*component
, const char *name
)
165 * bt_component_borrow_input_port_by_name() logs details/errors
166 * and checks preconditions.
168 return bt_component_borrow_input_port_by_name(
169 (void *) component
, name
, __func__
);
173 struct bt_self_component_port_input
*
174 bt_self_component_filter_borrow_input_port_by_name(
175 struct bt_self_component_filter
*component
, const char *name
)
178 * bt_component_borrow_input_port_by_name() logs details/errors
179 * and checks preconditions.
181 return (void *) bt_component_borrow_input_port_by_name(
182 (void *) component
, name
, __func__
);
186 const struct bt_port_input
*
187 bt_component_filter_borrow_input_port_by_index_const(
188 const struct bt_component_filter
*component
, uint64_t index
)
191 * bt_component_borrow_input_port_by_index() logs details/errors
192 * and checks preconditions.
194 return bt_component_borrow_input_port_by_index(
195 (void *) component
, index
, __func__
);
199 struct bt_self_component_port_input
*
200 bt_self_component_filter_borrow_input_port_by_index(
201 struct bt_self_component_filter
*component
, uint64_t index
)
204 * bt_component_borrow_input_port_by_index() logs details/errors
205 * and checks preconditions.
207 return (void *) bt_component_borrow_input_port_by_index(
208 (void *) component
, index
, __func__
);
212 enum bt_self_component_add_port_status
bt_self_component_filter_add_input_port(
213 struct bt_self_component_filter
*self_comp
,
214 const char *name
, void *user_data
,
215 struct bt_self_component_port_input
**self_port
)
217 enum bt_self_component_add_port_status status
;
218 struct bt_port
*port
= NULL
;
219 struct bt_component
*comp
= (void *) self_comp
;
222 * bt_component_add_input_port() logs details/errors and checks
225 status
= bt_component_add_input_port(comp
, name
, user_data
, &port
,
227 if (status
!= BT_FUNC_STATUS_OK
) {
232 /* Move reference to user */
233 *self_port
= (void *) port
;
237 bt_object_put_ref(port
);
242 void bt_component_filter_get_ref(
243 const struct bt_component_filter
*component_filter
)
245 bt_object_get_ref(component_filter
);
249 void bt_component_filter_put_ref(
250 const struct bt_component_filter
*component_filter
)
252 bt_object_put_ref(component_filter
);