Make bt_private_component_*_add_*_port() return a status code
[babeltrace.git] / plugins / utils / muxer / muxer.c
index 533ccfaa5f937b4a5341b4b66b8d84b8134caf1d..30864edb4ceffbb3aba1dc4dc2ad7d927d6de326 100644 (file)
@@ -43,7 +43,7 @@
 #include <assert.h>
 #include <stdlib.h>
 
-#define IGNORE_ABSOLUTE_PARAM_NAME     "ignore-absolute"
+#define ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME       "assume-absolute-clock-classes"
 
 struct muxer_comp {
        /* Array of struct bt_private_notification_iterator * (weak refs) */
@@ -62,9 +62,6 @@ struct muxer_upstream_notif_iter {
        /* Owned by this, NULL if ended */
        struct bt_notification_iterator *notif_iter;
 
-       /* Weak */
-       struct bt_private_port *priv_port;
-
        /*
         * This flag is true if the upstream notification iterator's
         * current notification must be considered for the multiplexing
@@ -134,7 +131,6 @@ struct muxer_upstream_notif_iter *muxer_notif_iter_add_upstream_notif_iter(
        }
 
        muxer_upstream_notif_iter->notif_iter = bt_get(notif_iter);
-       muxer_upstream_notif_iter->priv_port = priv_port;
        muxer_upstream_notif_iter->is_valid = false;
        g_ptr_array_add(muxer_notif_iter->muxer_upstream_notif_iters,
                muxer_upstream_notif_iter);
@@ -144,13 +140,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);
 
@@ -160,15 +156,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;
        }
 
@@ -180,24 +175,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
@@ -225,8 +211,8 @@ struct bt_value *get_default_params(void)
                goto error;
        }
 
-       ret = bt_value_map_insert_bool(params, IGNORE_ABSOLUTE_PARAM_NAME,
-               false);
+       ret = bt_value_map_insert_bool(params,
+               ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME, false);
        if (ret) {
                goto error;
        }
@@ -260,7 +246,7 @@ int configure_muxer_comp(struct muxer_comp *muxer_comp, struct bt_value *params)
        }
 
        ignore_absolute = bt_value_map_get(real_params,
-               IGNORE_ABSOLUTE_PARAM_NAME);
+               ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME);
        if (!bt_value_is_bool(ignore_absolute)) {
                goto error;
        }
@@ -309,8 +295,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;
        }
 
@@ -325,7 +311,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;
@@ -706,6 +695,21 @@ enum bt_notification_iterator_status validate_muxer_upstream_notif_iters(
                if (status != BT_NOTIFICATION_ITERATOR_STATUS_OK) {
                        goto end;
                }
+
+               /*
+                * Remove this muxer upstream notification iterator
+                * if it's ended or canceled.
+                */
+               if (!muxer_upstream_notif_iter->notif_iter) {
+                       /*
+                        * Use g_ptr_array_remove_fast() because the
+                        * order of those elements is not important.
+                        */
+                       g_ptr_array_remove_index_fast(
+                               muxer_notif_iter->muxer_upstream_notif_iters,
+                               i);
+                       i--;
+               }
        }
 
 end:
This page took 0.025319 seconds and 4 git commands to generate.