Make bt_private_connection_create_notification_iterator() return a status code
[babeltrace.git] / plugins / utils / muxer / muxer.c
index 04f8c535645066e25d07ffeb28cba8f8dc71c57f..47ffb866002018bdf5b5471ed6f7126fc355151c 100644 (file)
@@ -37,6 +37,7 @@
 #include <babeltrace/graph/private-connection.h>
 #include <babeltrace/graph/private-notification-iterator.h>
 #include <babeltrace/graph/private-port.h>
+#include <babeltrace/graph/connection.h>
 #include <plugins-common.h>
 #include <glib.h>
 #include <stdbool.h>
@@ -140,13 +141,13 @@ end:
 }
 
 static
-int ensure_available_input_port(struct bt_private_component *priv_comp)
+enum bt_component_status ensure_available_input_port(
+               struct bt_private_component *priv_comp)
 {
        struct muxer_comp *muxer_comp =
                bt_private_component_get_user_data(priv_comp);
-       int ret = 0;
+       enum bt_component_status status = BT_COMPONENT_STATUS_OK;
        GString *port_name = NULL;
-       void *priv_port = NULL;
 
        assert(muxer_comp);
 
@@ -156,15 +157,14 @@ int ensure_available_input_port(struct bt_private_component *priv_comp)
 
        port_name = g_string_new("in");
        if (!port_name) {
-               ret = -1;
+               status = BT_COMPONENT_STATUS_NOMEM;
                goto end;
        }
 
        g_string_append_printf(port_name, "%u", muxer_comp->next_port_num);
-       priv_port = bt_private_component_filter_add_input_private_port(
-               priv_comp, port_name->str, NULL);
-       if (!priv_port) {
-               ret = -1;
+       status = bt_private_component_filter_add_input_private_port(
+               priv_comp, port_name->str, NULL, NULL);
+       if (status != BT_COMPONENT_STATUS_OK) {
                goto end;
        }
 
@@ -176,24 +176,15 @@ end:
                g_string_free(port_name, TRUE);
        }
 
-       bt_put(priv_port);
-       return ret;
+       return status;
 }
 
 static
-int create_output_port(struct bt_private_component *priv_comp)
+enum bt_component_status create_output_port(
+               struct bt_private_component *priv_comp)
 {
-       void *priv_port;
-       int ret = 0;
-
-       priv_port = bt_private_component_filter_add_output_private_port(
-               priv_comp, "out", NULL);
-       if (!priv_port) {
-               ret = -1;
-       }
-
-       bt_put(priv_port);
-       return ret;
+       return bt_private_component_filter_add_output_private_port(
+               priv_comp, "out", NULL, NULL);
 }
 
 static
@@ -305,8 +296,8 @@ enum bt_component_status muxer_init(
        muxer_comp->priv_comp = priv_comp;
        ret = bt_private_component_set_user_data(priv_comp, muxer_comp);
        assert(ret == 0);
-       ret = ensure_available_input_port(priv_comp);
-       if (ret) {
+       status = ensure_available_input_port(priv_comp);
+       if (status != BT_COMPONENT_STATUS_OK) {
                goto error;
        }
 
@@ -321,7 +312,10 @@ error:
        destroy_muxer_comp(muxer_comp);
        ret = bt_private_component_set_user_data(priv_comp, NULL);
        assert(ret == 0);
-       status = BT_COMPONENT_STATUS_ERROR;
+
+       if (status == BT_COMPONENT_STATUS_OK) {
+               status = BT_COMPONENT_STATUS_ERROR;
+       }
 
 end:
        return status;
@@ -343,6 +337,7 @@ struct bt_notification_iterator *create_notif_iter_on_input_port(
        struct bt_port *port = bt_port_from_private_port(priv_port);
        struct bt_notification_iterator *notif_iter = NULL;
        struct bt_private_connection *priv_conn = NULL;
+       enum bt_connection_status conn_status;
 
        assert(ret);
        *ret = 0;
@@ -358,9 +353,9 @@ struct bt_notification_iterator *create_notif_iter_on_input_port(
        // TODO: Advance the iterator to >= the time of the latest
        //       returned notification by the muxer notification
        //       iterator which creates it.
-       notif_iter = bt_private_connection_create_notification_iterator(
-               priv_conn, NULL);
-       if (!notif_iter) {
+       conn_status = bt_private_connection_create_notification_iterator(
+               priv_conn, NULL, &notif_iter);
+       if (conn_status != BT_CONNECTION_STATUS_OK) {
                *ret = -1;
                goto end;
        }
This page took 0.025515 seconds and 4 git commands to generate.