4 * Babeltrace Notification Iterator
6 * Copyright 2015 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-internal.h>
30 #include <babeltrace/ref.h>
31 #include <babeltrace/graph/component.h>
32 #include <babeltrace/graph/component-source-internal.h>
33 #include <babeltrace/graph/component-class-internal.h>
34 #include <babeltrace/graph/notification-iterator.h>
35 #include <babeltrace/graph/notification-iterator-internal.h>
36 #include <babeltrace/graph/notification-internal.h>
39 void bt_notification_iterator_destroy(struct bt_object
*obj
)
41 struct bt_notification_iterator
*iterator
;
42 struct bt_component_class
*comp_class
;
45 iterator
= container_of(obj
, struct bt_notification_iterator
,
47 assert(iterator
->component
);
48 comp_class
= iterator
->component
->class;
50 /* Call user-defined destroy method */
51 switch (comp_class
->type
) {
52 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
54 struct bt_component_class_source
*source_class
;
56 source_class
= container_of(comp_class
, struct bt_component_class_source
, parent
);
58 if (source_class
->methods
.iterator
.finalize
) {
59 source_class
->methods
.iterator
.finalize(
60 bt_private_notification_iterator_from_notification_iterator(iterator
));
64 case BT_COMPONENT_CLASS_TYPE_FILTER
:
66 struct bt_component_class_filter
*filter_class
;
68 filter_class
= container_of(comp_class
, struct bt_component_class_filter
, parent
);
70 if (filter_class
->methods
.iterator
.finalize
) {
71 filter_class
->methods
.iterator
.finalize(
72 bt_private_notification_iterator_from_notification_iterator(iterator
));
81 BT_PUT(iterator
->current_notification
);
82 BT_PUT(iterator
->component
);
87 struct bt_notification_iterator
*bt_notification_iterator_create(
88 struct bt_component
*component
)
90 enum bt_component_class_type type
;
91 struct bt_notification_iterator
*iterator
= NULL
;
97 type
= bt_component_get_class_type(component
);
99 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
100 case BT_COMPONENT_CLASS_TYPE_FILTER
:
106 iterator
= g_new0(struct bt_notification_iterator
, 1);
111 iterator
->component
= bt_get(component
);
112 bt_object_init(iterator
, bt_notification_iterator_destroy
);
118 enum bt_notification_iterator_status
bt_notification_iterator_validate(
119 struct bt_notification_iterator
*iterator
)
121 enum bt_notification_iterator_status ret
=
122 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
125 ret
= BT_NOTIFICATION_ITERATOR_STATUS_INVALID
;
132 void *bt_private_notification_iterator_get_user_data(
133 struct bt_private_notification_iterator
*private_iterator
)
135 struct bt_notification_iterator
*iterator
=
136 bt_notification_iterator_from_private(private_iterator
);
138 return iterator
? iterator
->user_data
: NULL
;
141 enum bt_notification_iterator_status
142 bt_private_notification_iterator_set_user_data(
143 struct bt_private_notification_iterator
*private_iterator
,
146 enum bt_notification_iterator_status ret
=
147 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
148 struct bt_notification_iterator
*iterator
=
149 bt_notification_iterator_from_private(private_iterator
);
152 ret
= BT_NOTIFICATION_ITERATOR_STATUS_INVALID
;
156 iterator
->user_data
= data
;
161 struct bt_notification
*bt_notification_iterator_get_notification(
162 struct bt_notification_iterator
*iterator
)
164 struct bt_notification
*notification
= NULL
;
170 notification
= bt_get(iterator
->current_notification
);
176 enum bt_notification_iterator_status
177 bt_notification_iterator_next(struct bt_notification_iterator
*iterator
)
179 struct bt_private_notification_iterator
*priv_iterator
=
180 bt_private_notification_iterator_from_notification_iterator(iterator
);
181 bt_component_class_notification_iterator_next_method next_method
= NULL
;
182 struct bt_notification_iterator_next_return next_return
= {
183 .status
= BT_NOTIFICATION_ITERATOR_STATUS_OK
,
184 .notification
= NULL
,
188 next_return
.status
= BT_NOTIFICATION_ITERATOR_STATUS_INVALID
;
192 assert(iterator
->component
);
193 assert(iterator
->component
->class);
195 switch (iterator
->component
->class->type
) {
196 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
198 struct bt_component_class_source
*source_class
=
199 container_of(iterator
->component
->class,
200 struct bt_component_class_source
, parent
);
202 assert(source_class
->methods
.iterator
.next
);
203 next_method
= source_class
->methods
.iterator
.next
;
206 case BT_COMPONENT_CLASS_TYPE_FILTER
:
208 struct bt_component_class_filter
*filter_class
=
209 container_of(iterator
->component
->class,
210 struct bt_component_class_filter
, parent
);
212 assert(filter_class
->methods
.iterator
.next
);
213 next_method
= filter_class
->methods
.iterator
.next
;
222 next_return
= next_method(priv_iterator
);
223 if (next_return
.status
== BT_NOTIFICATION_ITERATOR_STATUS_OK
) {
224 if (!next_return
.notification
) {
226 BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
230 BT_MOVE(iterator
->current_notification
,
231 next_return
.notification
);
232 bt_notification_freeze(iterator
->current_notification
);
236 return next_return
.status
;
239 struct bt_component
*bt_notification_iterator_get_component(
240 struct bt_notification_iterator
*iterator
)
242 return bt_get(iterator
->component
);
245 struct bt_private_component
*
246 bt_private_notification_iterator_get_private_component(
247 struct bt_private_notification_iterator
*private_iterator
)
249 return bt_private_component_from_component(
250 bt_notification_iterator_get_component(
251 bt_notification_iterator_from_private(private_iterator
)));
254 enum bt_notification_iterator_status
bt_notification_iterator_seek_time(
255 struct bt_notification_iterator
*iterator
,
256 enum bt_notification_iterator_seek_origin seek_origin
,
259 enum bt_notification_iterator_status ret
=
260 BT_NOTIFICATION_ITERATOR_STATUS_UNSUPPORTED
;