| 1 | #ifndef BABELTRACE_COMPONENT_NOTIFICATION_ITERATOR_INTERNAL_H |
| 2 | #define BABELTRACE_COMPONENT_NOTIFICATION_ITERATOR_INTERNAL_H |
| 3 | |
| 4 | /* |
| 5 | * BabelTrace - Notification Iterator Internal |
| 6 | * |
| 7 | * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
| 8 | * Copyright 2017 Philippe Proulx <pproulx@efficios.com> |
| 9 | * |
| 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: |
| 16 | * |
| 17 | * The above copyright notice and this permission notice shall be included in |
| 18 | * all copies or substantial portions of the Software. |
| 19 | * |
| 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 |
| 26 | * SOFTWARE. |
| 27 | */ |
| 28 | |
| 29 | #include <babeltrace/babeltrace-internal.h> |
| 30 | #include <babeltrace/object-internal.h> |
| 31 | #include <babeltrace/ref-internal.h> |
| 32 | #include <babeltrace/graph/notification.h> |
| 33 | #include <babeltrace/graph/notification-iterator.h> |
| 34 | #include <babeltrace/graph/private-notification-iterator.h> |
| 35 | |
| 36 | struct bt_port; |
| 37 | |
| 38 | enum bt_notification_iterator_notif_type { |
| 39 | BT_NOTIFICATION_ITERATOR_NOTIF_TYPE_EVENT = (1U << 0), |
| 40 | BT_NOTIFICATION_ITERATOR_NOTIF_TYPE_INACTIVITY = (1U << 1), |
| 41 | BT_NOTIFICATION_ITERATOR_NOTIF_TYPE_STREAM_BEGIN = (1U << 2), |
| 42 | BT_NOTIFICATION_ITERATOR_NOTIF_TYPE_STREAM_END = (1U << 3), |
| 43 | BT_NOTIFICATION_ITERATOR_NOTIF_TYPE_PACKET_BEGIN = (1U << 4), |
| 44 | BT_NOTIFICATION_ITERATOR_NOTIF_TYPE_PACKET_END = (1U << 5), |
| 45 | }; |
| 46 | |
| 47 | struct bt_notification_iterator { |
| 48 | struct bt_object base; |
| 49 | struct bt_component *upstream_component; /* owned by this */ |
| 50 | struct bt_port *upstream_port; /* owned by this */ |
| 51 | struct bt_notification *current_notification; /* owned by this */ |
| 52 | GQueue *queue; /* struct bt_notification * (owned by this) */ |
| 53 | |
| 54 | /* |
| 55 | * This hash table keeps the state of a stream as viewed by |
| 56 | * this notification iterator. This is used to: |
| 57 | * |
| 58 | * * Automatically enqueue "stream begin", "packet begin", |
| 59 | * "packet end", and "stream end" notifications depending |
| 60 | * on the stream's state and on the next notification returned |
| 61 | * by the upstream component. |
| 62 | * |
| 63 | * * Make sure that, once the notification iterator has seen |
| 64 | * a "stream end" notification for a given stream, that no |
| 65 | * other notifications which refer to this stream can be |
| 66 | * delivered by this iterator. |
| 67 | * |
| 68 | * The key (struct bt_ctf_stream *) is not owned by this. The |
| 69 | * value is an allocated state structure. |
| 70 | */ |
| 71 | GHashTable *stream_states; |
| 72 | |
| 73 | /* |
| 74 | * This is an array of actions which can be rolled back. It's |
| 75 | * similar to the memento pattern, but it's not exactly that. It |
| 76 | * is allocated once and reset for each notification to process. |
| 77 | * More details near the implementation. |
| 78 | */ |
| 79 | GArray *actions; |
| 80 | |
| 81 | /* |
| 82 | * This is a mask of notifications to which the user of this |
| 83 | * iterator is subscribed |
| 84 | * (see enum bt_notification_iterator_notif_type above). |
| 85 | */ |
| 86 | uint32_t subscription_mask; |
| 87 | |
| 88 | bool is_ended; |
| 89 | void *user_data; |
| 90 | }; |
| 91 | |
| 92 | static inline |
| 93 | struct bt_notification_iterator *bt_notification_iterator_from_private( |
| 94 | struct bt_private_notification_iterator *private_notification_iterator) |
| 95 | { |
| 96 | return (void *) private_notification_iterator; |
| 97 | } |
| 98 | |
| 99 | static inline |
| 100 | struct bt_private_notification_iterator * |
| 101 | bt_private_notification_iterator_from_notification_iterator( |
| 102 | struct bt_notification_iterator *notification_iterator) |
| 103 | { |
| 104 | return (void *) notification_iterator; |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Allocate a notification iterator. |
| 109 | * |
| 110 | * @param component Component instance |
| 111 | * @returns A notification iterator instance |
| 112 | */ |
| 113 | BT_HIDDEN |
| 114 | struct bt_notification_iterator *bt_notification_iterator_create( |
| 115 | struct bt_component *upstream_component, |
| 116 | struct bt_port *upstream_port, |
| 117 | const enum bt_notification_type *notification_types); |
| 118 | |
| 119 | /** |
| 120 | * Validate a notification iterator. |
| 121 | * |
| 122 | * @param iterator Notification iterator instance |
| 123 | * @returns One of #bt_component_status values |
| 124 | */ |
| 125 | BT_HIDDEN |
| 126 | enum bt_notification_iterator_status bt_notification_iterator_validate( |
| 127 | struct bt_notification_iterator *iterator); |
| 128 | |
| 129 | #endif /* BABELTRACE_COMPONENT_NOTIFICATION_ITERATOR_INTERNAL_H */ |