Values API: standardize function names
[babeltrace.git] / lib / graph / component-class-sink-colander.c
index 25176ea35a8e183527b3be3b5963ac548dcbf344..1422b266ce4634455986887ca96031883d9ecf01 100644 (file)
 #include <babeltrace/graph/private-component-sink.h>
 #include <babeltrace/graph/private-port.h>
 #include <babeltrace/graph/private-connection.h>
+#include <babeltrace/graph/private-connection-notification-iterator.h>
 #include <babeltrace/graph/private-component.h>
 #include <babeltrace/graph/component-class-sink-colander-internal.h>
+#include <babeltrace/assert-internal.h>
 #include <glib.h>
-#include <assert.h>
 
 static
 struct bt_component_class *colander_comp_cls;
 
 struct colander_data {
-       struct bt_notification **user_notif;
-       enum bt_notification_type *notif_types;
+       bt_notification_array notifs;
+       uint64_t *count_addr;
        struct bt_notification_iterator *notif_iter;
 };
 
@@ -52,7 +53,6 @@ enum bt_component_status colander_init(
        struct colander_data *colander_data = NULL;
        struct bt_component_class_sink_colander_data *user_provided_data =
                init_method_data;
-       const enum bt_notification_type *notif_type;
 
        if (!init_method_data) {
                BT_LOGW_STR("Component initialization method data is NULL.");
@@ -67,31 +67,8 @@ enum bt_component_status colander_init(
                goto end;
        }
 
-       colander_data->user_notif = user_provided_data->notification;
-
-       if (user_provided_data->notification_types) {
-               notif_type = user_provided_data->notification_types;
-               unsigned long count;
-
-               while (*notif_type != BT_NOTIFICATION_TYPE_SENTINEL) {
-                       notif_type++;
-               }
-
-               count = notif_type - user_provided_data->notification_types + 1;
-
-               colander_data->notif_types =
-                       g_new0(enum bt_notification_type, count);
-               if (!colander_data->notif_types) {
-                       BT_LOGE_STR("Failed to allocate an array of notification types.");
-                       status = BT_COMPONENT_STATUS_NOMEM;
-                       goto end;
-               }
-
-               memcpy(colander_data->notif_types,
-                       user_provided_data->notification_types,
-                       count * sizeof(enum bt_notification_type));
-       }
-
+       colander_data->notifs = user_provided_data->notifs;
+       colander_data->count_addr = user_provided_data->count_addr;
        status = bt_private_component_sink_add_input_private_port(
                priv_comp, "in", NULL, NULL);
        if (status != BT_COMPONENT_STATUS_OK) {
@@ -119,35 +96,36 @@ void colander_finalize(struct bt_private_component *priv_comp)
                bt_put(colander_data->notif_iter);
        }
 
-       g_free(colander_data->notif_types);
        g_free(colander_data);
 }
 
 static
-void colander_port_connected(struct bt_private_component *priv_comp,
+enum bt_component_status colander_port_connected(struct bt_private_component *priv_comp,
                struct bt_private_port *self_priv_port,
                struct bt_port *other_port)
 {
+       enum bt_component_status status = BT_COMPONENT_STATUS_OK;
        enum bt_connection_status conn_status;
        struct bt_private_connection *priv_conn =
                bt_private_port_get_private_connection(self_priv_port);
        struct colander_data *colander_data =
                bt_private_component_get_user_data(priv_comp);
 
-       assert(priv_conn);
-       assert(colander_data);
+       BT_ASSERT(priv_conn);
+       BT_ASSERT(colander_data);
        BT_PUT(colander_data->notif_iter);
        conn_status = bt_private_connection_create_notification_iterator(
-               priv_conn, colander_data->notif_types,
-               &colander_data->notif_iter);
+               priv_conn, &colander_data->notif_iter);
        if (conn_status) {
                BT_LOGE("Cannot create notification iterator from connection: "
                        "comp-addr=%p, conn-addr=%p", priv_comp, priv_conn);
+               status = BT_COMPONENT_STATUS_ERROR;
                goto end;
        }
 
 end:
        bt_put(priv_conn);
+       return status;
 }
 
 static
@@ -156,11 +134,11 @@ enum bt_component_status colander_consume(
 {
        enum bt_component_status status = BT_COMPONENT_STATUS_OK;
        enum bt_notification_iterator_status notif_iter_status;
-       struct bt_notification *notif = NULL;
        struct colander_data *colander_data =
                bt_private_component_get_user_data(priv_comp);
+       bt_notification_array notifs;
 
-       assert(colander_data);
+       BT_ASSERT(colander_data);
 
        if (!colander_data->notif_iter) {
                BT_LOGW("Trying to consume without an upstream notification iterator: "
@@ -168,8 +146,8 @@ enum bt_component_status colander_consume(
                goto end;
        }
 
-       notif_iter_status = bt_notification_iterator_next(
-               colander_data->notif_iter);
+       notif_iter_status = bt_private_connection_notification_iterator_next(
+               colander_data->notif_iter, &notifs, colander_data->count_addr);
        switch (notif_iter_status) {
        case BT_NOTIFICATION_ITERATOR_STATUS_CANCELED:
                status = BT_COMPONENT_STATUS_OK;
@@ -181,19 +159,17 @@ enum bt_component_status colander_consume(
                status = BT_COMPONENT_STATUS_END;
                goto end;
        case BT_NOTIFICATION_ITERATOR_STATUS_OK:
+               /* Move notifications to user (count already set) */
+               memcpy(colander_data->notifs, notifs,
+                       sizeof(*notifs) * *colander_data->count_addr);
                break;
        default:
                status = BT_COMPONENT_STATUS_ERROR;
                goto end;
        }
 
-       notif = bt_notification_iterator_get_notification(
-               colander_data->notif_iter);
-       assert(notif);
-
 end:
        /* Move notification to user's pointer, even if NULL. */
-       *colander_data->user_notif = notif;
        return status;
 }
 
This page took 0.026121 seconds and 4 git commands to generate.