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 #include <babeltrace/compiler.h>
30 #include <babeltrace/values.h>
31 #include <babeltrace/plugin/filter-internal.h>
32 #include <babeltrace/plugin/component-internal.h>
33 #include <babeltrace/plugin/notification/notification.h>
34 #include <babeltrace/plugin/notification/iterator-internal.h>
36 enum bt_component_status
bt_component_filter_set_iterator_init_cb(
37 struct bt_component
*component
,
38 bt_component_filter_init_iterator_cb init_iterator
)
40 struct bt_component_filter
*filter
;
41 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
43 if (component
->class->type
!= BT_COMPONENT_TYPE_FILTER
||
44 !component
->initializing
) {
45 ret
= BT_COMPONENT_STATUS_INVALID
;
49 filter
= container_of(component
, struct bt_component_filter
, parent
);
50 filter
->init_iterator
= init_iterator
;
55 enum bt_component_status
bt_component_filter_set_add_iterator_cb(
56 struct bt_component
*component
,
57 bt_component_filter_add_iterator_cb add_iterator
)
59 struct bt_component_filter
*filter
;
60 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
63 ret
= BT_COMPONENT_STATUS_INVALID
;
67 if (bt_component_get_type(component
) != BT_COMPONENT_TYPE_FILTER
) {
68 ret
= BT_COMPONENT_STATUS_UNSUPPORTED
;
72 if (!component
->initializing
) {
73 ret
= BT_COMPONENT_STATUS_INVALID
;
77 filter
= container_of(component
, struct bt_component_filter
, parent
);
78 filter
->add_iterator
= add_iterator
;
83 enum bt_component_status
bt_component_filter_set_minimum_input_count(
84 struct bt_component
*component
,
87 struct bt_component_filter
*filter
;
88 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
91 ret
= BT_COMPONENT_STATUS_INVALID
;
95 if (bt_component_get_type(component
) != BT_COMPONENT_TYPE_FILTER
) {
96 ret
= BT_COMPONENT_STATUS_UNSUPPORTED
;
100 if (!component
->initializing
) {
101 ret
= BT_COMPONENT_STATUS_INVALID
;
105 filter
= container_of(component
, struct bt_component_filter
, parent
);
106 filter
->input
.min_count
= minimum
;
111 enum bt_component_status
bt_component_filter_set_maximum_input_count(
112 struct bt_component
*component
,
113 unsigned int maximum
)
115 struct bt_component_filter
*filter
;
116 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
119 ret
= BT_COMPONENT_STATUS_INVALID
;
123 if (bt_component_get_type(component
) != BT_COMPONENT_TYPE_FILTER
) {
124 ret
= BT_COMPONENT_STATUS_UNSUPPORTED
;
128 if (!component
->initializing
) {
129 ret
= BT_COMPONENT_STATUS_INVALID
;
133 filter
= container_of(component
, struct bt_component_filter
, parent
);
134 filter
->input
.max_count
= maximum
;
139 enum bt_component_status
140 bt_component_filter_get_input_count(struct bt_component
*component
,
143 struct bt_component_filter
*filter
;
144 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
146 if (!component
|| !count
) {
147 ret
= BT_COMPONENT_STATUS_INVALID
;
151 if (bt_component_get_type(component
) != BT_COMPONENT_TYPE_FILTER
) {
152 ret
= BT_COMPONENT_STATUS_UNSUPPORTED
;
156 filter
= container_of(component
, struct bt_component_filter
, parent
);
157 *count
= (unsigned int) filter
->input
.iterators
->len
;
162 enum bt_component_status
163 bt_component_filter_get_input_iterator(struct bt_component
*component
,
164 unsigned int input
, struct bt_notification_iterator
**iterator
)
166 struct bt_component_filter
*filter
;
167 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
169 if (!component
|| !iterator
) {
170 ret
= BT_COMPONENT_STATUS_INVALID
;
174 if (bt_component_get_type(component
) != BT_COMPONENT_TYPE_FILTER
) {
175 ret
= BT_COMPONENT_STATUS_UNSUPPORTED
;
179 filter
= container_of(component
, struct bt_component_filter
, parent
);
180 if (input
>= (unsigned int) filter
->input
.iterators
->len
) {
181 ret
= BT_COMPONENT_STATUS_INVALID
;
185 *iterator
= bt_get(g_ptr_array_index(filter
->input
.iterators
, input
));
190 enum bt_component_status
bt_component_filter_add_iterator(
191 struct bt_component
*component
,
192 struct bt_notification_iterator
*iterator
)
194 struct bt_component_filter
*filter
;
195 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
197 if (!component
|| !iterator
) {
198 ret
= BT_COMPONENT_STATUS_INVALID
;
202 if (bt_component_get_type(component
) != BT_COMPONENT_TYPE_FILTER
) {
203 ret
= BT_COMPONENT_STATUS_UNSUPPORTED
;
207 filter
= container_of(component
, struct bt_component_filter
, parent
);
208 if (filter
->input
.iterators
->len
== filter
->input
.max_count
) {
209 ret
= BT_COMPONENT_STATUS_UNSUPPORTED
;
213 if (filter
->add_iterator
) {
214 ret
= filter
->add_iterator(component
, iterator
);
215 if (ret
!= BT_COMPONENT_STATUS_OK
) {
220 g_ptr_array_add(filter
->input
.iterators
, bt_get(iterator
));
225 struct bt_notification_iterator
*bt_component_filter_create_iterator(
226 struct bt_component
*component
)
228 return bt_component_create_iterator(component
);