X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=lib%2Fgraph%2Fmessage%2Fdiscarded-items.c;h=9a8b0a1d19d767ccbec570cec590b3d4c0046f80;hb=9b24b6aa4258079f2b59fa156dd3e070969f6f2a;hp=a4bc9e3b2f8b527302238f794e3b50ef9ea9f92f;hpb=aa12059be0a0fab5242a7648d9bc6bd3f0f77afb;p=babeltrace.git diff --git a/lib/graph/message/discarded-items.c b/lib/graph/message/discarded-items.c index a4bc9e3b..9a8b0a1d 100644 --- a/lib/graph/message/discarded-items.c +++ b/lib/graph/message/discarded-items.c @@ -69,16 +69,32 @@ struct bt_message *create_discarded_items_message( { struct bt_message_discarded_items *message; struct bt_stream_class *stream_class; + bool has_support; + bool has_default_clock_snapshots; BT_ASSERT_PRE_NON_NULL(self_msg_iter, "Message iterator"); BT_ASSERT_PRE_NON_NULL(stream, "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), - "Creating a message with a default clock snapshot, but without " - "a default clock class, or without a default clock snapshot, " - "but with a default clock class: ", + + if (type == BT_MESSAGE_TYPE_DISCARDED_EVENTS) { + has_support = stream_class->supports_discarded_events; + has_default_clock_snapshots = + stream_class->discarded_events_have_default_clock_snapshots; + } else { + has_support = stream_class->supports_discarded_packets; + has_default_clock_snapshots = + stream_class->discarded_packets_have_default_clock_snapshots; + } + + BT_ASSERT_PRE(has_support, + "Stream class does not support discarded events or packets: " + "type=%s, %![stream-]+s, %![sc-]+S", + bt_message_type_string(type), stream, stream_class); + BT_ASSERT_PRE((with_cs && has_default_clock_snapshots) || + (!with_cs && !has_default_clock_snapshots), + "Unexpected stream class configuration when creating " + "a discarded events or packets message: " "type=%s, %![stream-]+s, %![sc-]+S, with-cs=%d, " "cs-begin-val=%" PRIu64 ", cs-end-val=%" PRIu64, bt_message_type_string(type), stream, stream_class, @@ -166,10 +182,9 @@ enum bt_property_availability get_discarded_items_message_count( } static inline -enum bt_clock_snapshot_state -borrow_discarded_items_message_default_beginning_clock_snapshot_const( - const struct bt_message *message, - const struct bt_clock_snapshot **snapshot) +const struct bt_clock_snapshot * +borrow_discarded_items_message_beginning_default_clock_snapshot_const( + const struct bt_message *message) { struct bt_message_discarded_items *disc_items_msg = (void *) message; @@ -178,16 +193,13 @@ borrow_discarded_items_message_default_beginning_clock_snapshot_const( "Message's stream's class has no default clock class: " "%![msg-]+n, %![sc-]+S", message, disc_items_msg->stream->class); - BT_ASSERT_PRE_NON_NULL(snapshot, "Clock snapshot (output)"); - *snapshot = disc_items_msg->default_begin_cs; - return BT_CLOCK_SNAPSHOT_STATE_KNOWN; + return disc_items_msg->default_begin_cs; } static inline -enum bt_clock_snapshot_state -borrow_discarded_items_message_default_end_clock_snapshot_const( - const struct bt_message *message, - const struct bt_clock_snapshot **snapshot) +const struct bt_clock_snapshot * +borrow_discarded_items_message_end_default_clock_snapshot_const( + const struct bt_message *message) { struct bt_message_discarded_items *disc_items_msg = (void *) message; @@ -196,9 +208,7 @@ borrow_discarded_items_message_default_end_clock_snapshot_const( "Message's stream's class has no default clock class: " "%![msg-]+n, %![sc-]+S", message, disc_items_msg->stream->class); - BT_ASSERT_PRE_NON_NULL(snapshot, "Clock snapshot (output)"); - *snapshot = disc_items_msg->default_end_cs; - return BT_CLOCK_SNAPSHOT_STATE_KNOWN; + return disc_items_msg->default_end_cs; } struct bt_message *bt_message_discarded_events_create( @@ -236,26 +246,24 @@ void bt_message_discarded_events_set_count(struct bt_message *message, set_discarded_items_message_count(message, count); } -enum bt_clock_snapshot_state -bt_message_discarded_events_borrow_default_beginning_clock_snapshot_const( - const struct bt_message *msg, - const struct bt_clock_snapshot **snapshot) +const struct bt_clock_snapshot * +bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const( + const struct bt_message *msg) { BT_ASSERT_PRE_NON_NULL(msg, "Message"); BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_DISCARDED_EVENTS); - return borrow_discarded_items_message_default_beginning_clock_snapshot_const( - msg, snapshot); + return borrow_discarded_items_message_beginning_default_clock_snapshot_const( + msg); } -enum bt_clock_snapshot_state -bt_message_discarded_events_borrow_default_end_clock_snapshot_const( - const struct bt_message *msg, - const struct bt_clock_snapshot **snapshot) +const struct bt_clock_snapshot * +bt_message_discarded_events_borrow_end_default_clock_snapshot_const( + const struct bt_message *msg) { BT_ASSERT_PRE_NON_NULL(msg, "Message"); BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_DISCARDED_EVENTS); - return borrow_discarded_items_message_default_end_clock_snapshot_const( - msg, snapshot); + return borrow_discarded_items_message_end_default_clock_snapshot_const( + msg); } const struct bt_stream * @@ -308,26 +316,24 @@ void bt_message_discarded_packets_set_count(struct bt_message *message, set_discarded_items_message_count(message, count); } -enum bt_clock_snapshot_state -bt_message_discarded_packets_borrow_default_beginning_clock_snapshot_const( - const struct bt_message *msg, - const struct bt_clock_snapshot **snapshot) +const struct bt_clock_snapshot * +bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const( + const struct bt_message *msg) { BT_ASSERT_PRE_NON_NULL(msg, "Message"); BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_DISCARDED_PACKETS); - return borrow_discarded_items_message_default_beginning_clock_snapshot_const( - msg, snapshot); + return borrow_discarded_items_message_beginning_default_clock_snapshot_const( + msg); } -enum bt_clock_snapshot_state -bt_message_discarded_packets_borrow_default_end_clock_snapshot_const( - const struct bt_message *msg, - const struct bt_clock_snapshot **snapshot) +const struct bt_clock_snapshot * +bt_message_discarded_packets_borrow_end_default_clock_snapshot_const( + const struct bt_message *msg) { BT_ASSERT_PRE_NON_NULL(msg, "Message"); BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_DISCARDED_PACKETS); - return borrow_discarded_items_message_default_end_clock_snapshot_const( - msg, snapshot); + return borrow_discarded_items_message_end_default_clock_snapshot_const( + msg); } const struct bt_stream * @@ -344,3 +350,34 @@ enum bt_property_availability bt_message_discarded_packets_get_count( BT_ASSERT_PRE_MSG_IS_TYPE(message, BT_MESSAGE_TYPE_DISCARDED_PACKETS); return get_discarded_items_message_count(message, count); } + +static inline +const struct bt_clock_class * +borrow_discarded_items_message_stream_class_default_clock_class( + const struct bt_message *msg) +{ + struct bt_message_discarded_items *disc_items_msg = (void *) msg; + + BT_ASSERT(msg); + return disc_items_msg->stream->class->default_clock_class; +} + +const struct bt_clock_class * +bt_message_discarded_events_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_DISCARDED_EVENTS); + return borrow_discarded_items_message_stream_class_default_clock_class( + msg); +} + +const struct bt_clock_class * +bt_message_discarded_packets_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_DISCARDED_PACKETS); + return borrow_discarded_items_message_stream_class_default_clock_class( + msg); +}