#include <babeltrace/babeltrace-internal.h>
#include <babeltrace/object-internal.h>
#include <babeltrace/ref-internal.h>
+#include <babeltrace/graph/connection.h>
#include <babeltrace/graph/notification.h>
#include <babeltrace/graph/notification-iterator.h>
#include <babeltrace/graph/private-notification-iterator.h>
+#include <babeltrace/types.h>
struct bt_port;
+enum bt_notification_iterator_notif_type {
+ BT_NOTIFICATION_ITERATOR_NOTIF_TYPE_EVENT = (1U << 0),
+ BT_NOTIFICATION_ITERATOR_NOTIF_TYPE_INACTIVITY = (1U << 1),
+ BT_NOTIFICATION_ITERATOR_NOTIF_TYPE_STREAM_BEGIN = (1U << 2),
+ BT_NOTIFICATION_ITERATOR_NOTIF_TYPE_STREAM_END = (1U << 3),
+ BT_NOTIFICATION_ITERATOR_NOTIF_TYPE_PACKET_BEGIN = (1U << 4),
+ BT_NOTIFICATION_ITERATOR_NOTIF_TYPE_PACKET_END = (1U << 5),
+};
+
+enum bt_notification_iterator_state {
+ /* Iterator is active, not at the end yet, and not finalized. */
+ BT_NOTIFICATION_ITERATOR_STATE_ACTIVE,
+
+ /*
+ * Iterator is ended, not finalized yet: the "next" method
+ * returns BT_NOTIFICATION_ITERATOR_STATUS_END.
+ */
+ BT_NOTIFICATION_ITERATOR_STATE_ENDED,
+
+ /*
+ * Iterator is finalized, but not at the end yet. This means
+ * that the "next" method can still return queued notifications
+ * before returning the BT_NOTIFICATION_ITERATOR_STATUS_CANCELED
+ * status.
+ */
+ BT_NOTIFICATION_ITERATOR_STATE_FINALIZED,
+
+ /*
+ * Iterator is finalized and ended: the "next" method always
+ * returns BT_NOTIFICATION_ITERATOR_STATUS_CANCELED.
+ */
+ BT_NOTIFICATION_ITERATOR_STATE_FINALIZED_AND_ENDED,
+};
+
struct bt_notification_iterator {
struct bt_object base;
- struct bt_component *upstream_component; /* owned by this */
- struct bt_port *upstream_port; /* owned by this */
+ struct bt_component *upstream_component; /* Weak */
+ struct bt_port *upstream_port; /* Weak */
+ struct bt_connection *connection; /* Weak */
struct bt_notification *current_notification; /* owned by this */
GQueue *queue; /* struct bt_notification * (owned by this) */
*/
GArray *actions;
- bool is_ended;
+ /*
+ * This is a mask of notifications to which the user of this
+ * iterator is subscribed
+ * (see enum bt_notification_iterator_notif_type above).
+ */
+ uint32_t subscription_mask;
+
+ enum bt_notification_iterator_state state;
void *user_data;
};
return (void *) notification_iterator;
}
-/**
- * Allocate a notification iterator.
- *
- * @param component Component instance
- * @returns A notification iterator instance
- */
BT_HIDDEN
-struct bt_notification_iterator *bt_notification_iterator_create(
- struct bt_component *upstream_component,
- struct bt_port *upstream_port);
+enum bt_connection_status bt_notification_iterator_create(
+ struct bt_component *upstream_comp,
+ struct bt_port *upstream_port,
+ const enum bt_notification_type *notification_types,
+ struct bt_connection *connection,
+ struct bt_notification_iterator **iterator);
-/**
- * Validate a notification iterator.
- *
- * @param iterator Notification iterator instance
- * @returns One of #bt_component_status values
- */
BT_HIDDEN
-enum bt_notification_iterator_status bt_notification_iterator_validate(
+void bt_notification_iterator_finalize(
struct bt_notification_iterator *iterator);
+BT_HIDDEN
+void bt_notification_iterator_set_connection(
+ struct bt_notification_iterator *iterator,
+ struct bt_connection *connection);
+
+static inline
+const char *bt_notification_iterator_status_string(
+ enum bt_notification_iterator_status status)
+{
+ switch (status) {
+ case BT_NOTIFICATION_ITERATOR_STATUS_CANCELED:
+ return "BT_NOTIFICATION_ITERATOR_STATUS_CANCELED";
+ case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN:
+ return "BT_NOTIFICATION_ITERATOR_STATUS_AGAIN";
+ case BT_NOTIFICATION_ITERATOR_STATUS_END:
+ return "BT_NOTIFICATION_ITERATOR_STATUS_END";
+ case BT_NOTIFICATION_ITERATOR_STATUS_OK:
+ return "BT_NOTIFICATION_ITERATOR_STATUS_OK";
+ case BT_NOTIFICATION_ITERATOR_STATUS_INVALID:
+ return "BT_NOTIFICATION_ITERATOR_STATUS_INVALID";
+ case BT_NOTIFICATION_ITERATOR_STATUS_ERROR:
+ return "BT_NOTIFICATION_ITERATOR_STATUS_ERROR";
+ case BT_NOTIFICATION_ITERATOR_STATUS_NOMEM:
+ return "BT_NOTIFICATION_ITERATOR_STATUS_NOMEM";
+ case BT_NOTIFICATION_ITERATOR_STATUS_UNSUPPORTED:
+ return "BT_NOTIFICATION_ITERATOR_STATUS_UNSUPPORTED";
+ default:
+ return "(unknown)";
+ }
+};
+
+static inline
+const char *bt_notification_iterator_state_string(
+ enum bt_notification_iterator_state state)
+{
+ switch (state) {
+ case BT_NOTIFICATION_ITERATOR_STATE_ACTIVE:
+ return "BT_NOTIFICATION_ITERATOR_STATE_ACTIVE";
+ case BT_NOTIFICATION_ITERATOR_STATE_ENDED:
+ return "BT_NOTIFICATION_ITERATOR_STATE_ENDED";
+ case BT_NOTIFICATION_ITERATOR_STATE_FINALIZED:
+ return "BT_NOTIFICATION_ITERATOR_STATE_FINALIZED";
+ case BT_NOTIFICATION_ITERATOR_STATE_FINALIZED_AND_ENDED:
+ return "BT_NOTIFICATION_ITERATOR_STATE_FINALIZED_AND_ENDED";
+ default:
+ return "(unknown)";
+ }
+};
+
#endif /* BABELTRACE_COMPONENT_NOTIFICATION_ITERATOR_INTERNAL_H */