lib: bt_packet_create(): accept previous packet to set properties
[babeltrace.git] / lib / graph / notification / event.c
index c31694a625adbc533f14d16096509e4435195a8b..6251979d266a20f845334277302a1ea18077e725 100644 (file)
@@ -84,6 +84,7 @@ struct bt_notification *bt_notification_event_create(
        struct bt_notification_event *notification = NULL;
        struct bt_event *event;
        struct bt_graph *graph;
+       int ret;
 
        BT_ASSERT_PRE_NON_NULL(notif_iter, "Notification iterator");
        BT_ASSERT_PRE_NON_NULL(event_class, "Event class");
@@ -103,6 +104,20 @@ struct bt_notification *bt_notification_event_create(
                goto error;
        }
 
+       /*
+        * Set packet's properties. This can fail so it happens before
+        * creating the notification below. We freeze it after we know
+        * this function succeeds.
+        */
+       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 error;
+               }
+       }
+
        /*
         * Create notification from pool _after_ we have everything
         * (in this case, a valid event object) so that we never have an
@@ -129,6 +144,8 @@ struct bt_notification *bt_notification_event_create(
 
        BT_ASSERT(!notification->event);
        notification->event = event;
+       bt_packet_set_is_frozen(packet, true);
+       bt_packet_validate_properties(packet);
        BT_LOGD("Created event notification object: "
                "event-addr=%p, event-class-addr=%p, "
                "event-class-name=\"%s\", event-class-id=%" PRId64 ", "
This page took 0.02421 seconds and 4 git commands to generate.