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(struct bt_component
*component
)
28 struct bt_component
*bt_component_filter_create(
29 const struct bt_component_class
*class)
31 struct bt_component_filter
*filter
= NULL
;
33 filter
= g_new0(struct bt_component_filter
, 1);
35 BT_LIB_LOGE_APPEND_CAUSE(
36 "Failed to allocate one filter component.");
41 return (void *) filter
;
45 const bt_component_class_filter
*
46 bt_component_filter_borrow_class_const(
47 const bt_component_filter
*component
)
49 struct bt_component_class
*cls
;
51 BT_ASSERT_PRE_DEV_COMP_NON_NULL(component
);
53 cls
= component
->parent
.class;
56 BT_ASSERT_DBG(cls
->type
== BT_COMPONENT_CLASS_TYPE_FILTER
);
58 return (bt_component_class_filter
*) cls
;
62 uint64_t bt_component_filter_get_output_port_count(
63 const struct bt_component_filter
*comp
)
65 /* bt_component_get_output_port_count() checks preconditions */
66 return bt_component_get_output_port_count((void *) comp
, __func__
);
70 const struct bt_port_output
*
71 bt_component_filter_borrow_output_port_by_name_const(
72 const struct bt_component_filter
*comp
, const char *name
)
75 * bt_component_borrow_output_port_by_name() logs details/errors
76 * and checks preconditions.
78 return bt_component_borrow_output_port_by_name(
79 (void *) comp
, name
, __func__
);
83 struct bt_self_component_port_output
*
84 bt_self_component_filter_borrow_output_port_by_name(
85 struct bt_self_component_filter
*comp
, const char *name
)
88 * bt_component_borrow_output_port_by_name() logs details/errors
89 * and checks preconditions.
91 return (void *) bt_component_borrow_output_port_by_name(
92 (void *) comp
, name
, __func__
);
96 const struct bt_port_output
*
97 bt_component_filter_borrow_output_port_by_index_const(
98 const struct bt_component_filter
*comp
, uint64_t index
)
101 * bt_component_borrow_output_port_by_index() logs
102 * details/errors and checks preconditions.
104 return bt_component_borrow_output_port_by_index(
105 (void *) comp
, index
, __func__
);
109 struct bt_self_component_port_output
*
110 bt_self_component_filter_borrow_output_port_by_index(
111 struct bt_self_component_filter
*comp
, uint64_t index
)
114 * bt_component_borrow_output_port_by_index() logs
115 * details/errors and checks preconditions.
117 return (void *) bt_component_borrow_output_port_by_index(
118 (void *) comp
, index
, __func__
);
122 enum bt_self_component_add_port_status
bt_self_component_filter_add_output_port(
123 struct bt_self_component_filter
*self_comp
,
124 const char *name
, void *user_data
,
125 struct bt_self_component_port_output
**self_port
)
127 struct bt_component
*comp
= (void *) self_comp
;
128 enum bt_self_component_add_port_status status
;
129 struct bt_port
*port
= NULL
;
131 BT_ASSERT_PRE_NO_ERROR();
134 * bt_component_add_output_port() logs details/errors and checks
137 status
= bt_component_add_output_port(comp
, name
, user_data
, &port
,
139 if (status
!= BT_FUNC_STATUS_OK
) {
144 /* Move reference to user */
145 *self_port
= (void *) port
;
149 bt_object_put_ref(port
);
154 uint64_t bt_component_filter_get_input_port_count(
155 const struct bt_component_filter
*component
)
157 /* bt_component_get_input_port_count() checks preconditions */
158 return bt_component_get_input_port_count((void *) component
, __func__
);
162 const struct bt_port_input
*bt_component_filter_borrow_input_port_by_name_const(
163 const struct bt_component_filter
*component
, const char *name
)
166 * bt_component_borrow_input_port_by_name() logs details/errors
167 * and checks preconditions.
169 return bt_component_borrow_input_port_by_name(
170 (void *) component
, name
, __func__
);
174 struct bt_self_component_port_input
*
175 bt_self_component_filter_borrow_input_port_by_name(
176 struct bt_self_component_filter
*component
, const char *name
)
179 * bt_component_borrow_input_port_by_name() logs details/errors
180 * and checks preconditions.
182 return (void *) bt_component_borrow_input_port_by_name(
183 (void *) component
, name
, __func__
);
187 const struct bt_port_input
*
188 bt_component_filter_borrow_input_port_by_index_const(
189 const struct bt_component_filter
*component
, uint64_t index
)
192 * bt_component_borrow_input_port_by_index() logs details/errors
193 * and checks preconditions.
195 return bt_component_borrow_input_port_by_index(
196 (void *) component
, index
, __func__
);
200 struct bt_self_component_port_input
*
201 bt_self_component_filter_borrow_input_port_by_index(
202 struct bt_self_component_filter
*component
, uint64_t index
)
205 * bt_component_borrow_input_port_by_index() logs details/errors
206 * and checks preconditions.
208 return (void *) bt_component_borrow_input_port_by_index(
209 (void *) component
, index
, __func__
);
213 enum bt_self_component_add_port_status
bt_self_component_filter_add_input_port(
214 struct bt_self_component_filter
*self_comp
,
215 const char *name
, void *user_data
,
216 struct bt_self_component_port_input
**self_port
)
218 enum bt_self_component_add_port_status status
;
219 struct bt_port
*port
= NULL
;
220 struct bt_component
*comp
= (void *) self_comp
;
222 BT_ASSERT_PRE_NO_ERROR();
225 * bt_component_add_input_port() logs details/errors and checks
228 status
= bt_component_add_input_port(comp
, name
, user_data
, &port
,
230 if (status
!= BT_FUNC_STATUS_OK
) {
235 /* Move reference to user */
236 *self_port
= (void *) port
;
240 bt_object_put_ref(port
);
245 void bt_component_filter_get_ref(
246 const struct bt_component_filter
*component_filter
)
248 bt_object_get_ref(component_filter
);
252 void bt_component_filter_put_ref(
253 const struct bt_component_filter
*component_filter
)
255 bt_object_put_ref(component_filter
);