Make API CTF-agnostic
[babeltrace.git] / plugins / utils / muxer / muxer.c
index 663bd3460d0a7fe741631eba2a02aba1e9bdf7c4..c75b5d9bbfd801b47dfea8366d923913a92f56f2 100644 (file)
@@ -52,7 +52,6 @@ struct muxer_comp {
        struct bt_private_component *priv_comp;
        unsigned int next_port_num;
        size_t available_input_ports;
-       bool error;
        bool initializing_muxer_notif_iter;
        bool assume_absolute_clock_classes;
 };
@@ -602,13 +601,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);
@@ -620,14 +619,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:
@@ -637,33 +637,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);
 
@@ -815,31 +808,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);
@@ -1403,16 +1372,6 @@ enum bt_notification_iterator_status muxer_notif_iter_next(
                "notif-iter-addr=%p",
                priv_comp, muxer_comp, muxer_notif_iter, priv_notif_iter);
 
-       /* Are we in an error state set elsewhere? */
-       if (unlikely(muxer_comp->error)) {
-               BT_LOGE("Muxer component is already in an error state: returning BT_NOTIFICATION_ITERATOR_STATUS_ERROR: "
-                       "comp-addr=%p, muxer-comp-addr=%p, muxer-notif-iter-addr=%p, "
-                       "notif-iter-addr=%p",
-                       priv_comp, muxer_comp, muxer_notif_iter, priv_notif_iter);
-               status = BT_NOTIFICATION_ITERATOR_STATUS_ERROR;
-               goto end;
-       }
-
        status = muxer_notif_iter_do_next(muxer_comp, muxer_notif_iter,
                notifs, capacity, count);
        if (status < 0) {
@@ -1427,17 +1386,17 @@ enum bt_notification_iterator_status muxer_notif_iter_next(
                        bt_notification_iterator_status_string(status));
        }
 
-end:
        bt_put(priv_comp);
        return status;
 }
 
 BT_HIDDEN
-void muxer_port_connected(
+enum bt_component_status muxer_port_connected(
                struct bt_private_component *priv_comp,
                struct bt_private_port *self_private_port,
                struct bt_port *other_port)
 {
+       enum bt_component_status status = BT_COMPONENT_STATUS_OK;
        struct bt_port *self_port =
                bt_port_borrow_from_private(self_private_port);
        struct muxer_comp *muxer_comp =
@@ -1478,7 +1437,7 @@ void muxer_port_connected(
                                "port-addr=%p, port-name=\"%s\", "
                                "muxer-notif-iter-addr=%p", self_port,
                                bt_port_get_name(self_port), muxer_notif_iter);
-                       muxer_comp->error = true;
+                       status = BT_COMPONENT_STATUS_ERROR;
                        goto end;
                }
 
@@ -1499,12 +1458,12 @@ void muxer_port_connected(
                BT_LOGE("Cannot ensure that at least one muxer component's input port is available: "
                        "muxer-comp-addr=%p, status=%s",
                        muxer_comp, bt_component_status_string(ret));
-               muxer_comp->error = true;
+               status = BT_COMPONENT_STATUS_ERROR;
                goto end;
        }
 
 end:
-       return;
+       return status;
 }
 
 BT_HIDDEN
This page took 0.0271670000000001 seconds and 4 git commands to generate.