1 #ifndef BABELTRACE_COMPONENT_NOTIFICATION_ITERATOR_INTERNAL_H
2 #define BABELTRACE_COMPONENT_NOTIFICATION_ITERATOR_INTERNAL_H
5 * BabelTrace - Notification Iterator Internal
7 * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 * Copyright 2017 Philippe Proulx <pproulx@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/babeltrace-internal.h>
30 #include <babeltrace/object-internal.h>
31 #include <babeltrace/ref-internal.h>
32 #include <babeltrace/graph/connection.h>
33 #include <babeltrace/graph/notification.h>
34 #include <babeltrace/graph/notification-iterator.h>
35 #include <babeltrace/graph/private-notification-iterator.h>
36 #include <babeltrace/types.h>
41 enum bt_notification_iterator_notif_type
{
42 BT_NOTIFICATION_ITERATOR_NOTIF_TYPE_EVENT
= (1U << 0),
43 BT_NOTIFICATION_ITERATOR_NOTIF_TYPE_INACTIVITY
= (1U << 1),
44 BT_NOTIFICATION_ITERATOR_NOTIF_TYPE_STREAM_BEGIN
= (1U << 2),
45 BT_NOTIFICATION_ITERATOR_NOTIF_TYPE_STREAM_END
= (1U << 3),
46 BT_NOTIFICATION_ITERATOR_NOTIF_TYPE_PACKET_BEGIN
= (1U << 4),
47 BT_NOTIFICATION_ITERATOR_NOTIF_TYPE_PACKET_END
= (1U << 5),
48 BT_NOTIFICATION_ITERATOR_NOTIF_TYPE_DISCARDED_EVENTS
= (1U << 6),
49 BT_NOTIFICATION_ITERATOR_NOTIF_TYPE_DISCARDED_PACKETS
= (1U << 7),
52 enum bt_notification_iterator_state
{
53 /* Iterator is not initialized. */
54 BT_NOTIFICATION_ITERATOR_STATE_NON_INITIALIZED
,
56 /* Iterator is active, not at the end yet, and not finalized. */
57 BT_NOTIFICATION_ITERATOR_STATE_ACTIVE
,
60 * Iterator is ended, not finalized yet: the "next" method
61 * returns BT_NOTIFICATION_ITERATOR_STATUS_END.
63 BT_NOTIFICATION_ITERATOR_STATE_ENDED
,
66 * Iterator is finalized, but not at the end yet. This means
67 * that the "next" method can still return queued notifications
68 * before returning the BT_NOTIFICATION_ITERATOR_STATUS_CANCELED
71 BT_NOTIFICATION_ITERATOR_STATE_FINALIZED
,
74 * Iterator is finalized and ended: the "next" method always
75 * returns BT_NOTIFICATION_ITERATOR_STATUS_CANCELED.
77 BT_NOTIFICATION_ITERATOR_STATE_FINALIZED_AND_ENDED
,
80 struct bt_notification_iterator
{
81 struct bt_object base
;
82 struct bt_component
*upstream_component
; /* Weak */
83 struct bt_port
*upstream_port
; /* Weak */
84 struct bt_connection
*connection
; /* Weak */
85 struct bt_notification
*current_notification
; /* owned by this */
86 GQueue
*queue
; /* struct bt_notification * (owned by this) */
89 * This hash table keeps the state of a stream as viewed by
90 * this notification iterator. This is used to:
92 * * Automatically enqueue "stream begin", "packet begin",
93 * "packet end", and "stream end" notifications depending
94 * on the stream's state and on the next notification returned
95 * by the upstream component.
97 * * Make sure that, once the notification iterator has seen
98 * a "stream end" notification for a given stream, that no
99 * other notifications which refer to this stream can be
100 * delivered by this iterator.
102 * The key (struct bt_ctf_stream *) is not owned by this. The
103 * value is an allocated state structure.
105 GHashTable
*stream_states
;
108 * This is an array of actions which can be rolled back. It's
109 * similar to the memento pattern, but it's not exactly that. It
110 * is allocated once and reset for each notification to process.
111 * More details near the implementation.
116 * This is a mask of notifications to which the user of this
117 * iterator is subscribed
118 * (see enum bt_notification_iterator_notif_type above).
120 uint32_t subscription_mask
;
122 enum bt_notification_iterator_state state
;
127 struct bt_notification_iterator
*bt_notification_iterator_from_private(
128 struct bt_private_notification_iterator
*private_notification_iterator
)
130 return (void *) private_notification_iterator
;
134 struct bt_private_notification_iterator
*
135 bt_private_notification_iterator_from_notification_iterator(
136 struct bt_notification_iterator
*notification_iterator
)
138 return (void *) notification_iterator
;
142 enum bt_connection_status
bt_notification_iterator_create(
143 struct bt_component
*upstream_comp
,
144 struct bt_port
*upstream_port
,
145 const enum bt_notification_type
*notification_types
,
146 struct bt_connection
*connection
,
147 struct bt_notification_iterator
**iterator
);
150 void bt_notification_iterator_finalize(
151 struct bt_notification_iterator
*iterator
);
154 void bt_notification_iterator_set_connection(
155 struct bt_notification_iterator
*iterator
,
156 struct bt_connection
*connection
);
159 const char *bt_notification_iterator_status_string(
160 enum bt_notification_iterator_status status
)
163 case BT_NOTIFICATION_ITERATOR_STATUS_CANCELED
:
164 return "BT_NOTIFICATION_ITERATOR_STATUS_CANCELED";
165 case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN
:
166 return "BT_NOTIFICATION_ITERATOR_STATUS_AGAIN";
167 case BT_NOTIFICATION_ITERATOR_STATUS_END
:
168 return "BT_NOTIFICATION_ITERATOR_STATUS_END";
169 case BT_NOTIFICATION_ITERATOR_STATUS_OK
:
170 return "BT_NOTIFICATION_ITERATOR_STATUS_OK";
171 case BT_NOTIFICATION_ITERATOR_STATUS_INVALID
:
172 return "BT_NOTIFICATION_ITERATOR_STATUS_INVALID";
173 case BT_NOTIFICATION_ITERATOR_STATUS_ERROR
:
174 return "BT_NOTIFICATION_ITERATOR_STATUS_ERROR";
175 case BT_NOTIFICATION_ITERATOR_STATUS_NOMEM
:
176 return "BT_NOTIFICATION_ITERATOR_STATUS_NOMEM";
177 case BT_NOTIFICATION_ITERATOR_STATUS_UNSUPPORTED
:
178 return "BT_NOTIFICATION_ITERATOR_STATUS_UNSUPPORTED";
185 const char *bt_notification_iterator_state_string(
186 enum bt_notification_iterator_state state
)
189 case BT_NOTIFICATION_ITERATOR_STATE_ACTIVE
:
190 return "BT_NOTIFICATION_ITERATOR_STATE_ACTIVE";
191 case BT_NOTIFICATION_ITERATOR_STATE_ENDED
:
192 return "BT_NOTIFICATION_ITERATOR_STATE_ENDED";
193 case BT_NOTIFICATION_ITERATOR_STATE_FINALIZED
:
194 return "BT_NOTIFICATION_ITERATOR_STATE_FINALIZED";
195 case BT_NOTIFICATION_ITERATOR_STATE_FINALIZED_AND_ENDED
:
196 return "BT_NOTIFICATION_ITERATOR_STATE_FINALIZED_AND_ENDED";
202 #endif /* BABELTRACE_COMPONENT_NOTIFICATION_ITERATOR_INTERNAL_H */