X-Git-Url: https://git.efficios.com/?a=blobdiff_plain;f=src%2Flib%2Fgraph%2Fmessage%2Fpacket.c;h=e27c766c29ff5b18be7cbafbf421681902076399;hb=d4f19030befaa331ead2414c649e812cf72a2b5d;hp=84dd8c4c29e609a4faeeb7088fbe1cef0da59f5d;hpb=d98421f2abfc5adab28ab7ee9b63537a6c7261cc;p=babeltrace.git diff --git a/src/lib/graph/message/packet.c b/src/lib/graph/message/packet.c index 84dd8c4c..e27c766c 100644 --- a/src/lib/graph/message/packet.c +++ b/src/lib/graph/message/packet.c @@ -26,6 +26,30 @@ #include "packet.h" +#define BT_ASSERT_PRE_DEV_MSG_IS_PACKET_BEGINNING(_msg) \ + BT_ASSERT_PRE_DEV_MSG_HAS_TYPE("message", (_msg), \ + "packet-beginning", BT_MESSAGE_TYPE_PACKET_BEGINNING) + +#define BT_ASSERT_PRE_DEV_MSG_IS_PACKET_END(_msg) \ + BT_ASSERT_PRE_DEV_MSG_HAS_TYPE("message", (_msg), \ + "packet-end", BT_MESSAGE_TYPE_PACKET_END) + +#define BT_ASSERT_PRE_DEV_MSG_STREAM_CLASS_PACKETS_HAVE_BEGINNING_DEF_CS(_msg) \ + BT_ASSERT_PRE_DEV("msg-stream-class-packets-have-beginning-default-clock-snapshot", ({ \ + const struct bt_packet *_packet = bt_message_packet_beginning_borrow_packet_const(_msg); \ + const struct bt_stream *_stream = bt_packet_borrow_stream_const(_packet); \ + const struct bt_stream_class *_stream_class = bt_stream_borrow_class_const(_stream); \ + bt_stream_class_packets_have_beginning_default_clock_snapshot(_stream_class); \ + }), "Packets of the message's stream don't have a beginning default clock snapshot.") + +#define BT_ASSERT_PRE_DEV_MSG_STREAM_CLASS_PACKETS_HAVE_END_DEF_CS(_msg) \ + BT_ASSERT_PRE_DEV("msg-stream-class-packets-have-end-default-clock-snapshot", ({ \ + const struct bt_packet *_packet = bt_message_packet_end_borrow_packet_const(_msg); \ + const struct bt_stream *_stream = bt_packet_borrow_stream_const(_packet); \ + const struct bt_stream_class *_stream_class = bt_stream_borrow_class_const(_stream); \ + bt_stream_class_packets_have_end_default_clock_snapshot(_stream_class); \ + }), "Packets of the message's stream don't have an end default clock snapshot.") + static inline struct bt_message *new_packet_message(struct bt_graph *graph, enum bt_message_type type, bt_object_release_func recycle_func) @@ -67,7 +91,7 @@ static inline struct bt_message *create_packet_message( struct bt_message_iterator *msg_iter, struct bt_packet *packet, struct bt_object_pool *pool, - bool with_cs, uint64_t raw_value) + bool with_cs, uint64_t raw_value, const char *api_func) { struct bt_message_packet *message = NULL; struct bt_stream *stream; @@ -75,7 +99,7 @@ struct bt_message *create_packet_message( bool need_cs; BT_ASSERT(msg_iter); - BT_ASSERT_PRE_NON_NULL(packet, "Packet"); + BT_ASSERT_PRE_PACKET_NON_NULL_FROM_FUNC(api_func, packet); stream = bt_packet_borrow_stream(packet); BT_ASSERT(stream); stream_class = bt_stream_borrow_class(stream); @@ -97,14 +121,16 @@ struct bt_message *create_packet_message( * `packet_has_default_clock_snapshot` implies that the stream * class has a default clock class (precondition). */ - BT_ASSERT_PRE(need_cs ? with_cs : true, + BT_ASSERT_PRE_FROM_FUNC(api_func, "with-default-clock-snapshot", + need_cs ? with_cs : true, "Unexpected stream class configuration when creating " "a packet beginning or end message: " "a default clock snapshot is needed, but none was provided: " "%![stream-]+s, %![sc-]+S, with-cs=%d, " "cs-val=%" PRIu64, stream, stream_class, with_cs, raw_value); - BT_ASSERT_PRE(!need_cs ? !with_cs : true, + BT_ASSERT_PRE_FROM_FUNC(api_func, "without-default-clock-snapshot", + !need_cs ? !with_cs : true, "Unexpected stream class configuration when creating " "a packet beginning or end message: " "no default clock snapshot is needed, but one was provided: " @@ -155,9 +181,9 @@ struct bt_message *bt_message_packet_beginning_create( (void *) self_msg_iter; BT_ASSERT_PRE_DEV_NO_ERROR(); - BT_ASSERT_PRE_NON_NULL(msg_iter, "Message iterator"); + BT_ASSERT_PRE_MSG_ITER_NON_NULL(msg_iter); 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, 0, __func__); } struct bt_message *bt_message_packet_beginning_create_with_default_clock_snapshot( @@ -168,9 +194,10 @@ struct bt_message *bt_message_packet_beginning_create_with_default_clock_snapsho (void *) self_msg_iter; BT_ASSERT_PRE_DEV_NO_ERROR(); - BT_ASSERT_PRE_NON_NULL(msg_iter, "Message iterator"); + BT_ASSERT_PRE_MSG_ITER_NON_NULL(msg_iter); 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, raw_value, + __func__); } struct bt_message *bt_message_packet_end_create( @@ -181,9 +208,9 @@ struct bt_message *bt_message_packet_end_create( (void *) self_msg_iter; BT_ASSERT_PRE_DEV_NO_ERROR(); - BT_ASSERT_PRE_NON_NULL(msg_iter, "Message iterator"); + BT_ASSERT_PRE_MSG_ITER_NON_NULL(msg_iter); 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, 0, __func__); } struct bt_message *bt_message_packet_end_create_with_default_clock_snapshot( @@ -194,9 +221,10 @@ struct bt_message *bt_message_packet_end_create_with_default_clock_snapshot( (void *) self_msg_iter; BT_ASSERT_PRE_DEV_NO_ERROR(); - BT_ASSERT_PRE_NON_NULL(msg_iter, "Message iterator"); + BT_ASSERT_PRE_MSG_ITER_NON_NULL(msg_iter); 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, raw_value, + __func__); } BT_HIDDEN @@ -266,9 +294,8 @@ struct bt_packet *bt_message_packet_beginning_borrow_packet( { struct bt_message_packet *packet_msg = (void *) message; - BT_ASSERT_PRE_DEV_NON_NULL(message, "Message"); - BT_ASSERT_PRE_DEV_MSG_IS_TYPE(message, - BT_MESSAGE_TYPE_PACKET_BEGINNING); + BT_ASSERT_PRE_DEV_MSG_NON_NULL(message); + BT_ASSERT_PRE_DEV_MSG_IS_PACKET_BEGINNING(message); return packet_msg->packet; } @@ -284,9 +311,8 @@ struct bt_packet *bt_message_packet_end_borrow_packet( { struct bt_message_packet *packet_msg = (void *) message; - BT_ASSERT_PRE_DEV_NON_NULL(message, "Message"); - BT_ASSERT_PRE_DEV_MSG_IS_TYPE(message, - BT_MESSAGE_TYPE_PACKET_END); + BT_ASSERT_PRE_DEV_MSG_NON_NULL(message); + BT_ASSERT_PRE_DEV_MSG_IS_PACKET_END(message); return packet_msg->packet; } @@ -297,6 +323,10 @@ const struct bt_packet *bt_message_packet_end_borrow_packet_const( (void *) message); } +#define BT_ASSERT_PRE_DEV_FOR_BORROW_DEF_CS(_msg) \ + BT_ASSERT_PRE_DEV_MSG_SC_DEF_CLK_CLS((_msg), \ + ((struct bt_message_packet *) _msg)->packet->stream->class) + static inline const struct bt_clock_snapshot * borrow_packet_message_default_clock_snapshot_const( @@ -305,11 +335,6 @@ borrow_packet_message_default_clock_snapshot_const( struct bt_message_packet *packet_msg = (void *) message; BT_ASSERT_DBG(message); - BT_ASSERT_PRE_DEV( - packet_msg->packet->stream->class->default_clock_class, - "Message's stream's class has no default clock class: " - "%![msg-]+n, %![sc-]+S", - message, packet_msg->packet->stream->class); return packet_msg->default_cs; } @@ -317,8 +342,10 @@ const struct bt_clock_snapshot * bt_message_packet_beginning_borrow_default_clock_snapshot_const( const struct bt_message *msg) { - BT_ASSERT_PRE_DEV_NON_NULL(msg, "Message"); - BT_ASSERT_PRE_DEV_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_PACKET_BEGINNING); + BT_ASSERT_PRE_DEV_MSG_NON_NULL(msg); + BT_ASSERT_PRE_DEV_MSG_IS_PACKET_BEGINNING(msg); + BT_ASSERT_PRE_DEV_FOR_BORROW_DEF_CS(msg); + BT_ASSERT_PRE_DEV_MSG_STREAM_CLASS_PACKETS_HAVE_BEGINNING_DEF_CS(msg); return borrow_packet_message_default_clock_snapshot_const(msg); } @@ -326,8 +353,10 @@ const struct bt_clock_snapshot * bt_message_packet_end_borrow_default_clock_snapshot_const( const struct bt_message *msg) { - BT_ASSERT_PRE_DEV_NON_NULL(msg, "Message"); - BT_ASSERT_PRE_DEV_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_PACKET_END); + BT_ASSERT_PRE_DEV_MSG_NON_NULL(msg); + BT_ASSERT_PRE_DEV_MSG_IS_PACKET_END(msg); + BT_ASSERT_PRE_DEV_FOR_BORROW_DEF_CS(msg); + BT_ASSERT_PRE_DEV_MSG_STREAM_CLASS_PACKETS_HAVE_END_DEF_CS(msg); return borrow_packet_message_default_clock_snapshot_const(msg); } @@ -346,8 +375,8 @@ const struct bt_clock_class * bt_message_packet_beginning_borrow_stream_class_default_clock_class_const( const struct bt_message *msg) { - BT_ASSERT_PRE_DEV_NON_NULL(msg, "Message"); - BT_ASSERT_PRE_DEV_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_PACKET_BEGINNING); + BT_ASSERT_PRE_DEV_MSG_NON_NULL(msg); + BT_ASSERT_PRE_DEV_MSG_IS_PACKET_BEGINNING(msg); return borrow_packet_message_stream_class_default_clock_class(msg); } @@ -355,7 +384,7 @@ const struct bt_clock_class * bt_message_packet_end_borrow_stream_class_default_clock_class_const( const struct bt_message *msg) { - BT_ASSERT_PRE_DEV_NON_NULL(msg, "Message"); - BT_ASSERT_PRE_DEV_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_PACKET_END); + BT_ASSERT_PRE_DEV_MSG_NON_NULL(msg); + BT_ASSERT_PRE_DEV_MSG_IS_PACKET_END(msg); return borrow_packet_message_stream_class_default_clock_class(msg); }