From 818919b92b3dfe0834cec1c2e15d6ed6a41abb70 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Sat, 11 Apr 2020 13:08:54 -0400 Subject: [PATCH] sink.text.details: replace switch to convert status with cast Replace the switch currently used in details_consume, to convert the status of bt_message_iterator_next, with a simple cast, as per standard procedure. Change-Id: Iea35bd26f4af983d7cca37fc01b2b2f903cc73da Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/3394 Tested-by: jenkins Reviewed-by: Philippe Proulx --- src/plugins/text/details/details.c | 67 ++++++++++++------------------ 1 file changed, 26 insertions(+), 41 deletions(-) diff --git a/src/plugins/text/details/details.c b/src/plugins/text/details/details.c index a5fa2c52..ae389b25 100644 --- a/src/plugins/text/details/details.c +++ b/src/plugins/text/details/details.c @@ -425,8 +425,7 @@ BT_HIDDEN bt_component_class_sink_consume_method_status details_consume(bt_self_component_sink *comp) { - bt_component_class_sink_consume_method_status ret = - BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK; + bt_component_class_sink_consume_method_status status; bt_message_array_const msgs; uint64_t count; struct details_comp *details_comp; @@ -441,52 +440,38 @@ details_consume(bt_self_component_sink *comp) /* Consume messages */ next_status = bt_message_iterator_next( details_comp->msg_iter, &msgs, &count); - switch (next_status) { - case BT_MESSAGE_ITERATOR_NEXT_STATUS_OK: - ret = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK; - - for (i = 0; i < count; i++) { - int print_ret = details_write_message(details_comp, - msgs[i]); - - if (print_ret) { - for (; i < count; i++) { - /* Put all remaining messages */ - bt_message_put_ref(msgs[i]); - } + if (next_status != BT_MESSAGE_ITERATOR_NEXT_STATUS_OK) { + status = (int) next_status; + goto end; + } - ret = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR; - goto end; - } + for (i = 0; i < count; i++) { + int print_ret = details_write_message(details_comp, + msgs[i]); - /* Print output buffer to standard output and flush */ - if (details_comp->str->len > 0) { - printf("%s", details_comp->str->str); - fflush(stdout); - details_comp->printed_something = true; + if (print_ret) { + for (; i < count; i++) { + /* Put all remaining messages */ + bt_message_put_ref(msgs[i]); } - /* Put this message */ - bt_message_put_ref(msgs[i]); + status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR; + goto end; } - break; - case BT_MESSAGE_ITERATOR_NEXT_STATUS_AGAIN: - ret = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_AGAIN; - goto end; - case BT_MESSAGE_ITERATOR_NEXT_STATUS_END: - ret = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_END; - goto end; - case BT_MESSAGE_ITERATOR_NEXT_STATUS_ERROR: - ret = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR; - goto end; - case BT_MESSAGE_ITERATOR_NEXT_STATUS_MEMORY_ERROR: - ret = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_MEMORY_ERROR; - goto end; - default: - bt_common_abort(); + /* Print output buffer to standard output and flush */ + if (details_comp->str->len > 0) { + printf("%s", details_comp->str->str); + fflush(stdout); + details_comp->printed_something = true; + } + + /* Put this message */ + bt_message_put_ref(msgs[i]); } + status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK; + end: - return ret; + return status; } -- 2.34.1