lib: bt_packet_create(): accept previous packet to set properties
[babeltrace.git] / lib / graph / notification / packet.c
index c5c6a6e5afff3e1b3f7da70e8302e909960268e9..552a99f1b1c6ec34c131092f2cfa264d06bcfab9 100644 (file)
@@ -69,10 +69,11 @@ struct bt_notification *bt_notification_packet_begin_create(
                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;
+       int ret;
 
        BT_ASSERT_PRE_NON_NULL(notif_iter, "Notification iterator");
        BT_ASSERT_PRE_NON_NULL(packet, "Packet");
@@ -88,6 +89,16 @@ struct bt_notification *bt_notification_packet_begin_create(
                stream_class,
                bt_stream_class_get_name(stream_class),
                bt_stream_class_get_id(stream_class));
+
+       if (likely(!packet->props_are_set)) {
+               ret = bt_packet_set_properties(packet);
+               if (ret) {
+                       BT_LIB_LOGE("Cannot update packet's properties: "
+                               "%![prev-packet-]+a", packet);
+                       goto end;
+               }
+       }
+
        graph = bt_private_connection_private_notification_iterator_borrow_graph(
                notif_iter);
        notification = (void *) bt_notification_create_from_pool(
@@ -101,6 +112,8 @@ struct bt_notification *bt_notification_packet_begin_create(
        notification->packet = packet;
        bt_object_get_no_null_check_no_parent_check(
                &notification->packet->base);
+       bt_packet_set_is_frozen(packet, true);
+       bt_packet_validate_properties(packet);
        BT_LOGD("Created packet beginning notification object: "
                "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", "
                "stream-class-addr=%p, stream-class-name=\"%s\", "
@@ -189,10 +202,11 @@ struct bt_notification *bt_notification_packet_end_create(
                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;
+       int ret;
 
        BT_ASSERT_PRE_NON_NULL(notif_iter, "Notification iterator");
        BT_ASSERT_PRE_NON_NULL(packet, "Packet");
@@ -208,6 +222,16 @@ struct bt_notification *bt_notification_packet_end_create(
                stream_class,
                bt_stream_class_get_name(stream_class),
                bt_stream_class_get_id(stream_class));
+
+       if (unlikely(!packet->props_are_set)) {
+               ret = bt_packet_set_properties(packet);
+               if (ret) {
+                       BT_LIB_LOGE("Cannot update packet's properties: "
+                               "%![prev-packet-]+a", packet);
+                       goto end;
+               }
+       }
+
        graph = bt_private_connection_private_notification_iterator_borrow_graph(
                notif_iter);
        notification = (void *) bt_notification_create_from_pool(
@@ -221,6 +245,8 @@ struct bt_notification *bt_notification_packet_end_create(
        notification->packet = packet;
        bt_object_get_no_null_check_no_parent_check(
                &notification->packet->base);
+       bt_packet_set_is_frozen(packet, true);
+       bt_packet_validate_properties(packet);
        BT_LOGD("Created packet end notification object: "
                "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", "
                "stream-class-addr=%p, stream-class-name=\"%s\", "
This page took 0.023565 seconds and 4 git commands to generate.