From 1e123ed605bf4936226d675e6725691bff249f7f Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Wed, 10 Nov 2021 10:22:58 -0500 Subject: [PATCH] Move bt_message_type_string to common Move it to src/common/common.h, so that it can be used by plugins. Rename it to bt_common_message_type_string. Change-Id: Ica2fc901a35a142ac54a68b3a69a3470e92a327a Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/6694 Reviewed-by: Philippe Proulx Tested-by: jenkins --- src/common/common.h | 25 +++++++++++++++++++++++++ src/lib/assert-cond.h | 4 ++-- src/lib/graph/message/discarded-items.c | 8 ++++---- src/lib/graph/message/message.h | 25 ------------------------- src/lib/graph/message/stream.c | 2 +- src/lib/lib-logging.c | 2 +- 6 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/common/common.h b/src/common/common.h index 2cad3076..46e6a1a1 100644 --- a/src/common/common.h +++ b/src/common/common.h @@ -895,6 +895,31 @@ const char *bt_common_component_class_type_string( bt_common_abort(); } +static inline +const char *bt_common_message_type_string(enum bt_message_type type) +{ + switch (type) { + case BT_MESSAGE_TYPE_STREAM_BEGINNING: + return "STREAM_BEGINNING"; + case BT_MESSAGE_TYPE_STREAM_END: + return "STREAM_END"; + case BT_MESSAGE_TYPE_EVENT: + return "EVENT"; + case BT_MESSAGE_TYPE_PACKET_BEGINNING: + return "PACKET_BEGINNING"; + case BT_MESSAGE_TYPE_PACKET_END: + return "PACKET_END"; + case BT_MESSAGE_TYPE_DISCARDED_EVENTS: + return "DISCARDED_EVENTS"; + case BT_MESSAGE_TYPE_DISCARDED_PACKETS: + return "DISCARDED_PACKETS"; + case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY: + return "MESSAGE_ITERATOR_INACTIVITY"; + } + + bt_common_abort(); +} + #ifdef __cplusplus } #endif diff --git a/src/lib/assert-cond.h b/src/lib/assert-cond.h index e89ee922..2c89d892 100644 --- a/src/lib/assert-cond.h +++ b/src/lib/assert-cond.h @@ -817,14 +817,14 @@ _BT_ASSERT_PRE_MSG_HAS_TYPE_ID(_msg_id, _type_id), \ _BT_ASSERT_PRE_MSG_HAS_TYPE_COND((_msg), (_type)), \ _BT_ASSERT_PRE_MSG_HAS_TYPE_FMT, \ - bt_message_type_string(_type), (_msg)) + bt_common_message_type_string(_type), (_msg)) #define BT_ASSERT_PRE_DEV_MSG_HAS_TYPE(_msg_id, _msg, _type_id, _type) \ BT_ASSERT_PRE_DEV( \ _BT_ASSERT_PRE_MSG_HAS_TYPE_ID(_msg_id, _type_id), \ _BT_ASSERT_PRE_MSG_HAS_TYPE_COND((_msg), (_type)), \ _BT_ASSERT_PRE_MSG_HAS_TYPE_FMT, \ - bt_message_type_string(_type), (_msg)) + bt_common_message_type_string(_type), (_msg)) #define _BT_ASSERT_PRE_MSG_NAME "Message" #define _BT_ASSERT_PRE_MSG_ID "message" diff --git a/src/lib/graph/message/discarded-items.c b/src/lib/graph/message/discarded-items.c index b20e1abf..313348c9 100644 --- a/src/lib/graph/message/discarded-items.c +++ b/src/lib/graph/message/discarded-items.c @@ -94,7 +94,7 @@ struct bt_message *create_discarded_items_message( 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_common_message_type_string(type), stream, stream_class); BT_ASSERT_PRE_FROM_FUNC(api_func, "with-default-clock-snapshots", need_cs ? with_cs : true, "Unexpected stream class configuration when creating " @@ -102,7 +102,7 @@ struct bt_message *create_discarded_items_message( "default clock snapshots are needed, but none was provided: " "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, + bt_common_message_type_string(type), stream, stream_class, with_cs, beginning_raw_value, end_raw_value); BT_ASSERT_PRE_FROM_FUNC(api_func, "without-default-clock-snapshots", !need_cs ? !with_cs : true, @@ -111,12 +111,12 @@ struct bt_message *create_discarded_items_message( "no default clock snapshots are needed, but two were provided: " "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, + bt_common_message_type_string(type), stream, stream_class, with_cs, beginning_raw_value, end_raw_value); BT_LIB_LOGD("Creating discarded items message object: " "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, + bt_common_message_type_string(type), stream, stream_class, with_cs, beginning_raw_value, end_raw_value); message = g_new0(struct bt_message_discarded_items, 1); if (!message) { diff --git a/src/lib/graph/message/message.h b/src/lib/graph/message/message.h index 8e87a765..791ac9ae 100644 --- a/src/lib/graph/message/message.h +++ b/src/lib/graph/message/message.h @@ -95,29 +95,4 @@ void bt_message_unlink_graph(struct bt_message *msg); # define bt_message_freeze(_x) #endif /* BT_DEV_MODE */ -static inline -const char *bt_message_type_string(enum bt_message_type type) -{ - switch (type) { - case BT_MESSAGE_TYPE_STREAM_BEGINNING: - return "STREAM_BEGINNING"; - case BT_MESSAGE_TYPE_STREAM_END: - return "STREAM_END"; - case BT_MESSAGE_TYPE_EVENT: - return "EVENT"; - case BT_MESSAGE_TYPE_PACKET_BEGINNING: - return "PACKET_BEGINNING"; - case BT_MESSAGE_TYPE_PACKET_END: - return "PACKET_END"; - case BT_MESSAGE_TYPE_DISCARDED_EVENTS: - return "DISCARDED_EVENTS"; - case BT_MESSAGE_TYPE_DISCARDED_PACKETS: - return "DISCARDED_PACKETS"; - case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY: - return "MESSAGE_ITERATOR_INACTIVITY"; - } - - bt_common_abort(); -} - #endif /* BABELTRACE_GRAPH_MESSAGE_MESSAGE_INTERNAL_H */ diff --git a/src/lib/graph/message/stream.c b/src/lib/graph/message/stream.c index cd88d25b..a3723e4a 100644 --- a/src/lib/graph/message/stream.c +++ b/src/lib/graph/message/stream.c @@ -62,7 +62,7 @@ struct bt_message *create_stream_message( BT_ASSERT(stream_class); BT_LIB_LOGD("Creating stream message object: " "type=%s, %![stream-]+s, %![sc-]+S", - bt_message_type_string(type), stream, stream_class); + bt_common_message_type_string(type), stream, stream_class); message = g_new0(struct bt_message_stream, 1); if (!message) { BT_LIB_LOGE_APPEND_CAUSE( diff --git a/src/lib/lib-logging.c b/src/lib/lib-logging.c index 8766e446..df73244b 100644 --- a/src/lib/lib-logging.c +++ b/src/lib/lib-logging.c @@ -932,7 +932,7 @@ static inline void format_message(char **buf_ch, bool extended, char tmp_prefix[TMP_PREFIX_LEN]; BUF_APPEND(", %stype=%s", - PRFIELD(bt_message_type_string(msg->type))); + PRFIELD(bt_common_message_type_string(msg->type))); if (!extended) { return; -- 2.34.1