lib: strictly type function return status enumerations
[babeltrace.git] / src / plugins / utils / counter / counter.c
index 42ac5ad6585b310efdad5c1fae0730ad4ace0341..db269e78e636b9b39d7df57167a35edb48cdea1a 100644 (file)
  * SOFTWARE.
  */
 
+#define BT_COMP_LOG_SELF_COMP (counter->self_comp)
+#define BT_LOG_OUTPUT_LEVEL (counter->log_level)
 #define BT_LOG_TAG "PLUGIN/FLT.UTILS.COUNTER"
-#include "logging.h"
+#include "plugins/comp-logging.h"
 
 #include <babeltrace2/babeltrace.h>
 #include "common/macros.h"
@@ -135,25 +137,38 @@ void counter_finalize(bt_self_component_sink *comp)
 }
 
 BT_HIDDEN
-bt_self_component_status counter_init(
+bt_component_class_init_method_status counter_init(
                bt_self_component_sink *component,
                const bt_value *params,
                __attribute__((unused)) void *init_method_data)
 {
-       bt_self_component_status ret;
+       bt_component_class_init_method_status status =
+               BT_COMPONENT_CLASS_INIT_METHOD_STATUS_OK;
+       bt_self_component_add_port_status add_port_status;
        struct counter *counter = g_new0(struct counter, 1);
        const bt_value *step = NULL;
        const bt_value *hide_zero = NULL;
 
        if (!counter) {
-               ret = BT_SELF_COMPONENT_STATUS_NOMEM;
+               status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_MEMORY_ERROR;
                goto error;
        }
 
-       ret = bt_self_component_sink_add_input_port(component,
+       counter->self_comp =
+               bt_self_component_sink_as_self_component(component);
+       counter->log_level = bt_component_get_logging_level(
+               bt_self_component_as_component(counter->self_comp));
+       add_port_status = bt_self_component_sink_add_input_port(component,
                "in", NULL, NULL);
-       if (ret != BT_SELF_COMPONENT_STATUS_OK) {
+       switch (add_port_status) {
+       case BT_SELF_COMPONENT_ADD_PORT_STATUS_ERROR:
+               status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_ERROR;
                goto error;
+       case BT_SELF_COMPONENT_ADD_PORT_STATUS_MEMORY_ERROR:
+               status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_MEMORY_ERROR;
+               goto error;
+       default:
+               break;
        }
 
        counter->last_printed_total = -1ULL;
@@ -161,7 +176,7 @@ bt_self_component_status counter_init(
        step = bt_value_map_borrow_entry_value_const(params, "step");
        if (step) {
                if (!bt_value_is_unsigned_integer(step)) {
-                       BT_LOGE("`step` parameter: expecting an unsigned integer value: "
+                       BT_COMP_LOGE("`step` parameter: expecting an unsigned integer value: "
                                "type=%s", bt_common_value_type_string(
                                        bt_value_get_type(step)));
                        goto error;
@@ -173,7 +188,7 @@ bt_self_component_status counter_init(
        hide_zero = bt_value_map_borrow_entry_value_const(params, "hide-zero");
        if (hide_zero) {
                if (!bt_value_is_bool(hide_zero)) {
-                       BT_LOGE("`hide-zero` parameter: expecting a boolean value: "
+                       BT_COMP_LOGE("`hide-zero` parameter: expecting a boolean value: "
                                "type=%s", bt_common_value_type_string(
                                        bt_value_get_type(hide_zero)));
                        goto error;
@@ -189,17 +204,22 @@ bt_self_component_status counter_init(
 
 error:
        destroy_private_counter_data(counter);
-       ret = BT_SELF_COMPONENT_STATUS_ERROR;
+
+       if (status == BT_COMPONENT_CLASS_INIT_METHOD_STATUS_OK) {
+               status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_ERROR;
+       }
 
 end:
-       return ret;
+       return status;
 }
 
 BT_HIDDEN
-bt_self_component_status counter_graph_is_configured(
+bt_component_class_sink_graph_is_configured_method_status
+counter_graph_is_configured(
                bt_self_component_sink *comp)
 {
-       bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK;
+       bt_component_class_sink_graph_is_configured_method_status status =
+               BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_OK;
        struct counter *counter;
        bt_self_component_port_input_message_iterator *iterator;
 
@@ -210,7 +230,7 @@ bt_self_component_status counter_graph_is_configured(
                bt_self_component_sink_borrow_input_port_by_name(comp,
                        in_port_name));
        if (!iterator) {
-               status = BT_SELF_COMPONENT_STATUS_NOMEM;
+               status = BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_MEMORY_ERROR;
                goto end;
        }
 
@@ -222,12 +242,13 @@ end:
 }
 
 BT_HIDDEN
-bt_self_component_status counter_consume(
+bt_component_class_sink_consume_method_status counter_consume(
                bt_self_component_sink *comp)
 {
-       bt_self_component_status ret = BT_SELF_COMPONENT_STATUS_OK;
+       bt_component_class_sink_consume_method_status status =
+               BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK;
        struct counter *counter;
-       bt_message_iterator_status it_ret;
+       bt_message_iterator_next_status next_status;
        uint64_t msg_count;
        bt_message_array_const msgs;
 
@@ -237,20 +258,20 @@ bt_self_component_status counter_consume(
 
        if (G_UNLIKELY(!counter->msg_iter)) {
                try_print_last(counter);
-               ret = BT_SELF_COMPONENT_STATUS_END;
+               status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_END;
                goto end;
        }
 
        /* Consume messages */
-       it_ret = bt_self_component_port_input_message_iterator_next(
+       next_status = bt_self_component_port_input_message_iterator_next(
                counter->msg_iter, &msgs, &msg_count);
-       if (it_ret < 0) {
-               ret = BT_SELF_COMPONENT_STATUS_ERROR;
+       if (next_status < 0) {
+               status = (int) next_status;
                goto end;
        }
 
-       switch (it_ret) {
-       case BT_MESSAGE_ITERATOR_STATUS_OK:
+       switch (next_status) {
+       case BT_MESSAGE_ITERATOR_NEXT_STATUS_OK:
        {
                uint64_t i;
 
@@ -296,18 +317,18 @@ bt_self_component_status counter_consume(
                        bt_message_put_ref(msg);
                }
 
-               ret = BT_SELF_COMPONENT_STATUS_OK;
+               status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK;
                break;
        }
-       case BT_MESSAGE_ITERATOR_STATUS_AGAIN:
-               ret = BT_SELF_COMPONENT_STATUS_AGAIN;
+       case BT_MESSAGE_ITERATOR_NEXT_STATUS_AGAIN:
+               status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_AGAIN;
                goto end;
-       case BT_MESSAGE_ITERATOR_STATUS_END:
+       case BT_MESSAGE_ITERATOR_NEXT_STATUS_END:
                try_print_last(counter);
-               ret = BT_SELF_COMPONENT_STATUS_END;
+               status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_END;
                goto end;
-       case BT_MESSAGE_ITERATOR_STATUS_NOMEM:
-               ret = BT_SELF_COMPONENT_STATUS_NOMEM;
+       case BT_MESSAGE_ITERATOR_NEXT_STATUS_MEMORY_ERROR:
+               status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_MEMORY_ERROR;
                goto end;
        default:
                break;
@@ -316,5 +337,5 @@ bt_self_component_status counter_consume(
        try_print_count(counter, msg_count);
 
 end:
-       return ret;
+       return status;
 }
This page took 0.027563 seconds and 4 git commands to generate.