Make API CTF-agnostic
[babeltrace.git] / lib / graph / notification / packet.c
index 17b00d463ee42a6c5341f25a98b3ffea0800cc61..70694e963bbfcc8645f236cafcaa2d309fe09c4a 100644 (file)
 #include <babeltrace/ctf-ir/stream-internal.h>
 #include <babeltrace/graph/graph-internal.h>
 #include <babeltrace/graph/notification-packet-internal.h>
+#include <babeltrace/graph/private-connection-private-notification-iterator.h>
 #include <babeltrace/assert-internal.h>
 #include <babeltrace/assert-pre-internal.h>
+#include <babeltrace/object-internal.h>
 #include <inttypes.h>
 
 BT_HIDDEN
@@ -64,12 +66,15 @@ end:
 }
 
 struct bt_notification *bt_notification_packet_begin_create(
-               struct bt_graph *graph, struct bt_packet *packet)
+               struct bt_private_connection_private_notification_iterator *notif_iter,
+               struct bt_packet *packet)
 {
-       struct bt_notification_packet_begin *notification;
+       struct bt_notification_packet_begin *notification = NULL;
        struct bt_stream *stream;
        struct bt_stream_class *stream_class;
+       struct bt_graph *graph;
 
+       BT_ASSERT_PRE_NON_NULL(notif_iter, "Notification iterator");
        BT_ASSERT_PRE_NON_NULL(packet, "Packet");
        stream = bt_packet_borrow_stream(packet);
        BT_ASSERT(stream);
@@ -83,14 +88,20 @@ struct bt_notification *bt_notification_packet_begin_create(
                stream_class,
                bt_stream_class_get_name(stream_class),
                bt_stream_class_get_id(stream_class));
+       graph = bt_private_connection_private_notification_iterator_borrow_graph(
+               notif_iter);
        notification = (void *) bt_notification_create_from_pool(
                &graph->packet_begin_notif_pool, graph);
        if (!notification) {
                /* bt_notification_create_from_pool() logs errors */
-               goto error;
+               goto end;
        }
 
-       notification->packet = bt_get(packet);
+       BT_ASSERT(!notification->packet);
+       notification->packet = packet;
+       bt_object_get_no_null_check_no_parent_check(
+               &notification->packet->base);
+       bt_packet_set_is_frozen(packet, true);
        BT_LOGD("Created packet beginning notification object: "
                "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", "
                "stream-class-addr=%p, stream-class-name=\"%s\", "
@@ -101,9 +112,6 @@ struct bt_notification *bt_notification_packet_begin_create(
                bt_stream_class_get_id(stream_class), notification);
        goto end;
 
-error:
-       BT_PUT(notification);
-
 end:
        return (void *) notification;
 }
@@ -127,14 +135,15 @@ void bt_notification_packet_begin_recycle(struct bt_notification *notif)
 
        BT_ASSERT(packet_begin_notif);
 
-       if (!notif->graph) {
+       if (unlikely(!notif->graph)) {
                bt_notification_packet_begin_destroy(notif);
                return;
        }
 
        BT_LOGD("Recycling packet beginning notification: addr=%p", notif);
        bt_notification_reset(notif);
-       BT_PUT(packet_begin_notif->packet);
+       bt_object_put_no_null_check(&packet_begin_notif->packet->base);
+       packet_begin_notif->packet = NULL;
        graph = notif->graph;
        notif->graph = NULL;
        bt_object_pool_recycle_object(&graph->packet_begin_notif_pool, notif);
@@ -178,12 +187,15 @@ end:
 }
 
 struct bt_notification *bt_notification_packet_end_create(
-               struct bt_graph *graph, struct bt_packet *packet)
+               struct bt_private_connection_private_notification_iterator *notif_iter,
+               struct bt_packet *packet)
 {
-       struct bt_notification_packet_end *notification;
+       struct bt_notification_packet_end *notification = NULL;
        struct bt_stream *stream;
        struct bt_stream_class *stream_class;
+       struct bt_graph *graph;
 
+       BT_ASSERT_PRE_NON_NULL(notif_iter, "Notification iterator");
        BT_ASSERT_PRE_NON_NULL(packet, "Packet");
        stream = bt_packet_borrow_stream(packet);
        BT_ASSERT(stream);
@@ -197,14 +209,20 @@ struct bt_notification *bt_notification_packet_end_create(
                stream_class,
                bt_stream_class_get_name(stream_class),
                bt_stream_class_get_id(stream_class));
+       graph = bt_private_connection_private_notification_iterator_borrow_graph(
+               notif_iter);
        notification = (void *) bt_notification_create_from_pool(
                &graph->packet_end_notif_pool, graph);
        if (!notification) {
                /* bt_notification_create_from_pool() logs errors */
-               goto error;
+               goto end;
        }
 
-       notification->packet = bt_get(packet);
+       BT_ASSERT(!notification->packet);
+       notification->packet = packet;
+       bt_object_get_no_null_check_no_parent_check(
+               &notification->packet->base);
+       bt_packet_set_is_frozen(packet, true);
        BT_LOGD("Created packet end notification object: "
                "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", "
                "stream-class-addr=%p, stream-class-name=\"%s\", "
@@ -215,9 +233,6 @@ struct bt_notification *bt_notification_packet_end_create(
                bt_stream_class_get_id(stream_class), notification);
        goto end;
 
-error:
-       BT_PUT(notification);
-
 end:
        return (void *) notification;
 }
This page took 0.026209 seconds and 4 git commands to generate.