X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fplugins%2Futils%2Fmuxer%2Fmuxer.c;h=18e716bd7cae2cd9f8052c10cd328394a8f881d0;hb=98b15851a941e7342b8bb19e265cdc3a40fabfb8;hp=12485df8cd8cda896b62d42bf6bf508f05c654c4;hpb=c4b56970e243138c6a6c790effbef58e1ae22513;p=babeltrace.git diff --git a/src/plugins/utils/muxer/muxer.c b/src/plugins/utils/muxer/muxer.c index 12485df8..18e716bd 100644 --- a/src/plugins/utils/muxer/muxer.c +++ b/src/plugins/utils/muxer/muxer.c @@ -37,6 +37,7 @@ #include #include "plugins/common/muxing/muxing.h" +#include "plugins/common/param-validation/param-validation.h" #include "muxer.h" @@ -246,19 +247,25 @@ void destroy_muxer_comp(struct muxer_comp *muxer_comp) g_free(muxer_comp); } +struct bt_param_validation_map_value_entry_descr muxer_params[] = { + BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_END +}; + BT_HIDDEN -bt_component_class_init_method_status muxer_init( +bt_component_class_initialize_method_status muxer_init( bt_self_component_filter *self_comp_flt, + bt_self_component_filter_configuration *config, const bt_value *params, void *init_data) { - bt_component_class_init_method_status status = - BT_COMPONENT_CLASS_INIT_METHOD_STATUS_OK; + bt_component_class_initialize_method_status status; bt_self_component_add_port_status add_port_status; bt_self_component *self_comp = bt_self_component_filter_as_self_component(self_comp_flt); struct muxer_comp *muxer_comp = g_new0(struct muxer_comp, 1); bt_logging_level log_level = bt_component_get_logging_level( bt_self_component_as_component(self_comp)); + enum bt_param_validation_status validation_status; + gchar *validate_error = NULL; BT_COMP_LOG_CUR_LVL(BT_LOG_INFO, log_level, self_comp, "Initializing muxer component: " @@ -267,6 +274,7 @@ bt_component_class_init_method_status muxer_init( if (!muxer_comp) { 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; goto error; } @@ -274,6 +282,17 @@ bt_component_class_init_method_status muxer_init( muxer_comp->self_comp = self_comp; muxer_comp->self_comp_flt = self_comp_flt; + validation_status = bt_param_validation_validate(params, + muxer_params, &validate_error); + if (validation_status == BT_PARAM_VALIDATION_STATUS_MEMORY_ERROR) { + status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR; + goto error; + } else if (validation_status == BT_PARAM_VALIDATION_STATUS_VALIDATION_ERROR) { + status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR; + BT_COMP_LOGE_APPEND_CAUSE(self_comp, "%s", validate_error); + goto error; + } + 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) { @@ -281,13 +300,7 @@ bt_component_class_init_method_status muxer_init( "muxer-comp-addr=%p, status=%s", muxer_comp, bt_common_func_status_string(add_port_status)); - if (add_port_status == - BT_SELF_COMPONENT_ADD_PORT_STATUS_MEMORY_ERROR) { - status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_MEMORY_ERROR; - } else { - status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_ERROR; - } - + status = (int) add_port_status; goto error; } @@ -297,13 +310,7 @@ bt_component_class_init_method_status muxer_init( "muxer-comp-addr=%p, status=%s", muxer_comp, bt_common_func_status_string(add_port_status)); - if (add_port_status == - BT_SELF_COMPONENT_ADD_PORT_STATUS_MEMORY_ERROR) { - status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_MEMORY_ERROR; - } else { - status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_ERROR; - } - + status = (int) add_port_status; goto error; } @@ -311,17 +318,15 @@ bt_component_class_init_method_status muxer_init( "comp-addr=%p, params-addr=%p, muxer-comp-addr=%p", self_comp, params, muxer_comp); + status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK; goto end; error: destroy_muxer_comp(muxer_comp); bt_self_component_set_data(self_comp, NULL); - if (status == BT_COMPONENT_CLASS_INIT_METHOD_STATUS_OK) { - status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_ERROR; - } - end: + g_free(validate_error); return status; } @@ -402,7 +407,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++) { @@ -455,8 +460,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, @@ -490,7 +495,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); @@ -607,7 +612,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); @@ -786,9 +791,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; @@ -808,9 +813,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)) { @@ -1062,15 +1067,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: @@ -1145,13 +1151,15 @@ void destroy_muxer_msg_iter(struct muxer_msg_iter *muxer_msg_iter) } static -bt_component_class_message_iterator_init_method_status +bt_component_class_message_iterator_initialize_method_status muxer_msg_iter_init_upstream_iterators(struct muxer_comp *muxer_comp, - struct muxer_msg_iter *muxer_msg_iter) + struct muxer_msg_iter *muxer_msg_iter, + struct bt_self_message_iterator_configuration *config) { int64_t count; int64_t i; - bt_component_class_message_iterator_init_method_status status; + bt_component_class_message_iterator_initialize_method_status status; + bool can_seek_forward = true; count = bt_component_filter_get_input_port_count( bt_self_component_filter_as_component_filter( @@ -1160,7 +1168,7 @@ muxer_msg_iter_init_upstream_iterators(struct muxer_comp *muxer_comp, BT_COMP_LOGD("No input port to initialize for muxer component's message iterator: " "muxer-comp-addr=%p, muxer-msg-iter-addr=%p", muxer_comp, muxer_msg_iter); - status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INIT_METHOD_STATUS_OK; + status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INITIALIZE_METHOD_STATUS_OK; goto end; } @@ -1198,27 +1206,39 @@ muxer_msg_iter_init_upstream_iterators(struct muxer_comp *muxer_comp, bt_self_component_port_input_message_iterator_put_ref( upstream_msg_iter); if (int_status) { - status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INIT_METHOD_STATUS_ERROR; + status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INITIALIZE_METHOD_STATUS_ERROR; /* muxer_msg_iter_add_upstream_msg_iter() logs errors */ goto end; } + + can_seek_forward = can_seek_forward && + bt_self_component_port_input_message_iterator_can_seek_forward( + upstream_msg_iter); } - status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INIT_METHOD_STATUS_OK; + /* + * This iterator can seek forward if all of its iterators can seek + * forward. + */ + bt_self_message_iterator_configuration_set_can_seek_forward( + config, can_seek_forward); + + status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INITIALIZE_METHOD_STATUS_OK; end: return status; } BT_HIDDEN -bt_component_class_message_iterator_init_method_status muxer_msg_iter_init( +bt_component_class_message_iterator_initialize_method_status muxer_msg_iter_init( bt_self_message_iterator *self_msg_iter, + bt_self_message_iterator_configuration *config, bt_self_component_filter *self_comp, bt_self_component_port_output *port) { struct muxer_comp *muxer_comp = NULL; struct muxer_msg_iter *muxer_msg_iter = NULL; - bt_component_class_message_iterator_init_method_status status; + bt_component_class_message_iterator_initialize_method_status status; muxer_comp = bt_self_component_get_data( bt_self_component_filter_as_self_component(self_comp)); @@ -1236,7 +1256,7 @@ bt_component_class_message_iterator_init_method_status muxer_msg_iter_init( BT_COMP_LOGE("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_COMPONENT_CLASS_MESSAGE_ITERATOR_INIT_METHOD_STATUS_ERROR; + status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INITIALIZE_METHOD_STATUS_ERROR; goto error; } @@ -1244,7 +1264,7 @@ bt_component_class_message_iterator_init_method_status muxer_msg_iter_init( 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."); - status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INIT_METHOD_STATUS_MEMORY_ERROR; + status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INITIALIZE_METHOD_STATUS_MEMORY_ERROR; goto error; } @@ -1256,7 +1276,7 @@ bt_component_class_message_iterator_init_method_status muxer_msg_iter_init( (GDestroyNotify) destroy_muxer_upstream_msg_iter); if (!muxer_msg_iter->active_muxer_upstream_msg_iters) { BT_COMP_LOGE_STR("Failed to allocate a GPtrArray."); - status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INIT_METHOD_STATUS_MEMORY_ERROR; + status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INITIALIZE_METHOD_STATUS_MEMORY_ERROR; goto error; } @@ -1265,12 +1285,12 @@ bt_component_class_message_iterator_init_method_status muxer_msg_iter_init( (GDestroyNotify) destroy_muxer_upstream_msg_iter); if (!muxer_msg_iter->ended_muxer_upstream_msg_iters) { BT_COMP_LOGE_STR("Failed to allocate a GPtrArray."); - status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INIT_METHOD_STATUS_MEMORY_ERROR; + status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INITIALIZE_METHOD_STATUS_MEMORY_ERROR; goto error; } status = muxer_msg_iter_init_upstream_iterators(muxer_comp, - muxer_msg_iter); + muxer_msg_iter, config); if (status) { BT_COMP_LOGE("Cannot initialize connected input ports for muxer component's message iterator: " "comp-addr=%p, muxer-comp-addr=%p, " @@ -1330,12 +1350,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",