Make some bt_param_validation_map_value_entry_descr variables static
[babeltrace.git] / src / plugins / utils / muxer / muxer.c
index 002cd6293991bfb47b9f63adbbd3ec7978f4e8ac..f4af51c8df083765e2242c1f80d39810fb355733 100644 (file)
@@ -107,6 +107,14 @@ struct muxer_msg_iter {
         * MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID.
         */
        bt_uuid_t expected_clock_class_uuid;
+
+       /*
+        * Saved error.  If we hit an error in the _next method, but have some
+        * messages ready to return, we save the error here and return it on
+        * the next _next call.
+        */
+       bt_component_class_message_iterator_next_method_status next_saved_status;
+       const struct bt_error *next_saved_error;
 };
 
 static
@@ -247,6 +255,7 @@ void destroy_muxer_comp(struct muxer_comp *muxer_comp)
        g_free(muxer_comp);
 }
 
+static
 struct bt_param_validation_map_value_entry_descr muxer_params[] = {
        BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_END
 };
@@ -382,8 +391,7 @@ bt_component_class_message_iterator_next_method_status muxer_upstream_msg_iter_n
                struct muxer_upstream_msg_iter *muxer_upstream_msg_iter,
                bool *is_ended)
 {
-       struct muxer_comp *muxer_comp =
-               muxer_upstream_msg_iter->muxer_comp;
+       struct muxer_comp *muxer_comp = muxer_upstream_msg_iter->muxer_comp;
        bt_component_class_message_iterator_next_method_status status;
        bt_message_iterator_next_status input_port_iter_status;
        bt_message_array_const msgs;
@@ -407,7 +415,7 @@ bt_component_class_message_iterator_next_method_status muxer_upstream_msg_iter_n
                 * valid: it must be considered for muxing operations.
                 */
                BT_COMP_LOGD_STR("Validated upstream message iterator wrapper.");
-               BT_ASSERT(count > 0);
+               BT_ASSERT_DBG(count > 0);
 
                /* Move messages to our queue */
                for (i = 0; i < count; i++) {
@@ -438,10 +446,19 @@ bt_component_class_message_iterator_next_method_status muxer_upstream_msg_iter_n
                *is_ended = true;
                status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK;
                break;
+       case BT_MESSAGE_ITERATOR_NEXT_STATUS_ERROR:
+       case BT_MESSAGE_ITERATOR_NEXT_STATUS_MEMORY_ERROR:
+               /* Error status code */
+               BT_COMP_LOGE_APPEND_CAUSE(muxer_comp->self_comp,
+                       "Upstream iterator's next method returned an error: status=%s",
+                       bt_common_func_status_string(input_port_iter_status));
+               status = (int) input_port_iter_status;
+               break;
        default:
-               /* Error or unsupported status code */
-               BT_COMP_LOGE("Error or unsupported status code: "
-                       "status-code=%d", input_port_iter_status);
+               /* Unsupported status code */
+               BT_COMP_LOGE_APPEND_CAUSE(muxer_comp->self_comp,
+                       "Unsupported status code: status=%s",
+                       bt_common_func_status_string(input_port_iter_status));
                status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_ERROR;
                break;
        }
@@ -460,8 +477,8 @@ int get_msg_ts_ns(struct muxer_comp *muxer_comp,
        const bt_stream_class *stream_class = NULL;
        bt_message_type msg_type;
 
-       BT_ASSERT(msg);
-       BT_ASSERT(ts_ns);
+       BT_ASSERT_DBG(msg);
+       BT_ASSERT_DBG(ts_ns);
        BT_COMP_LOGD("Getting message's timestamp: "
                "muxer-msg-iter-addr=%p, msg-addr=%p, "
                "last-returned-ts=%" PRId64,
@@ -495,7 +512,7 @@ int get_msg_ts_ns(struct muxer_comp *muxer_comp,
 
        switch (msg_type) {
        case BT_MESSAGE_TYPE_EVENT:
-               BT_ASSERT(bt_message_event_borrow_stream_class_default_clock_class_const(
+               BT_ASSERT_DBG(bt_message_event_borrow_stream_class_default_clock_class_const(
                                msg));
                clock_snapshot = bt_message_event_borrow_default_clock_snapshot_const(
                        msg);
@@ -612,7 +629,7 @@ int validate_clock_class(struct muxer_msg_iter *muxer_msg_iter,
        const uint8_t *cc_uuid;
        const char *cc_name;
 
-       BT_ASSERT(clock_class);
+       BT_ASSERT_DBG(clock_class);
        cc_uuid = bt_clock_class_get_uuid(clock_class);
        cc_name = bt_clock_class_get_name(clock_class);
 
@@ -714,7 +731,7 @@ int validate_clock_class(struct muxer_msg_iter *muxer_msg_iter,
                BT_COMP_LOGF("Unexpected clock class expectation: "
                        "expectation-code=%d",
                        muxer_msg_iter->clock_class_expectation);
-               abort();
+               bt_common_abort();
        }
 
        goto end;
@@ -791,9 +808,9 @@ muxer_msg_iter_youngest_upstream_msg_iter(
        bt_component_class_message_iterator_next_method_status status =
                BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK;
 
-       BT_ASSERT(muxer_comp);
-       BT_ASSERT(muxer_msg_iter);
-       BT_ASSERT(muxer_upstream_msg_iter);
+       BT_ASSERT_DBG(muxer_comp);
+       BT_ASSERT_DBG(muxer_msg_iter);
+       BT_ASSERT_DBG(muxer_upstream_msg_iter);
        *muxer_upstream_msg_iter = NULL;
 
        for (i = 0; i < muxer_msg_iter->active_muxer_upstream_msg_iters->len;
@@ -813,9 +830,9 @@ muxer_msg_iter_youngest_upstream_msg_iter(
                        continue;
                }
 
-               BT_ASSERT(cur_muxer_upstream_msg_iter->msgs->length > 0);
+               BT_ASSERT_DBG(cur_muxer_upstream_msg_iter->msgs->length > 0);
                msg = g_queue_peek_head(cur_muxer_upstream_msg_iter->msgs);
-               BT_ASSERT(msg);
+               BT_ASSERT_DBG(msg);
 
                if (G_UNLIKELY(bt_message_get_type(msg) ==
                                BT_MESSAGE_TYPE_STREAM_BEGINNING)) {
@@ -917,10 +934,8 @@ validate_muxer_upstream_msg_iter(
        struct muxer_upstream_msg_iter *muxer_upstream_msg_iter,
        bool *is_ended)
 {
-       struct muxer_comp *muxer_comp =
-               muxer_upstream_msg_iter->muxer_comp;
-       bt_component_class_message_iterator_next_method_status status =
-               BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK;
+       struct muxer_comp *muxer_comp = muxer_upstream_msg_iter->muxer_comp;
+       bt_component_class_message_iterator_next_method_status status;
 
        BT_COMP_LOGD("Validating muxer's upstream message iterator wrapper: "
                "muxer-upstream-msg-iter-wrap-addr=%p",
@@ -932,6 +947,7 @@ validate_muxer_upstream_msg_iter(
                        "queue-len=%u, upstream-msg-iter-addr=%p",
                        muxer_upstream_msg_iter->msgs->length,
                        muxer_upstream_msg_iter->msg_iter);
+               status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK;
                goto end;
        }
 
@@ -949,8 +965,7 @@ validate_muxer_upstream_msg_iters(
                struct muxer_msg_iter *muxer_msg_iter)
 {
        struct muxer_comp *muxer_comp = muxer_msg_iter->muxer_comp;
-       bt_component_class_message_iterator_next_method_status status =
-               BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK;
+       bt_component_class_message_iterator_next_method_status status;
        size_t i;
 
        BT_COMP_LOGD("Validating muxer's upstream message iterator wrappers: "
@@ -968,7 +983,8 @@ validate_muxer_upstream_msg_iters(
                        muxer_upstream_msg_iter, &is_ended);
                if (status != BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK) {
                        if (status < 0) {
-                               BT_COMP_LOGE("Cannot validate muxer's upstream message iterator wrapper: "
+                               BT_COMP_LOGE_APPEND_CAUSE(muxer_comp->self_comp,
+                                       "Cannot validate muxer's upstream message iterator wrapper: "
                                        "muxer-msg-iter-addr=%p, "
                                        "muxer-upstream-msg-iter-wrap-addr=%p",
                                        muxer_msg_iter,
@@ -1009,6 +1025,8 @@ validate_muxer_upstream_msg_iters(
                }
        }
 
+       status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK;
+
 end:
        return status;
 }
@@ -1040,7 +1058,8 @@ bt_component_class_message_iterator_next_method_status muxer_msg_iter_do_next_on
                        &next_return_ts);
        if (status < 0 || status == BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_END) {
                if (status < 0) {
-                       BT_COMP_LOGE("Cannot find the youngest upstream message iterator wrapper: "
+                       BT_COMP_LOGE_APPEND_CAUSE(muxer_comp->self_comp,
+                               "Cannot find the youngest upstream message iterator wrapper: "
                                "status=%s",
                                bt_common_func_status_string(status));
                } else {
@@ -1053,7 +1072,8 @@ bt_component_class_message_iterator_next_method_status muxer_msg_iter_do_next_on
        }
 
        if (next_return_ts < muxer_msg_iter->last_returned_ts_ns) {
-               BT_COMP_LOGE("Youngest upstream message iterator wrapper's timestamp is less than muxer's message iterator's last returned timestamp: "
+               BT_COMP_LOGE_APPEND_CAUSE(muxer_comp->self_comp,
+                       "Youngest upstream message iterator wrapper's timestamp is less than muxer's message iterator's last returned timestamp: "
                        "muxer-msg-iter-addr=%p, ts=%" PRId64 ", "
                        "last-returned-ts=%" PRId64,
                        muxer_msg_iter, next_return_ts,
@@ -1067,15 +1087,16 @@ bt_component_class_message_iterator_next_method_status muxer_msg_iter_do_next_on
                "muxer-upstream-msg-iter-wrap-addr=%p, "
                "ts=%" PRId64,
                muxer_msg_iter, muxer_upstream_msg_iter, next_return_ts);
-       BT_ASSERT(status == BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK);
-       BT_ASSERT(muxer_upstream_msg_iter);
+       BT_ASSERT_DBG(status ==
+               BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK);
+       BT_ASSERT_DBG(muxer_upstream_msg_iter);
 
        /*
         * 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);
-       BT_ASSERT(*msg);
+       BT_ASSERT_DBG(*msg);
        muxer_msg_iter->last_returned_ts_ns = next_return_ts;
 
 end:
@@ -1089,17 +1110,27 @@ bt_component_class_message_iterator_next_method_status muxer_msg_iter_do_next(
                bt_message_array_const msgs, uint64_t capacity,
                uint64_t *count)
 {
-       bt_component_class_message_iterator_next_method_status status =
-               BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK;
+       bt_component_class_message_iterator_next_method_status status;
        uint64_t i = 0;
 
-       while (i < capacity && status == BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK) {
+       if (G_UNLIKELY(muxer_msg_iter->next_saved_error)) {
+               /*
+                * Last time we were called, we hit an error but had some
+                * messages to deliver, so we stashed the error here.  Return
+                * it now.
+                */
+               BT_CURRENT_THREAD_MOVE_ERROR_AND_RESET(muxer_msg_iter->next_saved_error);
+               status = muxer_msg_iter->next_saved_status;
+               goto end;
+       }
+
+       do {
                status = muxer_msg_iter_do_next_one(muxer_comp,
                        muxer_msg_iter, &msgs[i]);
                if (status == BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK) {
                        i++;
                }
-       }
+       } while (i < capacity && status == BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK);
 
        if (i > 0) {
                /*
@@ -1114,10 +1145,23 @@ bt_component_class_message_iterator_next_method_status muxer_msg_iter_do_next(
                 * called, possibly without any accumulated
                 * message, in which case we'll return it.
                 */
+               if (status < 0) {
+                       /*
+                        * Save this error for the next _next call.  Assume that
+                        * this component always appends error causes when
+                        * returning an error status code, which will cause the
+                        * current thread error to be non-NULL.
+                        */
+                       muxer_msg_iter->next_saved_error = bt_current_thread_take_error();
+                       BT_ASSERT(muxer_msg_iter->next_saved_error);
+                       muxer_msg_iter->next_saved_status = status;
+               }
+
                *count = i;
                status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK;
        }
 
+end:
        return status;
 }
 
@@ -1349,12 +1393,12 @@ bt_component_class_message_iterator_next_method_status muxer_msg_iter_next(
        bt_self_component *self_comp = NULL;
        struct muxer_comp *muxer_comp = NULL;
 
-       BT_ASSERT(muxer_msg_iter);
+       BT_ASSERT_DBG(muxer_msg_iter);
        self_comp = bt_self_message_iterator_borrow_component(
                self_msg_iter);
-       BT_ASSERT(self_comp);
+       BT_ASSERT_DBG(self_comp);
        muxer_comp = bt_self_component_get_data(self_comp);
-       BT_ASSERT(muxer_comp);
+       BT_ASSERT_DBG(muxer_comp);
        BT_COMP_LOGT("Muxer component's message iterator's \"next\" method called: "
                "comp-addr=%p, muxer-comp-addr=%p, muxer-msg-iter-addr=%p, "
                "msg-iter-addr=%p",
This page took 0.029098 seconds and 4 git commands to generate.