Values API: standardize parameters and return values
[babeltrace.git] / plugins / utils / muxer / muxer.c
index 2e52f3d70925b4377582be7d3299b7cfeee2136a..8275f3e4f660e91f14e81f2613866b2be225f5bc 100644 (file)
@@ -35,6 +35,7 @@
 #include <stdbool.h>
 #include <inttypes.h>
 #include <babeltrace/assert-internal.h>
+#include <babeltrace/common-internal.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -120,14 +121,14 @@ void destroy_muxer_upstream_notif_iter(
                muxer_upstream_notif_iter,
                muxer_upstream_notif_iter->notif_iter,
                muxer_upstream_notif_iter->notifs->length);
-       bt_put(muxer_upstream_notif_iter->notif_iter);
+       bt_object_put_ref(muxer_upstream_notif_iter->notif_iter);
 
        if (muxer_upstream_notif_iter->notifs) {
                struct bt_notification *notif;
 
                while ((notif = g_queue_pop_head(
                                muxer_upstream_notif_iter->notifs))) {
-                       bt_put(notif);
+                       bt_object_put_ref(notif);
                }
 
                g_queue_free(muxer_upstream_notif_iter->notifs);
@@ -150,7 +151,7 @@ struct muxer_upstream_notif_iter *muxer_notif_iter_add_upstream_notif_iter(
                goto end;
        }
 
-       muxer_upstream_notif_iter->notif_iter = bt_get(notif_iter);
+       muxer_upstream_notif_iter->notif_iter = bt_object_get_ref(notif_iter);
        muxer_upstream_notif_iter->notifs = g_queue_new();
        if (!muxer_upstream_notif_iter->notifs) {
                BT_LOGE_STR("Failed to allocate a GQueue.");
@@ -243,18 +244,18 @@ void destroy_muxer_comp(struct muxer_comp *muxer_comp)
 }
 
 static
-struct bt_value *get_default_params(void)
+struct bt_private_value *get_default_params(void)
 {
-       struct bt_value *params;
+       struct bt_private_value *params;
        int ret;
 
-       params = bt_value_map_create();
+       params = bt_private_value_map_create();
        if (!params) {
                BT_LOGE_STR("Cannot create a map value object.");
                goto error;
        }
 
-       ret = bt_value_map_insert_bool(params,
+       ret = bt_private_value_map_insert_bool_entry(params,
                ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME, false);
        if (ret) {
                BT_LOGE_STR("Cannot add boolean value to map value object.");
@@ -264,7 +265,7 @@ struct bt_value *get_default_params(void)
        goto end;
 
 error:
-       BT_PUT(params);
+       BT_OBJECT_PUT_REF_AND_RESET(params);
 
 end:
        return params;
@@ -273,8 +274,8 @@ end:
 static
 int configure_muxer_comp(struct muxer_comp *muxer_comp, struct bt_value *params)
 {
-       struct bt_value *default_params = NULL;
-       struct bt_value *real_params = NULL;
+       struct bt_private_value *default_params = NULL;
+       struct bt_private_value *real_params = NULL;
        struct bt_value *assume_absolute_clock_classes = NULL;
        int ret = 0;
        bt_bool bool_val;
@@ -286,8 +287,9 @@ int configure_muxer_comp(struct muxer_comp *muxer_comp, struct bt_value *params)
                goto error;
        }
 
-       real_params = bt_value_map_extend(default_params, params);
-       if (!real_params) {
+       ret = bt_value_map_extend(&real_params,
+               bt_value_borrow_from_private(default_params), params);
+       if (ret) {
                BT_LOGE("Cannot extend default parameters map value: "
                        "muxer-comp-addr=%p, def-params-addr=%p, "
                        "params-addr=%p", muxer_comp, default_params,
@@ -295,20 +297,20 @@ int configure_muxer_comp(struct muxer_comp *muxer_comp, struct bt_value *params)
                goto error;
        }
 
-       assume_absolute_clock_classes = bt_value_map_borrow(real_params,
+       assume_absolute_clock_classes = bt_value_map_borrow_entry_value(
+               bt_value_borrow_from_private(real_params),
                ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME);
        if (assume_absolute_clock_classes &&
                        !bt_value_is_bool(assume_absolute_clock_classes)) {
                BT_LOGE("Expecting a boolean value for the `%s` parameter: "
                        "muxer-comp-addr=%p, value-type=%s",
                        ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME, muxer_comp,
-                       bt_value_type_string(
+                       bt_common_value_type_string(
                                bt_value_get_type(assume_absolute_clock_classes)));
                goto error;
        }
 
-       ret = bt_value_bool_get(assume_absolute_clock_classes, &bool_val);
-       BT_ASSERT(ret == 0);
+       bool_val = bt_value_bool_get(assume_absolute_clock_classes);
        muxer_comp->assume_absolute_clock_classes = (bool) bool_val;
        BT_LOGD("Configured muxer component: muxer-comp-addr=%p, "
                "assume-absolute-clock-classes=%d",
@@ -319,8 +321,8 @@ error:
        ret = -1;
 
 end:
-       bt_put(default_params);
-       bt_put(real_params);
+       bt_object_put_ref(default_params);
+       bt_object_put_ref(real_params);
        return ret;
 }
 
@@ -443,7 +445,7 @@ struct bt_notification_iterator *create_notif_iter_on_input_port(
                port, bt_port_get_name(port), priv_conn, notif_iter);
 
 end:
-       bt_put(priv_conn);
+       bt_object_put_ref(priv_conn);
        return notif_iter;
 }
 
@@ -499,7 +501,7 @@ enum bt_notification_iterator_status muxer_upstream_notif_iter_next(
                 * won't be considered again to find the youngest
                 * notification.
                 */
-               BT_PUT(muxer_upstream_notif_iter->notif_iter);
+               BT_OBJECT_PUT_REF_AND_RESET(muxer_upstream_notif_iter->notif_iter);
                status = BT_NOTIFICATION_ITERATOR_STATUS_OK;
                break;
        default:
@@ -567,7 +569,7 @@ int muxer_notif_iter_handle_newly_connected_ports(
                        muxer_notif_iter_add_upstream_notif_iter(
                                muxer_notif_iter, upstream_notif_iter,
                                priv_port);
-               BT_PUT(upstream_notif_iter);
+               BT_OBJECT_PUT_REF_AND_RESET(upstream_notif_iter);
                if (!muxer_upstream_notif_iter) {
                        /*
                         * muxer_notif_iter_add_upstream_notif_iter()
@@ -577,7 +579,7 @@ int muxer_notif_iter_handle_newly_connected_ports(
                }
 
 remove_node:
-               bt_put(upstream_notif_iter);
+               bt_object_put_ref(upstream_notif_iter);
                muxer_notif_iter->newly_connected_priv_ports =
                        g_list_delete_link(
                                muxer_notif_iter->newly_connected_priv_ports,
@@ -601,13 +603,13 @@ int get_notif_ts_ns(struct muxer_comp *muxer_comp,
                struct bt_notification *notif, int64_t last_returned_ts_ns,
                int64_t *ts_ns)
 {
-       struct bt_clock_class_priority_map *cc_prio_map = NULL;
        struct bt_clock_class *clock_class = NULL;
        struct bt_clock_value *clock_value = NULL;
        struct bt_event *event = NULL;
        int ret = 0;
        const unsigned char *cc_uuid;
        const char *cc_name;
+       enum bt_clock_value_status cv_status = BT_CLOCK_VALUE_STATUS_KNOWN;
 
        BT_ASSERT(notif);
        BT_ASSERT(ts_ns);
@@ -619,14 +621,15 @@ int get_notif_ts_ns(struct muxer_comp *muxer_comp,
 
        switch (bt_notification_get_type(notif)) {
        case BT_NOTIFICATION_TYPE_EVENT:
-               cc_prio_map =
-                       bt_notification_event_borrow_clock_class_priority_map(
-                               notif);
+               event = bt_notification_event_borrow_event(notif);
+               BT_ASSERT(event);
+               cv_status = bt_event_borrow_default_clock_value(event,
+                       &clock_value);
                break;
 
        case BT_NOTIFICATION_TYPE_INACTIVITY:
-               cc_prio_map =
-                       bt_notification_inactivity_borrow_clock_class_priority_map(
+               clock_value =
+                       bt_notification_inactivity_borrow_default_clock_value(
                                notif);
                break;
        default:
@@ -636,33 +639,26 @@ int get_notif_ts_ns(struct muxer_comp *muxer_comp,
                goto end;
        }
 
-       if (!cc_prio_map) {
-               BT_LOGE("Cannot get notification's clock class priority map: "
-                       "notif-addr=%p", notif);
-               goto error;
+       if (cv_status != BT_CLOCK_VALUE_STATUS_KNOWN) {
+               BT_LOGE_STR("Unsupported unknown clock value.");
+               ret = -1;
+               goto end;
        }
 
        /*
-        * If the clock class priority map is empty, then we consider
-        * that this notification has no time. In this case it's always
-        * the youngest.
+        * If the clock value is missing, then we consider that this
+        * notification has no time. In this case it's always the
+        * youngest.
         */
-       if (bt_clock_class_priority_map_get_clock_class_count(cc_prio_map) == 0) {
-               BT_LOGV_STR("Notification's clock class priority map contains 0 clock classes: "
+       if (!clock_value) {
+               BT_LOGV_STR("Notification's default clock value is missing: "
                        "using the last returned timestamp.");
                *ts_ns = last_returned_ts_ns;
                goto end;
        }
 
-       clock_class =
-               bt_clock_class_priority_map_borrow_highest_priority_clock_class(
-                       cc_prio_map);
-       if (!clock_class) {
-               BT_LOGE("Cannot get the clock class with the highest priority from clock class priority map: "
-                       "cc-prio-map-addr=%p", cc_prio_map);
-               goto error;
-       }
-
+       clock_class = bt_clock_value_borrow_clock_class(clock_value);
+       BT_ASSERT(clock_class);
        cc_uuid = bt_clock_class_get_uuid(clock_class);
        cc_name = bt_clock_class_get_name(clock_class);
 
@@ -814,31 +810,7 @@ int get_notif_ts_ns(struct muxer_comp *muxer_comp,
                }
        }
 
-       switch (bt_notification_get_type(notif)) {
-       case BT_NOTIFICATION_TYPE_EVENT:
-               event = bt_notification_event_borrow_event(notif);
-               BT_ASSERT(event);
-               clock_value = bt_event_borrow_clock_value(event,
-                       clock_class);
-               break;
-       case BT_NOTIFICATION_TYPE_INACTIVITY:
-               clock_value = bt_notification_inactivity_borrow_clock_value(
-                       notif, clock_class);
-               break;
-       default:
-               BT_LOGF("Unexpected notification type at this point: "
-                       "type=%d", bt_notification_get_type(notif));
-               abort();
-       }
-
-       if (!clock_value) {
-               BT_LOGE("Cannot get notification's clock value for clock class: "
-                       "clock-class-addr=%p, clock-class-name=\"%s\"",
-                       clock_class, cc_name);
-               goto error;
-       }
-
-       ret = bt_clock_value_get_value_ns_from_epoch(clock_value, ts_ns);
+       ret = bt_clock_value_get_ns_from_origin(clock_value, ts_ns);
        if (ret) {
                BT_LOGE("Cannot get nanoseconds from Epoch of clock value: "
                        "clock-value-addr=%p", clock_value);
@@ -1227,11 +1199,11 @@ int muxer_notif_iter_init_newly_connected_ports(struct muxer_comp *muxer_comp,
                        BT_LOGD("Skipping input port: not connected: "
                                "muxer-comp-addr=%p, port-addr=%p, port-name\"%s\"",
                                muxer_comp, port, bt_port_get_name(port));
-                       bt_put(priv_port);
+                       bt_object_put_ref(priv_port);
                        continue;
                }
 
-               bt_put(priv_port);
+               bt_object_put_ref(priv_port);
                muxer_notif_iter->newly_connected_priv_ports =
                        g_list_append(
                                muxer_notif_iter->newly_connected_priv_ports,
@@ -1348,7 +1320,7 @@ error:
 
 end:
        muxer_comp->initializing_muxer_notif_iter = false;
-       bt_put(priv_comp);
+       bt_object_put_ref(priv_comp);
        return status;
 }
 
@@ -1376,7 +1348,7 @@ void muxer_notif_iter_finalize(
                destroy_muxer_notif_iter(muxer_notif_iter);
        }
 
-       bt_put(priv_comp);
+       bt_object_put_ref(priv_comp);
 }
 
 BT_HIDDEN
@@ -1416,7 +1388,7 @@ enum bt_notification_iterator_status muxer_notif_iter_next(
                        bt_notification_iterator_status_string(status));
        }
 
-       bt_put(priv_comp);
+       bt_object_put_ref(priv_comp);
        return status;
 }
 
This page took 0.027498 seconds and 4 git commands to generate.