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 struct bt_component
*bt_component_filter_create(void)
26 struct bt_component_filter
*filter
= NULL
;
28 filter
= g_new0(struct bt_component_filter
, 1);
30 BT_LIB_LOGE_APPEND_CAUSE(
31 "Failed to allocate one filter component.");
36 return (void *) filter
;
40 const bt_component_class_filter
*
41 bt_component_filter_borrow_class_const(
42 const bt_component_filter
*component
)
44 struct bt_component_class
*cls
;
46 BT_ASSERT_PRE_DEV_COMP_NON_NULL(component
);
48 cls
= component
->parent
.class;
51 BT_ASSERT_DBG(cls
->type
== BT_COMPONENT_CLASS_TYPE_FILTER
);
53 return (bt_component_class_filter
*) cls
;
57 uint64_t bt_component_filter_get_output_port_count(
58 const struct bt_component_filter
*comp
)
60 /* bt_component_get_output_port_count() checks preconditions */
61 return bt_component_get_output_port_count((void *) comp
, __func__
);
65 const struct bt_port_output
*
66 bt_component_filter_borrow_output_port_by_name_const(
67 const struct bt_component_filter
*comp
, const char *name
)
70 * bt_component_borrow_output_port_by_name() logs details/errors
71 * and checks preconditions.
73 return bt_component_borrow_output_port_by_name(
74 (void *) comp
, name
, __func__
);
78 struct bt_self_component_port_output
*
79 bt_self_component_filter_borrow_output_port_by_name(
80 struct bt_self_component_filter
*comp
, const char *name
)
83 * bt_component_borrow_output_port_by_name() logs details/errors
84 * and checks preconditions.
86 return (void *) bt_component_borrow_output_port_by_name(
87 (void *) comp
, name
, __func__
);
91 const struct bt_port_output
*
92 bt_component_filter_borrow_output_port_by_index_const(
93 const struct bt_component_filter
*comp
, uint64_t index
)
96 * bt_component_borrow_output_port_by_index() logs
97 * details/errors and checks preconditions.
99 return bt_component_borrow_output_port_by_index(
100 (void *) comp
, index
, __func__
);
104 struct bt_self_component_port_output
*
105 bt_self_component_filter_borrow_output_port_by_index(
106 struct bt_self_component_filter
*comp
, uint64_t index
)
109 * bt_component_borrow_output_port_by_index() logs
110 * details/errors and checks preconditions.
112 return (void *) bt_component_borrow_output_port_by_index(
113 (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
;
127 * bt_component_add_output_port() logs details/errors and checks
130 status
= bt_component_add_output_port(comp
, name
, user_data
, &port
,
132 if (status
!= BT_FUNC_STATUS_OK
) {
137 /* Move reference to user */
138 *self_port
= (void *) port
;
142 bt_object_put_ref(port
);
147 uint64_t bt_component_filter_get_input_port_count(
148 const struct bt_component_filter
*component
)
150 /* bt_component_get_input_port_count() checks preconditions */
151 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__
);
167 struct bt_self_component_port_input
*
168 bt_self_component_filter_borrow_input_port_by_name(
169 struct bt_self_component_filter
*component
, const char *name
)
172 * bt_component_borrow_input_port_by_name() logs details/errors
173 * and checks preconditions.
175 return (void *) bt_component_borrow_input_port_by_name(
176 (void *) component
, name
, __func__
);
180 const struct bt_port_input
*
181 bt_component_filter_borrow_input_port_by_index_const(
182 const struct bt_component_filter
*component
, uint64_t index
)
185 * bt_component_borrow_input_port_by_index() logs details/errors
186 * and checks preconditions.
188 return bt_component_borrow_input_port_by_index(
189 (void *) component
, index
, __func__
);
193 struct bt_self_component_port_input
*
194 bt_self_component_filter_borrow_input_port_by_index(
195 struct bt_self_component_filter
*component
, uint64_t index
)
198 * bt_component_borrow_input_port_by_index() logs details/errors
199 * and checks preconditions.
201 return (void *) bt_component_borrow_input_port_by_index(
202 (void *) component
, index
, __func__
);
206 enum bt_self_component_add_port_status
bt_self_component_filter_add_input_port(
207 struct bt_self_component_filter
*self_comp
,
208 const char *name
, void *user_data
,
209 struct bt_self_component_port_input
**self_port
)
211 enum bt_self_component_add_port_status status
;
212 struct bt_port
*port
= NULL
;
213 struct bt_component
*comp
= (void *) self_comp
;
216 * bt_component_add_input_port() logs details/errors and checks
219 status
= bt_component_add_input_port(comp
, name
, user_data
, &port
,
221 if (status
!= BT_FUNC_STATUS_OK
) {
226 /* Move reference to user */
227 *self_port
= (void *) port
;
231 bt_object_put_ref(port
);
236 void bt_component_filter_get_ref(
237 const struct bt_component_filter
*component_filter
)
239 bt_object_get_ref(component_filter
);
243 void bt_component_filter_put_ref(
244 const struct bt_component_filter
*component_filter
)
246 bt_object_put_ref(component_filter
);