flt.utils.muxer: replace queue with array
[babeltrace.git] / src / plugins / utils / muxer / muxer.c
index db8b86bd817c94c7d5a6dd9a56dc433c0554421a..fa049cf0dd939b65272dc1d02dc1ab1f82bfdb42 100644 (file)
@@ -1,23 +1,7 @@
 /*
- * Copyright 2017 Philippe Proulx <pproulx@efficios.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
+ * SPDX-License-Identifier: MIT
  *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
+ * Copyright 2017 Philippe Proulx <pproulx@efficios.com>
  */
 
 #define BT_COMP_LOG_SELF_COMP (muxer_comp->self_comp)
@@ -59,7 +43,10 @@ struct muxer_upstream_msg_iter {
        bt_message_iterator *msg_iter;
 
        /* Contains `const bt_message *`, owned by this */
-       GQueue *msgs;
+       GPtrArray *msgs;
+
+       /* Index of the next message in `msgs` to return */
+       guint next_msg;
 };
 
 enum muxer_msg_iter_clock_class_expectation {
@@ -120,11 +107,7 @@ struct muxer_msg_iter {
 static
 void empty_message_queue(struct muxer_upstream_msg_iter *upstream_msg_iter)
 {
-       const bt_message *msg;
-
-       while ((msg = g_queue_pop_head(upstream_msg_iter->msgs))) {
-               bt_message_put_ref(msg);
-       }
+       g_ptr_array_set_size(upstream_msg_iter->msgs, 0);
 }
 
 static
@@ -139,16 +122,17 @@ void destroy_muxer_upstream_msg_iter(
 
        muxer_comp = muxer_upstream_msg_iter->muxer_comp;
        BT_COMP_LOGD("Destroying muxer's upstream message iterator wrapper: "
-               "addr=%p, msg-iter-addr=%p, queue-len=%u",
+               "addr=%p, msg-iter-addr=%p, queue-len=%u, next-msg=%u",
                muxer_upstream_msg_iter,
                muxer_upstream_msg_iter->msg_iter,
-               muxer_upstream_msg_iter->msgs->length);
+               muxer_upstream_msg_iter->msgs->len,
+               muxer_upstream_msg_iter->next_msg);
+
        bt_message_iterator_put_ref(
                muxer_upstream_msg_iter->msg_iter);
 
        if (muxer_upstream_msg_iter->msgs) {
-               empty_message_queue(muxer_upstream_msg_iter);
-               g_queue_free(muxer_upstream_msg_iter->msgs);
+               g_ptr_array_free(muxer_upstream_msg_iter->msgs, TRUE);
        }
 
        g_free(muxer_upstream_msg_iter);
@@ -164,16 +148,19 @@ int muxer_msg_iter_add_upstream_msg_iter(struct muxer_msg_iter *muxer_msg_iter,
        struct muxer_comp *muxer_comp = muxer_msg_iter->muxer_comp;
 
        if (!muxer_upstream_msg_iter) {
-               BT_COMP_LOGE_STR("Failed to allocate one muxer's upstream message iterator wrapper.");
+               BT_COMP_LOGE_APPEND_CAUSE(muxer_comp->self_comp,
+                       "Failed to allocate one muxer's upstream message iterator wrapper.");
                goto error;
        }
 
        muxer_upstream_msg_iter->muxer_comp = muxer_comp;
        muxer_upstream_msg_iter->msg_iter = self_msg_iter;
        bt_message_iterator_get_ref(muxer_upstream_msg_iter->msg_iter);
-       muxer_upstream_msg_iter->msgs = g_queue_new();
+       muxer_upstream_msg_iter->msgs =
+               g_ptr_array_new_with_free_func((GDestroyNotify) bt_message_put_ref);
        if (!muxer_upstream_msg_iter->msgs) {
-               BT_COMP_LOGE_STR("Failed to allocate a GQueue.");
+               BT_COMP_LOGE_APPEND_CAUSE(muxer_comp->self_comp,
+                       "Failed to allocate a GPtrArray.");
                goto error;
        }
 
@@ -187,7 +174,7 @@ int muxer_msg_iter_add_upstream_msg_iter(struct muxer_msg_iter *muxer_msg_iter,
        goto end;
 
 error:
-       g_free(muxer_upstream_msg_iter);
+       destroy_muxer_upstream_msg_iter(muxer_upstream_msg_iter);
        ret = -1;
 
 end:
@@ -207,7 +194,7 @@ bt_self_component_add_port_status add_available_input_port(
        BT_ASSERT(muxer_comp);
        port_name = g_string_new("in");
        if (!port_name) {
-               BT_COMP_LOGE_STR("Failed to allocate a GString.");
+               BT_COMP_LOGE_APPEND_CAUSE(muxer_comp->self_comp, "Failed to allocate a GString.");
                status = BT_SELF_COMPONENT_ADD_PORT_STATUS_MEMORY_ERROR;
                goto end;
        }
@@ -216,7 +203,8 @@ bt_self_component_add_port_status add_available_input_port(
        status = bt_self_component_filter_add_input_port(
                self_comp, port_name->str, NULL, NULL);
        if (status != BT_SELF_COMPONENT_ADD_PORT_STATUS_OK) {
-               BT_COMP_LOGE("Cannot add input port to muxer component: "
+               BT_COMP_LOGE_APPEND_CAUSE(muxer_comp->self_comp,
+                       "Cannot add input port to muxer component: "
                        "port-name=\"%s\", comp-addr=%p, status=%s",
                        port_name->str, self_comp,
                        bt_common_func_status_string(status));
@@ -281,9 +269,15 @@ bt_component_class_initialize_method_status muxer_init(
                "comp-addr=%p, params-addr=%p", self_comp, params);
 
        if (!muxer_comp) {
+               /*
+                * Don't use BT_COMP_LOGE_APPEND_CAUSE, as `muxer_comp` is not
+                * initialized.
+                */
                BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR, log_level, self_comp,
                        "Failed to allocate one muxer component.");
-               status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR;
+               BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_COMPONENT(self_comp,
+                       "Failed to allocate one muxer component.");
+                       status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR;
                goto error;
        }
 
@@ -305,20 +299,20 @@ bt_component_class_initialize_method_status muxer_init(
        bt_self_component_set_data(self_comp, muxer_comp);
        add_port_status = add_available_input_port(self_comp_flt);
        if (add_port_status != BT_SELF_COMPONENT_ADD_PORT_STATUS_OK) {
-               BT_COMP_LOGE("Cannot ensure that at least one muxer component's input port is available: "
+               BT_COMP_LOGE_APPEND_CAUSE(self_comp,
+                       "Cannot ensure that at least one muxer component's input port is available: "
                        "muxer-comp-addr=%p, status=%s",
-                       muxer_comp,
-                       bt_common_func_status_string(add_port_status));
+                       muxer_comp, bt_common_func_status_string(add_port_status));
                status = (int) add_port_status;
                goto error;
        }
 
        add_port_status = create_output_port(self_comp_flt);
        if (add_port_status != BT_SELF_COMPONENT_ADD_PORT_STATUS_OK) {
-               BT_COMP_LOGE("Cannot create muxer component's output port: "
+               BT_COMP_LOGE_APPEND_CAUSE(self_comp,
+                       "Cannot create muxer component's output port: "
                        "muxer-comp-addr=%p, status=%s",
-                       muxer_comp,
-                       bt_common_func_status_string(add_port_status));
+                       muxer_comp, bt_common_func_status_string(add_port_status));
                status = (int) add_port_status;
                goto error;
        }
@@ -372,7 +366,8 @@ create_msg_iter_on_input_port(struct muxer_comp *muxer_comp,
        status = bt_message_iterator_create_from_message_iterator(
                muxer_msg_iter->self_msg_iter, self_port, msg_iter);
        if (status != BT_MESSAGE_ITERATOR_CREATE_FROM_MESSAGE_ITERATOR_STATUS_OK) {
-               BT_COMP_LOGE("Cannot create upstream message iterator on input port: "
+               BT_COMP_LOGE_APPEND_CAUSE(muxer_comp->self_comp,
+                       "Cannot create upstream message iterator on input port: "
                        "port-addr=%p, port-name=\"%s\"",
                        port, bt_port_get_name(port));
                goto end;
@@ -417,6 +412,9 @@ bt_message_iterator_class_next_method_status muxer_upstream_msg_iter_next(
                BT_COMP_LOGD_STR("Validated upstream message iterator wrapper.");
                BT_ASSERT_DBG(count > 0);
 
+               g_ptr_array_set_size(muxer_upstream_msg_iter->msgs, count);
+               muxer_upstream_msg_iter->next_msg = 0;
+
                /* Move messages to our queue */
                for (i = 0; i < count; i++) {
                        /*
@@ -424,8 +422,8 @@ bt_message_iterator_class_next_method_status muxer_upstream_msg_iter_next(
                         * (muxer_msg_iter_do_next_one()) consumes
                         * from the head first.
                         */
-                       g_queue_push_tail(muxer_upstream_msg_iter->msgs,
-                               (void *) msgs[i]);
+                       g_ptr_array_index(muxer_upstream_msg_iter->msgs, i)
+                               = (gpointer *) msgs[i];
                }
                status = BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK;
                break;
@@ -580,7 +578,7 @@ int get_msg_ts_ns(struct muxer_comp *muxer_comp,
 
                break;
        case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY:
-               clock_snapshot = bt_message_message_iterator_inactivity_borrow_default_clock_snapshot_const(
+               clock_snapshot = bt_message_message_iterator_inactivity_borrow_clock_snapshot_const(
                        msg);
                break;
        default:
@@ -592,7 +590,8 @@ int get_msg_ts_ns(struct muxer_comp *muxer_comp,
 
        ret = bt_clock_snapshot_get_ns_from_origin(clock_snapshot, ts_ns);
        if (ret) {
-               BT_COMP_LOGE("Cannot get nanoseconds from Epoch of clock snapshot: "
+               BT_COMP_LOGE_APPEND_CAUSE(muxer_comp->self_comp,
+                       "Cannot get nanoseconds from Epoch of clock snapshot: "
                        "clock-snapshot-addr=%p", clock_snapshot);
                goto error;
        }
@@ -667,7 +666,8 @@ int validate_clock_class(struct muxer_msg_iter *muxer_msg_iter,
        switch (muxer_msg_iter->clock_class_expectation) {
        case MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_ABSOLUTE:
                if (!bt_clock_class_origin_is_unix_epoch(clock_class)) {
-                       BT_COMP_LOGE("Expecting an absolute clock class, "
+                       BT_COMP_LOGE_APPEND_CAUSE(muxer_comp->self_comp,
+                               "Expecting an absolute clock class, "
                                "but got a non-absolute one: "
                                "clock-class-addr=%p, clock-class-name=\"%s\"",
                                clock_class, cc_name);
@@ -676,7 +676,8 @@ int validate_clock_class(struct muxer_msg_iter *muxer_msg_iter,
                break;
        case MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_NO_UUID:
                if (bt_clock_class_origin_is_unix_epoch(clock_class)) {
-                       BT_COMP_LOGE("Expecting a non-absolute clock class with no UUID, "
+                       BT_COMP_LOGE_APPEND_CAUSE(muxer_comp->self_comp,
+                               "Expecting a non-absolute clock class with no UUID, "
                                "but got an absolute one: "
                                "clock-class-addr=%p, clock-class-name=\"%s\"",
                                clock_class, cc_name);
@@ -684,7 +685,8 @@ int validate_clock_class(struct muxer_msg_iter *muxer_msg_iter,
                }
 
                if (cc_uuid) {
-                       BT_COMP_LOGE("Expecting a non-absolute clock class with no UUID, "
+                       BT_COMP_LOGE_APPEND_CAUSE(muxer_comp->self_comp,
+                               "Expecting a non-absolute clock class with no UUID, "
                                "but got one with a UUID: "
                                "clock-class-addr=%p, clock-class-name=\"%s\", "
                                "uuid=\"" BT_UUID_FMT "\"",
@@ -694,7 +696,8 @@ int validate_clock_class(struct muxer_msg_iter *muxer_msg_iter,
                break;
        case MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID:
                if (bt_clock_class_origin_is_unix_epoch(clock_class)) {
-                       BT_COMP_LOGE("Expecting a non-absolute clock class with a specific UUID, "
+                       BT_COMP_LOGE_APPEND_CAUSE(muxer_comp->self_comp,
+                               "Expecting a non-absolute clock class with a specific UUID, "
                                "but got an absolute one: "
                                "clock-class-addr=%p, clock-class-name=\"%s\"",
                                clock_class, cc_name);
@@ -702,7 +705,8 @@ int validate_clock_class(struct muxer_msg_iter *muxer_msg_iter,
                }
 
                if (!cc_uuid) {
-                       BT_COMP_LOGE("Expecting a non-absolute clock class with a specific UUID, "
+                       BT_COMP_LOGE_APPEND_CAUSE(muxer_comp->self_comp,
+                               "Expecting a non-absolute clock class with a specific UUID, "
                                "but got one with no UUID: "
                                "clock-class-addr=%p, clock-class-name=\"%s\"",
                                clock_class, cc_name);
@@ -710,7 +714,8 @@ int validate_clock_class(struct muxer_msg_iter *muxer_msg_iter,
                }
 
                if (bt_uuid_compare(muxer_msg_iter->expected_clock_class_uuid, cc_uuid) != 0) {
-                       BT_COMP_LOGE("Expecting a non-absolute clock class with a specific UUID, "
+                       BT_COMP_LOGE_APPEND_CAUSE(muxer_comp->self_comp,
+                               "Expecting a non-absolute clock class with a specific UUID, "
                                "but got one with different UUID: "
                                "clock-class-addr=%p, clock-class-name=\"%s\", "
                                "expected-uuid=\"" BT_UUID_FMT "\", "
@@ -722,7 +727,8 @@ int validate_clock_class(struct muxer_msg_iter *muxer_msg_iter,
                }
                break;
        case MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NONE:
-               BT_COMP_LOGE("Expecting no clock class, but got one: "
+               BT_COMP_LOGE_APPEND_CAUSE(muxer_comp->self_comp,
+                       "Expecting no clock class, but got one: "
                        "clock-class-addr=%p, clock-class-name=\"%s\"",
                        clock_class, cc_name);
                goto error;
@@ -761,7 +767,8 @@ int validate_new_stream_clock_class(struct muxer_msg_iter *muxer_msg_iter,
                                MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NONE;
                } else if (muxer_msg_iter->clock_class_expectation !=
                                MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NONE) {
-                       BT_COMP_LOGE("Expecting stream class without a default clock class: "
+                       BT_COMP_LOGE_APPEND_CAUSE(muxer_comp->self_comp,
+                               "Expecting stream class without a default clock class: "
                                "stream-class-addr=%p, stream-class-name=\"%s\", "
                                "stream-class-id=%" PRIu64,
                                stream_class, bt_stream_class_get_name(stream_class),
@@ -830,8 +837,10 @@ muxer_msg_iter_youngest_upstream_msg_iter(
                        continue;
                }
 
-               BT_ASSERT_DBG(cur_muxer_upstream_msg_iter->msgs->length > 0);
-               msg = g_queue_peek_head(cur_muxer_upstream_msg_iter->msgs);
+               BT_ASSERT_DBG(cur_muxer_upstream_msg_iter->next_msg <
+                       cur_muxer_upstream_msg_iter->msgs->len);
+               msg = g_ptr_array_index(cur_muxer_upstream_msg_iter->msgs,
+                       cur_muxer_upstream_msg_iter->next_msg);
                BT_ASSERT_DBG(msg);
 
                if (G_UNLIKELY(bt_message_get_type(msg) ==
@@ -852,7 +861,7 @@ muxer_msg_iter_youngest_upstream_msg_iter(
                                BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY)) {
                        const bt_clock_snapshot *cs;
 
-                       cs = bt_message_message_iterator_inactivity_borrow_default_clock_snapshot_const(
+                       cs = bt_message_message_iterator_inactivity_borrow_clock_snapshot_const(
                                msg);
                        ret = validate_clock_class(muxer_msg_iter, muxer_comp,
                                bt_clock_snapshot_borrow_clock_class_const(cs));
@@ -890,8 +899,11 @@ muxer_msg_iter_youngest_upstream_msg_iter(
                         * current candidate message. We must break the tie
                         * in a predictable manner.
                         */
-                       const bt_message *selected_msg = g_queue_peek_head(
-                               (*muxer_upstream_msg_iter)->msgs);
+                       BT_ASSERT_DBG((*muxer_upstream_msg_iter)->next_msg <
+                               (*muxer_upstream_msg_iter)->msgs->len);
+                       const bt_message *selected_msg =
+                               g_ptr_array_index((*muxer_upstream_msg_iter)->msgs,
+                                       (*muxer_upstream_msg_iter)->next_msg);
                        BT_COMP_LOGD_STR("Two of the next message candidates have the same timestamps, pick one deterministically.");
 
                        /*
@@ -941,11 +953,12 @@ validate_muxer_upstream_msg_iter(
                "muxer-upstream-msg-iter-wrap-addr=%p",
                muxer_upstream_msg_iter);
 
-       if (muxer_upstream_msg_iter->msgs->length > 0 ||
+       if (muxer_upstream_msg_iter->next_msg < muxer_upstream_msg_iter->msgs->len ||
                        !muxer_upstream_msg_iter->msg_iter) {
                BT_COMP_LOGD("Already valid or not considered: "
-                       "queue-len=%u, upstream-msg-iter-addr=%p",
-                       muxer_upstream_msg_iter->msgs->length,
+                       "queue-len=%u, next-msg=%u, upstream-msg-iter-addr=%p",
+                       muxer_upstream_msg_iter->msgs->len,
+                       muxer_upstream_msg_iter->next_msg,
                        muxer_upstream_msg_iter->msg_iter);
                status = BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK;
                goto end;
@@ -1039,7 +1052,8 @@ bt_message_iterator_class_next_method_status muxer_msg_iter_do_next_one(
 {
        bt_message_iterator_class_next_method_status status;
        struct muxer_upstream_msg_iter *muxer_upstream_msg_iter = NULL;
-       int64_t next_return_ts;
+       /* Initialize to avoid -Wmaybe-uninitialized warning with gcc 4.8. */
+       int64_t next_return_ts = 0;
 
        status = validate_muxer_upstream_msg_iters(muxer_msg_iter);
        if (status != BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK) {
@@ -1095,7 +1109,11 @@ bt_message_iterator_class_next_method_status muxer_msg_iter_do_next_one(
         * Consume from the queue's head: other side
         * (muxer_upstream_msg_iter_next()) writes to the tail.
         */
-       *msg = g_queue_pop_head(muxer_upstream_msg_iter->msgs);
+       *msg = g_ptr_array_index(muxer_upstream_msg_iter->msgs,
+               muxer_upstream_msg_iter->next_msg);
+       g_ptr_array_index(muxer_upstream_msg_iter->msgs,
+               muxer_upstream_msg_iter->next_msg) = NULL;
+       ++muxer_upstream_msg_iter->next_msg;
        BT_ASSERT_DBG(*msg);
        muxer_msg_iter->last_returned_ts_ns = next_return_ts;
 
@@ -1276,12 +1294,13 @@ BT_HIDDEN
 bt_message_iterator_class_initialize_method_status muxer_msg_iter_init(
                bt_self_message_iterator *self_msg_iter,
                bt_self_message_iterator_configuration *config,
-               bt_self_component *self_comp,
                bt_self_component_port_output *port)
 {
        struct muxer_comp *muxer_comp = NULL;
        struct muxer_msg_iter *muxer_msg_iter = NULL;
        bt_message_iterator_class_initialize_method_status status;
+       bt_self_component *self_comp =
+               bt_self_message_iterator_borrow_component(self_msg_iter);
 
        muxer_comp = bt_self_component_get_data(self_comp);
        BT_ASSERT(muxer_comp);
@@ -1295,7 +1314,8 @@ bt_message_iterator_class_initialize_method_status muxer_msg_iter_init(
                 * creates a muxer message iterator while creating
                 * another muxer message iterator (same component).
                 */
-               BT_COMP_LOGE("Recursive initialization of muxer component's message iterator: "
+               BT_COMP_LOGE_APPEND_CAUSE(muxer_comp->self_comp,
+                       "Recursive initialization of muxer component's message iterator: "
                        "comp-addr=%p, muxer-comp-addr=%p, msg-iter-addr=%p",
                        self_comp, muxer_comp, self_msg_iter);
                status = BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_ERROR;
@@ -1305,7 +1325,8 @@ bt_message_iterator_class_initialize_method_status muxer_msg_iter_init(
        muxer_comp->initializing_muxer_msg_iter = true;
        muxer_msg_iter = g_new0(struct muxer_msg_iter, 1);
        if (!muxer_msg_iter) {
-               BT_COMP_LOGE_STR("Failed to allocate one muxer component's message iterator.");
+               BT_COMP_LOGE_APPEND_CAUSE(muxer_comp->self_comp,
+                       "Failed to allocate one muxer component's message iterator.");
                status = BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR;
                goto error;
        }
@@ -1317,7 +1338,7 @@ bt_message_iterator_class_initialize_method_status muxer_msg_iter_init(
                g_ptr_array_new_with_free_func(
                        (GDestroyNotify) destroy_muxer_upstream_msg_iter);
        if (!muxer_msg_iter->active_muxer_upstream_msg_iters) {
-               BT_COMP_LOGE_STR("Failed to allocate a GPtrArray.");
+               BT_COMP_LOGE_APPEND_CAUSE(muxer_comp->self_comp, "Failed to allocate a GPtrArray.");
                status = BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR;
                goto error;
        }
@@ -1326,7 +1347,7 @@ bt_message_iterator_class_initialize_method_status muxer_msg_iter_init(
                g_ptr_array_new_with_free_func(
                        (GDestroyNotify) destroy_muxer_upstream_msg_iter);
        if (!muxer_msg_iter->ended_muxer_upstream_msg_iters) {
-               BT_COMP_LOGE_STR("Failed to allocate a GPtrArray.");
+               BT_COMP_LOGE_APPEND_CAUSE(muxer_comp->self_comp, "Failed to allocate a GPtrArray.");
                status = BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR;
                goto error;
        }
@@ -1334,7 +1355,8 @@ bt_message_iterator_class_initialize_method_status muxer_msg_iter_init(
        status = muxer_msg_iter_init_upstream_iterators(muxer_comp,
                muxer_msg_iter, config);
        if (status) {
-               BT_COMP_LOGE("Cannot initialize connected input ports for muxer component's message iterator: "
+               BT_COMP_LOGE_APPEND_CAUSE(muxer_comp->self_comp,
+                       "Cannot initialize connected input ports for muxer component's message iterator: "
                        "comp-addr=%p, muxer-comp-addr=%p, "
                        "muxer-msg-iter-addr=%p, msg-iter-addr=%p, ret=%d",
                        self_comp, muxer_comp, muxer_msg_iter,
@@ -1406,7 +1428,8 @@ bt_message_iterator_class_next_method_status muxer_msg_iter_next(
        status = muxer_msg_iter_do_next(muxer_comp, muxer_msg_iter,
                msgs, capacity, count);
        if (status < 0) {
-               BT_COMP_LOGE("Cannot get next message: "
+               BT_COMP_LOGE_APPEND_CAUSE(self_comp,
+                       "Cannot get next message: "
                        "comp-addr=%p, muxer-comp-addr=%p, muxer-msg-iter-addr=%p, "
                        "msg-iter-addr=%p, status=%s",
                        self_comp, muxer_comp, muxer_msg_iter, self_msg_iter,
@@ -1434,9 +1457,9 @@ bt_component_class_port_connected_method_status muxer_input_port_connected(
 
        add_port_status = add_available_input_port(self_comp);
        if (add_port_status) {
-               BT_COMP_LOGE("Cannot add one muxer component's input port: "
-                       "status=%s",
-                       bt_common_func_status_string(status));
+               BT_COMP_LOGE_APPEND_CAUSE(muxer_comp->self_comp,
+                       "Cannot add one muxer component's input port: status=%s",
+                       bt_common_func_status_string(add_port_status));
 
                if (add_port_status ==
                                BT_SELF_COMPONENT_ADD_PORT_STATUS_MEMORY_ERROR) {
@@ -1455,6 +1478,7 @@ end:
 static inline
 bt_message_iterator_class_can_seek_beginning_method_status
 muxer_upstream_msg_iters_can_all_seek_beginning(
+               struct muxer_comp *muxer_comp,
                GPtrArray *muxer_upstream_msg_iters, bt_bool *can_seek)
 {
        bt_message_iterator_class_can_seek_beginning_method_status status =
@@ -1467,6 +1491,9 @@ muxer_upstream_msg_iters_can_all_seek_beginning(
                status = (int) bt_message_iterator_can_seek_beginning(
                        upstream_msg_iter->msg_iter, can_seek);
                if (status != BT_MESSAGE_ITERATOR_CLASS_CAN_SEEK_BEGINNING_METHOD_STATUS_OK) {
+                       BT_COMP_LOGE_APPEND_CAUSE(muxer_comp->self_comp,
+                               "Failed to determine whether upstream message iterator can seek beginning: "
+                               "msg-iter-addr=%p", upstream_msg_iter->msg_iter);
                        goto end;
                }
 
@@ -1491,6 +1518,7 @@ muxer_msg_iter_can_seek_beginning(
        bt_message_iterator_class_can_seek_beginning_method_status status;
 
        status = muxer_upstream_msg_iters_can_all_seek_beginning(
+               muxer_msg_iter->muxer_comp,
                muxer_msg_iter->active_muxer_upstream_msg_iters, can_seek);
        if (status != BT_MESSAGE_ITERATOR_CLASS_CAN_SEEK_BEGINNING_METHOD_STATUS_OK) {
                goto end;
@@ -1501,6 +1529,7 @@ muxer_msg_iter_can_seek_beginning(
        }
 
        status = muxer_upstream_msg_iters_can_all_seek_beginning(
+               muxer_msg_iter->muxer_comp,
                muxer_msg_iter->ended_muxer_upstream_msg_iters, can_seek);
 
 end:
This page took 0.029866 seconds and 4 git commands to generate.