Notification iterator: generate automatic notifications when missing
[babeltrace.git] / lib / graph / notification / stream.c
index 68b9bcdb8b193e2c46375b51f5a29375c8e6ca06..68b999c0c6e0d36c7c02d0eea5f8b58656684b17 100644 (file)
@@ -25,6 +25,7 @@
  */
 
 #include <babeltrace/compiler-internal.h>
+#include <babeltrace/ctf-ir/stream-internal.h>
 #include <babeltrace/graph/notification-stream-internal.h>
 
 static
@@ -42,7 +43,7 @@ struct bt_notification *bt_notification_stream_end_create(
 {
        struct bt_notification_stream_end *notification;
 
-       if (!stream) {
+       if (!stream || stream->pos.fd >= 0) {
                goto error;
        }
 
@@ -65,3 +66,42 @@ struct bt_ctf_packet *bt_notification_stream_end_get_stream(
                        struct bt_notification_stream_end, parent);
        return bt_get(stream_end->stream);
 }
+
+static
+void bt_notification_stream_begin_destroy(struct bt_object *obj)
+{
+       struct bt_notification_stream_begin *notification =
+                       (struct bt_notification_stream_begin *) obj;
+
+       BT_PUT(notification->stream);
+       g_free(notification);
+}
+
+struct bt_notification *bt_notification_stream_begin_create(
+               struct bt_ctf_stream *stream)
+{
+       struct bt_notification_stream_begin *notification;
+
+       if (!stream || stream->pos.fd >= 0) {
+               goto error;
+       }
+
+       notification = g_new0(struct bt_notification_stream_begin, 1);
+       bt_notification_init(&notification->parent,
+                       BT_NOTIFICATION_TYPE_STREAM_BEGIN,
+                       bt_notification_stream_begin_destroy);
+       notification->stream = bt_get(stream);
+       return &notification->parent;
+error:
+       return NULL;
+}
+
+struct bt_ctf_packet *bt_notification_stream_begin_get_stream(
+               struct bt_notification *notification)
+{
+       struct bt_notification_stream_begin *stream_begin;
+
+       stream_begin = container_of(notification,
+                       struct bt_notification_stream_begin, parent);
+       return bt_get(stream_begin->stream);
+}
This page took 0.025899 seconds and 4 git commands to generate.