sink.text.pretty: simplify error handling in pretty_consume
[babeltrace.git] / src / plugins / text / pretty / pretty.c
index 1a5a759d17603887d6c5fb092f95609155efebb8..a114818fa844020f2658cb370f8e5b030fb5ddae 100644 (file)
@@ -5,8 +5,8 @@
  * Copyright 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  */
 
-#define BT_COMP_LOG_SELF_COMP self_comp
-#define BT_LOG_OUTPUT_LEVEL log_level
+#define BT_COMP_LOG_SELF_COMP (pretty->self_comp)
+#define BT_LOG_OUTPUT_LEVEL (pretty->log_level)
 #define BT_LOG_TAG "PLUGIN/SINK.TEXT.PRETTY"
 #include "logging/comp-logging.h"
 
@@ -129,9 +129,7 @@ pretty_graph_is_configured(bt_self_component_sink *self_comp_sink)
        struct pretty_component *pretty;
        bt_self_component *self_comp =
                bt_self_component_sink_as_self_component(self_comp_sink);
-       const bt_component *comp = bt_self_component_as_component(self_comp);
        bt_self_component_port_input *in_port;
-       bt_logging_level log_level = bt_component_get_logging_level(comp);
 
        pretty = bt_self_component_get_data(self_comp);
        BT_ASSERT(pretty);
@@ -164,8 +162,7 @@ BT_HIDDEN
 bt_component_class_sink_consume_method_status pretty_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;
        bt_message_iterator *it;
        struct pretty_component *pretty = bt_self_component_get_data(
@@ -177,29 +174,14 @@ bt_component_class_sink_consume_method_status pretty_consume(
        it = pretty->iterator;
        next_status = bt_message_iterator_next(it,
                &msgs, &count);
-
-       switch (next_status) {
-       case BT_MESSAGE_ITERATOR_NEXT_STATUS_OK:
-               break;
-       case BT_MESSAGE_ITERATOR_NEXT_STATUS_MEMORY_ERROR:
-       case BT_MESSAGE_ITERATOR_NEXT_STATUS_AGAIN:
-               ret = (int) next_status;
-               goto end;
-       case BT_MESSAGE_ITERATOR_NEXT_STATUS_END:
-               ret = (int) next_status;
-               BT_MESSAGE_ITERATOR_PUT_REF_AND_RESET(
-                       pretty->iterator);
-               goto end;
-       default:
-               ret = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR;
+       if (next_status != BT_MESSAGE_ITERATOR_NEXT_STATUS_OK) {
+               status = (int) next_status;
                goto end;
        }
 
-       BT_ASSERT_DBG(next_status == BT_MESSAGE_ITERATOR_NEXT_STATUS_OK);
-
        for (i = 0; i < count; i++) {
-               ret = (int) handle_message(pretty, msgs[i]);
-               if (ret) {
+               status = (int) handle_message(pretty, msgs[i]);
+               if (status) {
                        goto end;
                }
 
@@ -211,7 +193,7 @@ end:
                bt_message_put_ref(msgs[i]);
        }
 
-       return ret;
+       return status;
 }
 
 static
@@ -329,8 +311,7 @@ struct bt_param_validation_map_value_entry_descr pretty_params[] = {
 
 static
 bt_component_class_initialize_method_status apply_params(
-               struct pretty_component *pretty, const bt_value *params,
-               bt_self_component *self_comp, bt_logging_level log_level)
+               struct pretty_component *pretty, const bt_value *params)
 {
        int ret;
        const bt_value *value;
@@ -345,7 +326,7 @@ bt_component_class_initialize_method_status apply_params(
                goto end;
        } else if (validation_status == BT_PARAM_VALIDATION_STATUS_VALIDATION_ERROR) {
                status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR;
-               BT_COMP_LOGE_APPEND_CAUSE(self_comp, "%s", validate_error);
+               BT_COMP_LOGE_APPEND_CAUSE(pretty->self_comp, "%s", validate_error);
                goto end;
        }
 
@@ -562,6 +543,9 @@ bt_component_class_initialize_method_status pretty_init(
                goto error;
        }
 
+       pretty->self_comp = self_comp;
+       pretty->log_level = log_level;
+
        add_port_status = bt_self_component_sink_add_input_port(self_comp_sink,
                in_port_name, NULL, NULL);
        if (add_port_status != BT_SELF_COMPONENT_ADD_PORT_STATUS_OK) {
@@ -578,7 +562,7 @@ bt_component_class_initialize_method_status pretty_init(
        pretty->delta_real_timestamp = -1ULL;
        pretty->last_real_timestamp = -1ULL;
 
-       status = apply_params(pretty, params, self_comp, log_level);
+       status = apply_params(pretty, params);
        if (status != BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK) {
                goto error;
        }
This page took 0.024448 seconds and 4 git commands to generate.