4 * Babeltrace Filter Component
6 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 #define BT_LOG_TAG "COMP-FILTER"
30 #include <babeltrace/lib-logging-internal.h>
32 #include <babeltrace/compiler-internal.h>
33 #include <babeltrace/values.h>
34 #include <babeltrace/graph/private-component.h>
35 #include <babeltrace/graph/component-filter-internal.h>
36 #include <babeltrace/graph/component-internal.h>
37 #include <babeltrace/graph/component-class-internal.h>
38 #include <babeltrace/graph/notification.h>
39 #include <babeltrace/graph/notification-iterator-internal.h>
40 #include <babeltrace/graph/graph.h>
43 void bt_component_filter_destroy(struct bt_component
*component
)
48 struct bt_component
*bt_component_filter_create(
49 struct bt_component_class
*class)
51 struct bt_component_filter
*filter
= NULL
;
53 filter
= g_new0(struct bt_component_filter
, 1);
55 BT_LOGE_STR("Failed to allocate one filter component.");
60 return filter
? &filter
->parent
: NULL
;
63 int64_t bt_component_filter_get_input_port_count(
64 struct bt_component
*component
)
69 BT_LOGW_STR("Invalid parameter: component is NULL.");
74 if (component
->class->type
!= BT_COMPONENT_CLASS_TYPE_FILTER
) {
75 BT_LOGW("Invalid parameter: component's class is not a filter component class: "
76 "comp-addr=%p, comp-name=\"%s\", comp-class-type=%s",
77 component
, bt_component_get_name(component
),
78 bt_component_class_type_string(component
->class->type
));
83 ret
= (int64_t) bt_component_get_input_port_count(component
);
89 struct bt_port
*bt_component_filter_get_input_port_by_name(
90 struct bt_component
*component
, const char *name
)
92 struct bt_port
*port
= NULL
;
95 BT_LOGW_STR("Invalid parameter: component is NULL.");
100 BT_LOGW_STR("Invalid parameter: name is NULL.");
104 if (component
->class->type
!= BT_COMPONENT_CLASS_TYPE_FILTER
) {
105 BT_LOGW("Invalid parameter: component's class is not a filter component class: "
106 "comp-addr=%p, comp-name=\"%s\", comp-class-type=%s",
107 component
, bt_component_get_name(component
),
108 bt_component_class_type_string(component
->class->type
));
112 /* bt_component_get_input_port_by_name() logs details/errors */
113 port
= bt_component_get_input_port_by_name(component
, name
);
119 struct bt_port
*bt_component_filter_get_input_port_by_index(
120 struct bt_component
*component
, uint64_t index
)
122 struct bt_port
*port
= NULL
;
125 BT_LOGW_STR("Invalid parameter: component is NULL.");
129 if (component
->class->type
!= BT_COMPONENT_CLASS_TYPE_FILTER
) {
130 BT_LOGW("Invalid parameter: component's class is not a filter component class: "
131 "comp-addr=%p, comp-name=\"%s\", comp-class-type=%s",
132 component
, bt_component_get_name(component
),
133 bt_component_class_type_string(component
->class->type
));
137 /* bt_component_get_input_port_by_index() logs details/errors */
138 port
= bt_component_get_input_port_by_index(component
, index
);
144 int64_t bt_component_filter_get_output_port_count(
145 struct bt_component
*component
)
150 BT_LOGW_STR("Invalid parameter: component is NULL.");
155 if (component
->class->type
!= BT_COMPONENT_CLASS_TYPE_FILTER
) {
156 BT_LOGW("Invalid parameter: component's class is not a filter component class: "
157 "comp-addr=%p, comp-name=\"%s\", comp-class-type=%s",
158 component
, bt_component_get_name(component
),
159 bt_component_class_type_string(component
->class->type
));
164 /* bt_component_get_output_port_count() logs details/errors */
165 ret
= bt_component_get_output_port_count(component
);
171 struct bt_port
*bt_component_filter_get_output_port_by_name(
172 struct bt_component
*component
, const char *name
)
174 struct bt_port
*port
= NULL
;
177 BT_LOGW_STR("Invalid parameter: component is NULL.");
182 BT_LOGW_STR("Invalid parameter: name is NULL.");
186 if (component
->class->type
!= BT_COMPONENT_CLASS_TYPE_FILTER
) {
187 BT_LOGW("Invalid parameter: component's class is not a filter component class: "
188 "comp-addr=%p, comp-name=\"%s\", comp-class-type=%s",
189 component
, bt_component_get_name(component
),
190 bt_component_class_type_string(component
->class->type
));
194 /* bt_component_get_output_port_by_name() logs details/errors */
195 port
= bt_component_get_output_port_by_name(component
, name
);
201 struct bt_port
*bt_component_filter_get_output_port_by_index(
202 struct bt_component
*component
, uint64_t index
)
204 struct bt_port
*port
= NULL
;
207 BT_LOGW_STR("Invalid parameter: component is NULL.");
211 if (component
->class->type
!= BT_COMPONENT_CLASS_TYPE_FILTER
) {
212 BT_LOGW("Invalid parameter: component's class is not a filter component class: "
213 "comp-addr=%p, comp-name=\"%s\", comp-class-type=%s",
214 component
, bt_component_get_name(component
),
215 bt_component_class_type_string(component
->class->type
));
219 /* bt_component_get_output_port_by_index() logs details/errors */
220 port
= bt_component_get_output_port_by_index(component
, index
);
226 struct bt_private_port
*
227 bt_private_component_filter_get_input_private_port_by_index(
228 struct bt_private_component
*private_component
, uint64_t index
)
230 /* bt_component_filter_get_input_port_by_index() logs details/errors */
231 return bt_private_port_from_port(
232 bt_component_filter_get_input_port_by_index(
233 bt_component_borrow_from_private(private_component
), index
));
236 struct bt_private_port
*
237 bt_private_component_filter_get_input_private_port_by_name(
238 struct bt_private_component
*private_component
,
241 /* bt_component_filter_get_input_port_by_name() logs details/errors */
242 return bt_private_port_from_port(
243 bt_component_filter_get_input_port_by_name(
244 bt_component_borrow_from_private(private_component
), name
));
247 enum bt_component_status
bt_private_component_filter_add_input_private_port(
248 struct bt_private_component
*private_component
,
249 const char *name
, void *user_data
,
250 struct bt_private_port
**user_priv_port
)
252 enum bt_component_status status
= BT_COMPONENT_STATUS_OK
;
253 struct bt_port
*port
= NULL
;
254 struct bt_component
*component
=
255 bt_component_borrow_from_private(private_component
);
256 struct bt_graph
*graph
;
259 BT_LOGW_STR("Invalid parameter: component is NULL.");
260 status
= BT_COMPONENT_STATUS_INVALID
;
264 if (component
->class->type
!= BT_COMPONENT_CLASS_TYPE_FILTER
) {
265 BT_LOGW("Invalid parameter: component's class is not a filter component class: "
266 "comp-addr=%p, comp-name=\"%s\", comp-class-type=%s",
267 component
, bt_component_get_name(component
),
268 bt_component_class_type_string(component
->class->type
));
269 status
= BT_COMPONENT_STATUS_INVALID
;
273 graph
= bt_component_borrow_graph(component
);
275 if (graph
&& bt_graph_is_canceled(graph
)) {
276 BT_LOGW("Cannot add input port to filter component: graph is canceled: "
277 "comp-addr=%p, comp-name=\"%s\", graph-addr=%p",
278 component
, bt_component_get_name(component
),
279 bt_component_borrow_graph(component
));
280 status
= BT_COMPONENT_STATUS_GRAPH_IS_CANCELED
;
284 /* bt_component_add_input_port() logs details/errors */
285 port
= bt_component_add_input_port(component
, name
, user_data
);
287 status
= BT_COMPONENT_STATUS_NOMEM
;
291 if (user_priv_port
) {
292 /* Move reference to user */
293 *user_priv_port
= bt_private_port_from_port(port
);
302 struct bt_private_port
*
303 bt_private_component_filter_get_output_private_port_by_index(
304 struct bt_private_component
*private_component
, uint64_t index
)
306 /* bt_component_filter_get_output_port_by_index() logs details/errors */
307 return bt_private_port_from_port(
308 bt_component_filter_get_output_port_by_index(
309 bt_component_borrow_from_private(private_component
), index
));
312 struct bt_private_port
*
313 bt_private_component_filter_get_output_private_port_by_name(
314 struct bt_private_component
*private_component
,
317 /* bt_component_filter_get_output_port_by_name() logs details/errors */
318 return bt_private_port_from_port(
319 bt_component_filter_get_output_port_by_name(
320 bt_component_borrow_from_private(private_component
), name
));
323 enum bt_component_status
bt_private_component_filter_add_output_private_port(
324 struct bt_private_component
*private_component
,
325 const char *name
, void *user_data
,
326 struct bt_private_port
**user_priv_port
)
328 enum bt_component_status status
= BT_COMPONENT_STATUS_OK
;
329 struct bt_port
*port
= NULL
;
330 struct bt_component
*component
=
331 bt_component_borrow_from_private(private_component
);
332 struct bt_graph
*graph
;
335 BT_LOGW_STR("Invalid parameter: component is NULL.");
336 status
= BT_COMPONENT_STATUS_INVALID
;
340 if (component
->class->type
!= BT_COMPONENT_CLASS_TYPE_FILTER
) {
341 BT_LOGW("Invalid parameter: component's class is not a filter component class: "
342 "comp-addr=%p, comp-name=\"%s\", comp-class-type=%s",
343 component
, bt_component_get_name(component
),
344 bt_component_class_type_string(component
->class->type
));
345 status
= BT_COMPONENT_STATUS_INVALID
;
349 graph
= bt_component_borrow_graph(component
);
351 if (graph
&& bt_graph_is_canceled(graph
)) {
352 BT_LOGW("Cannot add output port to filter component: graph is canceled: "
353 "comp-addr=%p, comp-name=\"%s\", graph-addr=%p",
354 component
, bt_component_get_name(component
),
355 bt_component_borrow_graph(component
));
356 status
= BT_COMPONENT_STATUS_GRAPH_IS_CANCELED
;
360 /* bt_component_add_output_port() logs details/errors */
361 port
= bt_component_add_output_port(component
, name
, user_data
);
363 status
= BT_COMPONENT_STATUS_NOMEM
;
367 if (user_priv_port
) {
368 /* Move reference to user */
369 *user_priv_port
= bt_private_port_from_port(port
);