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-pre.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 BT_ASSERT_PRE_NO_ERROR();
37 filter
= g_new0(struct bt_component_filter
, 1);
39 BT_LIB_LOGE_APPEND_CAUSE(
40 "Failed to allocate one filter component.");
45 return (void *) filter
;
48 const bt_component_class_filter
*
49 bt_component_filter_borrow_class_const(
50 const bt_component_filter
*component
)
52 struct bt_component_class
*cls
;
54 BT_ASSERT_PRE_DEV_NON_NULL(component
, "Component");
56 cls
= component
->parent
.class;
59 BT_ASSERT_DBG(cls
->type
== BT_COMPONENT_CLASS_TYPE_FILTER
);
61 return (bt_component_class_filter
*) cls
;
64 uint64_t bt_component_filter_get_output_port_count(
65 const struct bt_component_filter
*comp
)
67 return bt_component_get_output_port_count((void *) comp
);
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
)
74 return bt_component_borrow_output_port_by_name(
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
)
82 return (void *) bt_component_borrow_output_port_by_name(
86 const struct bt_port_output
*
87 bt_component_filter_borrow_output_port_by_index_const(
88 const struct bt_component_filter
*comp
, uint64_t index
)
90 return bt_component_borrow_output_port_by_index(
91 (void *) comp
, index
);
94 struct bt_self_component_port_output
*
95 bt_self_component_filter_borrow_output_port_by_index(
96 struct bt_self_component_filter
*comp
, uint64_t index
)
98 return (void *) bt_component_borrow_output_port_by_index(
99 (void *) comp
, index
);
102 enum bt_self_component_add_port_status
bt_self_component_filter_add_output_port(
103 struct bt_self_component_filter
*self_comp
,
104 const char *name
, void *user_data
,
105 struct bt_self_component_port_output
**self_port
)
107 struct bt_component
*comp
= (void *) self_comp
;
108 enum bt_self_component_add_port_status status
;
109 struct bt_port
*port
= NULL
;
111 BT_ASSERT_PRE_NO_ERROR();
112 BT_ASSERT_PRE_OUTPUT_PORT_NAME_UNIQUE(comp
, name
);
114 /* bt_component_add_output_port() logs details and errors */
115 status
= bt_component_add_output_port(comp
, name
, user_data
, &port
);
116 if (status
!= BT_FUNC_STATUS_OK
) {
121 /* Move reference to user */
122 *self_port
= (void *) port
;
126 bt_object_put_ref(port
);
130 uint64_t bt_component_filter_get_input_port_count(
131 const struct bt_component_filter
*component
)
133 /* bt_component_get_input_port_count() logs details/errors */
134 return bt_component_get_input_port_count((void *) component
);
137 const struct bt_port_input
*bt_component_filter_borrow_input_port_by_name_const(
138 const struct bt_component_filter
*component
, const char *name
)
140 /* bt_component_borrow_input_port_by_name() logs details/errors */
141 return bt_component_borrow_input_port_by_name(
142 (void *) component
, name
);
145 struct bt_self_component_port_input
*
146 bt_self_component_filter_borrow_input_port_by_name(
147 struct bt_self_component_filter
*component
, const char *name
)
149 /* bt_component_borrow_input_port_by_name() logs details/errors */
150 return (void *) bt_component_borrow_input_port_by_name(
151 (void *) component
, name
);
154 const struct bt_port_input
*
155 bt_component_filter_borrow_input_port_by_index_const(
156 const struct bt_component_filter
*component
, uint64_t index
)
158 /* bt_component_borrow_input_port_by_index() logs details/errors */
159 return bt_component_borrow_input_port_by_index(
160 (void *) component
, index
);
163 struct bt_self_component_port_input
*
164 bt_self_component_filter_borrow_input_port_by_index(
165 struct bt_self_component_filter
*component
, uint64_t index
)
167 /* bt_component_borrow_input_port_by_index() logs details/errors */
168 return (void *) bt_component_borrow_input_port_by_index(
169 (void *) component
, index
);
172 enum bt_self_component_add_port_status
bt_self_component_filter_add_input_port(
173 struct bt_self_component_filter
*self_comp
,
174 const char *name
, void *user_data
,
175 struct bt_self_component_port_input
**self_port
)
177 enum bt_self_component_add_port_status status
;
178 struct bt_port
*port
= NULL
;
179 struct bt_component
*comp
= (void *) self_comp
;
181 BT_ASSERT_PRE_NO_ERROR();
182 BT_ASSERT_PRE_INPUT_PORT_NAME_UNIQUE(comp
, name
);
184 /* bt_component_add_input_port() logs details/errors */
185 status
= bt_component_add_input_port(comp
, name
, user_data
, &port
);
186 if (status
!= BT_FUNC_STATUS_OK
) {
191 /* Move reference to user */
192 *self_port
= (void *) port
;
196 bt_object_put_ref(port
);
200 void bt_component_filter_get_ref(
201 const struct bt_component_filter
*component_filter
)
203 bt_object_get_ref(component_filter
);
206 void bt_component_filter_put_ref(
207 const struct bt_component_filter
*component_filter
)
209 bt_object_put_ref(component_filter
);