tests: build system spring cleanup
[babeltrace.git] / lib / graph / message / packet.c
index a61999aedc16ec39354b697f3d8afcc6e9fac665..df3e0e993cbf8dd67a1e4306ff6ac39e1fb8c248 100644 (file)
@@ -82,11 +82,12 @@ static inline
 struct bt_message *create_packet_message(
                struct bt_self_component_port_input_message_iterator *msg_iter,
                struct bt_packet *packet, struct bt_object_pool *pool,
-               bool with_cs, uint64_t raw_value)
+               bool with_cs, bool is_beginning, uint64_t raw_value)
 {
        struct bt_message_packet *message = NULL;
        struct bt_stream *stream;
        struct bt_stream_class *stream_class;
+       bool packet_has_default_clock_snapshot;
 
        BT_ASSERT(msg_iter);
        BT_ASSERT_PRE_NON_NULL(packet, "Packet");
@@ -94,8 +95,21 @@ struct bt_message *create_packet_message(
        BT_ASSERT(stream);
        stream_class = bt_stream_borrow_class(stream);
        BT_ASSERT(stream_class);
-       BT_ASSERT_PRE((with_cs && stream_class->default_clock_class) ||
-               (!with_cs && !stream_class->default_clock_class),
+
+       if (is_beginning) {
+               packet_has_default_clock_snapshot =
+                       stream_class->packets_have_default_beginning_clock_snapshot;
+       } else {
+               packet_has_default_clock_snapshot =
+                       stream_class->packets_have_default_end_clock_snapshot;
+       }
+
+       /*
+        * `packet_has_default_clock_snapshot` implies that the stream
+        * class has a default clock class (precondition).
+        */
+       BT_ASSERT_PRE((with_cs && packet_has_default_clock_snapshot) ||
+               (!with_cs && !packet_has_default_clock_snapshot),
                "Creating a packet message with a default clock snapshot, but without "
                "a default clock class, or without a default clock snapshot, "
                "but with a default clock class: ",
@@ -147,7 +161,7 @@ struct bt_message *bt_message_packet_beginning_create(
 
        BT_ASSERT_PRE_NON_NULL(msg_iter, "Message iterator");
        return create_packet_message(msg_iter, (void *) packet,
-               &msg_iter->graph->packet_begin_msg_pool, false, 0);
+               &msg_iter->graph->packet_begin_msg_pool, false, true, 0);
 }
 
 struct bt_message *bt_message_packet_beginning_create_with_default_clock_snapshot(
@@ -159,7 +173,7 @@ struct bt_message *bt_message_packet_beginning_create_with_default_clock_snapsho
 
        BT_ASSERT_PRE_NON_NULL(msg_iter, "Message iterator");
        return create_packet_message(msg_iter, (void *) packet,
-               &msg_iter->graph->packet_begin_msg_pool, true, raw_value);
+               &msg_iter->graph->packet_begin_msg_pool, true, true, raw_value);
 }
 
 struct bt_message *bt_message_packet_end_create(
@@ -171,7 +185,7 @@ struct bt_message *bt_message_packet_end_create(
 
        BT_ASSERT_PRE_NON_NULL(msg_iter, "Message iterator");
        return create_packet_message(msg_iter, (void *) packet,
-               &msg_iter->graph->packet_end_msg_pool, false, 0);
+               &msg_iter->graph->packet_end_msg_pool, false, false, 0);
 }
 
 struct bt_message *bt_message_packet_end_create_with_default_clock_snapshot(
@@ -183,7 +197,7 @@ struct bt_message *bt_message_packet_end_create_with_default_clock_snapshot(
 
        BT_ASSERT_PRE_NON_NULL(msg_iter, "Message iterator");
        return create_packet_message(msg_iter, (void *) packet,
-               &msg_iter->graph->packet_end_msg_pool, true, raw_value);
+               &msg_iter->graph->packet_end_msg_pool, true, false, raw_value);
 }
 
 BT_HIDDEN
@@ -285,10 +299,9 @@ const struct bt_packet *bt_message_packet_end_borrow_packet_const(
 }
 
 static inline
-enum bt_clock_snapshot_state
+const struct bt_clock_snapshot *
 borrow_packet_message_default_clock_snapshot_const(
-               const struct bt_message *message,
-               const struct bt_clock_snapshot **snapshot)
+               const struct bt_message *message)
 {
        struct bt_message_packet *packet_msg = (void *) message;
 
@@ -297,29 +310,52 @@ borrow_packet_message_default_clock_snapshot_const(
                "Message's stream's class has no default clock class: "
                "%![msg-]+n, %![sc-]+S",
                message, packet_msg->packet->stream->class);
-       BT_ASSERT_PRE_NON_NULL(snapshot, "Clock snapshot (output)");
-       *snapshot = packet_msg->default_cs;
-       return BT_CLOCK_SNAPSHOT_STATE_KNOWN;
+       return packet_msg->default_cs;
 }
 
-enum bt_clock_snapshot_state
+const struct bt_clock_snapshot *
 bt_message_packet_beginning_borrow_default_clock_snapshot_const(
-               const struct bt_message *msg,
-               const struct bt_clock_snapshot **snapshot)
+               const struct bt_message *msg)
 {
        BT_ASSERT_PRE_NON_NULL(msg, "Message");
        BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_PACKET_BEGINNING);
-       return borrow_packet_message_default_clock_snapshot_const(
-               msg, snapshot);
+       return borrow_packet_message_default_clock_snapshot_const(msg);
 }
 
-enum bt_clock_snapshot_state
+const struct bt_clock_snapshot *
 bt_message_packet_end_borrow_default_clock_snapshot_const(
-               const struct bt_message *msg,
-               const struct bt_clock_snapshot **snapshot)
+               const struct bt_message *msg)
+{
+       BT_ASSERT_PRE_NON_NULL(msg, "Message");
+       BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_PACKET_END);
+       return borrow_packet_message_default_clock_snapshot_const(msg);
+}
+
+static inline
+const struct bt_clock_class *
+borrow_packet_message_stream_class_default_clock_class(
+               const struct bt_message *msg)
+{
+       struct bt_message_packet *packet_msg = (void *) msg;
+
+       BT_ASSERT(msg);
+       return packet_msg->packet->stream->class->default_clock_class;
+}
+
+const struct bt_clock_class *
+bt_message_packet_beginning_borrow_stream_class_default_clock_class_const(
+               const struct bt_message *msg)
+{
+       BT_ASSERT_PRE_NON_NULL(msg, "Message");
+       BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_PACKET_BEGINNING);
+       return borrow_packet_message_stream_class_default_clock_class(msg);
+}
+
+const struct bt_clock_class *
+bt_message_packet_end_borrow_stream_class_default_clock_class_const(
+               const struct bt_message *msg)
 {
        BT_ASSERT_PRE_NON_NULL(msg, "Message");
        BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_PACKET_END);
-       return borrow_packet_message_default_clock_snapshot_const(
-               msg, snapshot);
+       return borrow_packet_message_stream_class_default_clock_class(msg);
 }
This page took 0.038207 seconds and 4 git commands to generate.