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"
25 void bt_component_filter_destroy(struct bt_component
*component
)
30 struct bt_component
*bt_component_filter_create(
31 const struct bt_component_class
*class)
33 struct bt_component_filter
*filter
= NULL
;
35 filter
= g_new0(struct bt_component_filter
, 1);
37 BT_LIB_LOGE_APPEND_CAUSE(
38 "Failed to allocate one filter component.");
43 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
;
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__
);
69 const struct bt_port_output
*
70 bt_component_filter_borrow_output_port_by_name_const(
71 const struct bt_component_filter
*comp
, const char *name
)
74 * bt_component_borrow_output_port_by_name() logs details/errors
75 * and checks preconditions.
77 return bt_component_borrow_output_port_by_name(
78 (void *) comp
, name
, __func__
);
81 struct bt_self_component_port_output
*
82 bt_self_component_filter_borrow_output_port_by_name(
83 struct bt_self_component_filter
*comp
, const char *name
)
86 * bt_component_borrow_output_port_by_name() logs details/errors
87 * and checks preconditions.
89 return (void *) bt_component_borrow_output_port_by_name(
90 (void *) comp
, name
, __func__
);
93 const struct bt_port_output
*
94 bt_component_filter_borrow_output_port_by_index_const(
95 const struct bt_component_filter
*comp
, uint64_t index
)
98 * bt_component_borrow_output_port_by_index() logs
99 * details/errors and checks preconditions.
101 return bt_component_borrow_output_port_by_index(
102 (void *) comp
, index
, __func__
);
105 struct bt_self_component_port_output
*
106 bt_self_component_filter_borrow_output_port_by_index(
107 struct bt_self_component_filter
*comp
, uint64_t index
)
110 * bt_component_borrow_output_port_by_index() logs
111 * details/errors and checks preconditions.
113 return (void *) bt_component_borrow_output_port_by_index(
114 (void *) comp
, index
, __func__
);
117 enum bt_self_component_add_port_status
bt_self_component_filter_add_output_port(
118 struct bt_self_component_filter
*self_comp
,
119 const char *name
, void *user_data
,
120 struct bt_self_component_port_output
**self_port
)
122 struct bt_component
*comp
= (void *) self_comp
;
123 enum bt_self_component_add_port_status status
;
124 struct bt_port
*port
= NULL
;
126 BT_ASSERT_PRE_NO_ERROR();
129 * bt_component_add_output_port() logs details/errors and checks
132 status
= bt_component_add_output_port(comp
, name
, user_data
, &port
,
134 if (status
!= BT_FUNC_STATUS_OK
) {
139 /* Move reference to user */
140 *self_port
= (void *) port
;
144 bt_object_put_ref(port
);
148 uint64_t bt_component_filter_get_input_port_count(
149 const struct bt_component_filter
*component
)
151 /* bt_component_get_input_port_count() checks preconditions */
152 return bt_component_get_input_port_count((void *) component
, __func__
);
155 const struct bt_port_input
*bt_component_filter_borrow_input_port_by_name_const(
156 const struct bt_component_filter
*component
, const char *name
)
159 * bt_component_borrow_input_port_by_name() logs details/errors
160 * and checks preconditions.
162 return bt_component_borrow_input_port_by_name(
163 (void *) component
, name
, __func__
);
166 struct bt_self_component_port_input
*
167 bt_self_component_filter_borrow_input_port_by_name(
168 struct bt_self_component_filter
*component
, const char *name
)
171 * bt_component_borrow_input_port_by_name() logs details/errors
172 * and checks preconditions.
174 return (void *) bt_component_borrow_input_port_by_name(
175 (void *) component
, name
, __func__
);
178 const struct bt_port_input
*
179 bt_component_filter_borrow_input_port_by_index_const(
180 const struct bt_component_filter
*component
, uint64_t index
)
183 * bt_component_borrow_input_port_by_index() logs details/errors
184 * and checks preconditions.
186 return bt_component_borrow_input_port_by_index(
187 (void *) component
, index
, __func__
);
190 struct bt_self_component_port_input
*
191 bt_self_component_filter_borrow_input_port_by_index(
192 struct bt_self_component_filter
*component
, uint64_t index
)
195 * bt_component_borrow_input_port_by_index() logs details/errors
196 * and checks preconditions.
198 return (void *) bt_component_borrow_input_port_by_index(
199 (void *) component
, index
, __func__
);
202 enum bt_self_component_add_port_status
bt_self_component_filter_add_input_port(
203 struct bt_self_component_filter
*self_comp
,
204 const char *name
, void *user_data
,
205 struct bt_self_component_port_input
**self_port
)
207 enum bt_self_component_add_port_status status
;
208 struct bt_port
*port
= NULL
;
209 struct bt_component
*comp
= (void *) self_comp
;
211 BT_ASSERT_PRE_NO_ERROR();
214 * bt_component_add_input_port() logs details/errors and checks
217 status
= bt_component_add_input_port(comp
, name
, user_data
, &port
,
219 if (status
!= BT_FUNC_STATUS_OK
) {
224 /* Move reference to user */
225 *self_port
= (void *) port
;
229 bt_object_put_ref(port
);
233 void bt_component_filter_get_ref(
234 const struct bt_component_filter
*component_filter
)
236 bt_object_get_ref(component_filter
);
239 void bt_component_filter_put_ref(
240 const struct bt_component_filter
*component_filter
)
242 bt_object_put_ref(component_filter
);