lib: create input port msg iterator from self {msg iterator, sink comp.}
[babeltrace.git] / src / lib / graph / component-class-sink-colander.c
index 667b997c3189e5423aae0b59502c470856ea0e2d..d1978c95eedc1b93d5e6a4b555686fad84b8f248 100644 (file)
@@ -20,8 +20,8 @@
  * SOFTWARE.
  */
 
-#define BT_LOG_TAG "COLANDER"
-#include "lib/lib-logging.h"
+#define BT_LOG_TAG "LIB/COLANDER"
+#include "lib/logging.h"
 
 #include "common/assert.h"
 #include "lib/assert-pre.h"
 #include <glib.h>
 
 #include "component-class-sink-colander.h"
+#include "lib/func-status.h"
 
 static
 struct bt_component_class_sink *colander_comp_cls;
 
 static
-enum bt_self_component_status colander_init(
+enum bt_component_class_init_method_status colander_init(
                struct bt_self_component_sink *self_comp,
                const struct bt_value *params, void *init_method_data)
 {
-       enum bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK;
+       int status = BT_FUNC_STATUS_OK;
        struct bt_component_class_sink_colander_priv_data *colander_data = NULL;
        struct bt_component_class_sink_colander_data *user_provided_data =
                init_method_data;
 
-       if (!init_method_data) {
-               BT_LOGW_STR("Component initialization method data is NULL.");
-               status = BT_SELF_COMPONENT_STATUS_ERROR;
-               goto end;
-       }
-
+       BT_ASSERT(init_method_data);
        colander_data = g_new0(
                struct bt_component_class_sink_colander_priv_data, 1);
        if (!colander_data) {
-               BT_LOGE_STR("Failed to allocate colander data.");
-               status = BT_SELF_COMPONENT_STATUS_NOMEM;
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate colander sink data.");
+               status = BT_FUNC_STATUS_MEMORY_ERROR;
                goto end;
        }
 
@@ -66,8 +63,9 @@ enum bt_self_component_status colander_init(
        colander_data->count_addr = user_provided_data->count_addr;
        status = bt_self_component_sink_add_input_port(self_comp, "in",
                NULL, NULL);
-       if (status != BT_SELF_COMPONENT_STATUS_OK) {
-               BT_LOGE_STR("Cannot add input port.");
+       if (status != BT_FUNC_STATUS_OK) {
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Cannot add input port to colander sink.");
                goto end;
        }
 
@@ -95,10 +93,12 @@ void colander_finalize(struct bt_self_component_sink *self_comp)
 }
 
 static
-enum bt_self_component_status colander_graph_is_configured(
+enum bt_component_class_sink_graph_is_configured_method_status
+colander_graph_is_configured(
        bt_self_component_sink *self_comp)
 {
-       enum bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK;
+       enum bt_component_class_sink_graph_is_configured_method_status status =
+               BT_FUNC_STATUS_OK;
        struct bt_component_class_sink_colander_priv_data *colander_data =
                bt_self_component_get_data(
                        bt_self_component_sink_as_self_component(self_comp));
@@ -110,13 +110,13 @@ enum bt_self_component_status colander_graph_is_configured(
        BT_ASSERT(colander_data);
        BT_OBJECT_PUT_REF_AND_RESET(colander_data->msg_iter);
        colander_data->msg_iter =
-               bt_self_component_port_input_message_iterator_create(
-                       self_port);
+               bt_self_component_port_input_message_iterator_create_from_sink_component(
+                       self_comp, self_port);
        if (!colander_data->msg_iter) {
-               BT_LIB_LOGE("Cannot create message iterator on "
+               BT_LIB_LOGE_APPEND_CAUSE("Cannot create message iterator on "
                        "self component input port: %![port-]+p",
                        self_port);
-               status = BT_SELF_COMPONENT_STATUS_NOMEM;
+               status = BT_FUNC_STATUS_MEMORY_ERROR;
                goto end;
        }
 
@@ -125,43 +125,36 @@ end:
 }
 
 static
-enum bt_self_component_status colander_consume(
+enum bt_component_class_sink_consume_method_status colander_consume(
                struct bt_self_component_sink *self_comp)
 {
-       enum bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK;
-       enum bt_message_iterator_status msg_iter_status;
+       enum bt_component_class_sink_consume_method_status status =
+               BT_FUNC_STATUS_OK;
+       enum bt_message_iterator_next_status next_status;
        struct bt_component_class_sink_colander_priv_data *colander_data =
                bt_self_component_get_data(
                        bt_self_component_sink_as_self_component(self_comp));
        bt_message_array_const msgs;
 
        BT_ASSERT(colander_data);
-
-       if (!colander_data->msg_iter) {
-               BT_LIB_LOGW("Trying to consume without an "
-                       "upstream message iterator: %![comp-]+c",
-                       self_comp);
-               goto end;
-       }
-
-       msg_iter_status =
-               bt_self_component_port_input_message_iterator_next(
-                       colander_data->msg_iter, &msgs,
-                       colander_data->count_addr);
-       switch (msg_iter_status) {
-       case BT_MESSAGE_ITERATOR_STATUS_AGAIN:
-               status = BT_SELF_COMPONENT_STATUS_AGAIN;
+       BT_ASSERT(colander_data->msg_iter);
+       next_status = bt_self_component_port_input_message_iterator_next(
+               colander_data->msg_iter, &msgs,
+               colander_data->count_addr);
+       switch (next_status) {
+       case BT_FUNC_STATUS_AGAIN:
+               status = BT_FUNC_STATUS_AGAIN;
                goto end;
-       case BT_MESSAGE_ITERATOR_STATUS_END:
-               status = BT_SELF_COMPONENT_STATUS_END;
+       case BT_FUNC_STATUS_END:
+               status = BT_FUNC_STATUS_END;
                goto end;
-       case BT_MESSAGE_ITERATOR_STATUS_OK:
+       case BT_FUNC_STATUS_OK:
                /* Move messages to user (count already set) */
                memcpy(colander_data->msgs, msgs,
                        sizeof(*msgs) * *colander_data->count_addr);
                break;
        default:
-               status = BT_SELF_COMPONENT_STATUS_ERROR;
+               status = BT_FUNC_STATUS_ERROR;
                goto end;
        }
 
@@ -178,7 +171,8 @@ struct bt_component_class_sink *bt_component_class_sink_colander_get(void)
        colander_comp_cls = bt_component_class_sink_create("colander",
                colander_consume);
        if (!colander_comp_cls) {
-               BT_LOGE_STR("Cannot create sink colander component class.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Cannot create sink colander component class.");
                goto end;
        }
 
@@ -191,7 +185,7 @@ struct bt_component_class_sink *bt_component_class_sink_colander_get(void)
 
 end:
        bt_object_get_ref(colander_comp_cls);
-       return (void *) colander_comp_cls;
+       return colander_comp_cls;
 }
 
 __attribute__((destructor)) static
This page took 0.03129 seconds and 4 git commands to generate.