X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=src%2Fplugins%2Ftext%2Fpretty%2Fpretty.c;h=5c0aae8209ab8ab487dba183ccc217f515c94663;hp=9db8770e8866c47e418c7e249e6aaa36b88e2bca;hb=2f84c7be554aebca849861b481241a7b17dd1a8a;hpb=578e048b5debf169e286e5b5cc747b5d6c16886d diff --git a/src/plugins/text/pretty/pretty.c b/src/plugins/text/pretty/pretty.c index 9db8770e..5c0aae82 100644 --- a/src/plugins/text/pretty/pretty.c +++ b/src/plugins/text/pretty/pretty.c @@ -23,22 +23,17 @@ * SOFTWARE. */ -#define BT_LOG_TAG "PLUGIN-TEXT-PRETTY-SINK" -#include "logging.h" - #include #include "compat/compiler.h" #include "common/common.h" -#include "plugins/plugins-common.h" #include #include #include +#include #include "common/assert.h" #include "pretty.h" -GQuark stream_packet_context_quarks[STREAM_PACKET_CONTEXT_QUARKS_LEN]; - static const char *plugin_options[] = { "color", @@ -127,27 +122,25 @@ void pretty_finalize(bt_self_component_sink *comp) } static -bt_self_component_status handle_message( +bt_component_class_message_iterator_next_method_status handle_message( struct pretty_component *pretty, const bt_message *message) { - bt_self_component_status ret = BT_SELF_COMPONENT_STATUS_OK; + bt_component_class_message_iterator_next_method_status ret = + BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK; BT_ASSERT(pretty); switch (bt_message_get_type(message)) { case BT_MESSAGE_TYPE_EVENT: if (pretty_print_event(pretty, message)) { - ret = BT_SELF_COMPONENT_STATUS_ERROR; + ret = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_ERROR; } break; - case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY: - BT_LOGD_STR("Message iterator inactivity message."); - break; case BT_MESSAGE_TYPE_DISCARDED_EVENTS: case BT_MESSAGE_TYPE_DISCARDED_PACKETS: if (pretty_print_discarded_items(pretty, message)) { - ret = BT_SELF_COMPONENT_STATUS_ERROR; + ret = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_ERROR; } break; default: @@ -158,10 +151,11 @@ bt_self_component_status handle_message( } BT_HIDDEN -bt_self_component_status pretty_graph_is_configured( - bt_self_component_sink *comp) +bt_component_class_sink_graph_is_configured_method_status +pretty_graph_is_configured(bt_self_component_sink *comp) { - bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK; + bt_component_class_sink_graph_is_configured_method_status status = + BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_OK; struct pretty_component *pretty; pretty = bt_self_component_get_data( @@ -172,52 +166,51 @@ bt_self_component_status pretty_graph_is_configured( bt_self_component_sink_borrow_input_port_by_name(comp, in_port_name)); if (!pretty->iterator) { - status = BT_SELF_COMPONENT_STATUS_NOMEM; + status = BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_ERROR; } return status; } BT_HIDDEN -bt_self_component_status pretty_consume( +bt_component_class_sink_consume_method_status pretty_consume( bt_self_component_sink *comp) { - bt_self_component_status ret; + bt_component_class_sink_consume_method_status ret = + BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK; bt_message_array_const msgs; bt_self_component_port_input_message_iterator *it; struct pretty_component *pretty = bt_self_component_get_data( bt_self_component_sink_as_self_component(comp)); - bt_message_iterator_status it_ret; + bt_message_iterator_next_status next_status; uint64_t count = 0; uint64_t i = 0; it = pretty->iterator; - it_ret = bt_self_component_port_input_message_iterator_next(it, + next_status = bt_self_component_port_input_message_iterator_next(it, &msgs, &count); - switch (it_ret) { - case BT_MESSAGE_ITERATOR_STATUS_OK: + switch (next_status) { + case BT_MESSAGE_ITERATOR_NEXT_STATUS_OK: break; - case BT_MESSAGE_ITERATOR_STATUS_NOMEM: - ret = BT_SELF_COMPONENT_STATUS_NOMEM; + case BT_MESSAGE_ITERATOR_NEXT_STATUS_MEMORY_ERROR: + case BT_MESSAGE_ITERATOR_NEXT_STATUS_AGAIN: + ret = (int) next_status; goto end; - case BT_MESSAGE_ITERATOR_STATUS_AGAIN: - ret = BT_SELF_COMPONENT_STATUS_AGAIN; - goto end; - case BT_MESSAGE_ITERATOR_STATUS_END: - ret = BT_SELF_COMPONENT_STATUS_END; + case BT_MESSAGE_ITERATOR_NEXT_STATUS_END: + ret = (int) next_status; BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_PUT_REF_AND_RESET( pretty->iterator); goto end; default: - ret = BT_SELF_COMPONENT_STATUS_ERROR; + ret = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR; goto end; } - BT_ASSERT(it_ret == BT_MESSAGE_ITERATOR_STATUS_OK); + BT_ASSERT(next_status == BT_MESSAGE_ITERATOR_NEXT_STATUS_OK); for (i = 0; i < count; i++) { - ret = handle_message(pretty, msgs[i]); + ret = (int) handle_message(pretty, msgs[i]); if (ret) { goto end; } @@ -241,18 +234,14 @@ int add_params_to_map(bt_value *plugin_opt_map) for (i = 0; i < BT_ARRAY_SIZE(plugin_options); i++) { const char *key = plugin_options[i]; - bt_value_status status; - - status = bt_value_map_insert_entry(plugin_opt_map, key, - bt_value_null); - switch (status) { - case BT_VALUE_STATUS_OK: - break; - default: + + if (bt_value_map_insert_entry(plugin_opt_map, key, + bt_value_null) < 0) { ret = -1; goto end; } } + end: return ret; } @@ -346,7 +335,6 @@ static int apply_params(struct pretty_component *pretty, const bt_value *params) { int ret = 0; - bt_value_status status; bool value, found; char *str = NULL; @@ -360,15 +348,12 @@ int apply_params(struct pretty_component *pretty, const bt_value *params) goto end; } /* Report unknown parameters. */ - status = bt_value_map_foreach_entry_const(params, - check_param_exists, pretty); - switch (status) { - case BT_VALUE_STATUS_OK: - break; - default: + if (bt_value_map_foreach_entry_const(params, + check_param_exists, pretty) < 0) { ret = -1; goto end; } + /* Known parameters. */ pretty->options.color = PRETTY_COLOR_OPT_AUTO; if (bt_value_map_has_entry(params, "color")) { @@ -428,9 +413,9 @@ int apply_params(struct pretty_component *pretty, const bt_value *params) apply_one_string("name-default", params, &str); if (!str) { pretty->options.name_default = PRETTY_DEFAULT_UNSET; - } else if (!strcmp(str, "show")) { + } else if (strcmp(str, "show") == 0) { pretty->options.name_default = PRETTY_DEFAULT_SHOW; - } else if (!strcmp(str, "hide")) { + } else if (strcmp(str, "hide") == 0) { pretty->options.name_default = PRETTY_DEFAULT_HIDE; } else { ret = -1; @@ -495,9 +480,9 @@ int apply_params(struct pretty_component *pretty, const bt_value *params) apply_one_string("field-default", params, &str); if (!str) { pretty->options.field_default = PRETTY_DEFAULT_UNSET; - } else if (!strcmp(str, "show")) { + } else if (strcmp(str, "show") == 0) { pretty->options.field_default = PRETTY_DEFAULT_SHOW; - } else if (!strcmp(str, "hide")) { + } else if (strcmp(str, "hide") == 0) { pretty->options.field_default = PRETTY_DEFAULT_HIDE; } else { ret = -1; @@ -622,43 +607,24 @@ void set_use_colors(struct pretty_component *pretty) } } -static -void init_stream_packet_context_quarks(void) -{ - stream_packet_context_quarks[Q_TIMESTAMP_BEGIN] = - g_quark_from_string("timestamp_begin"); - stream_packet_context_quarks[Q_TIMESTAMP_BEGIN] = - g_quark_from_string("timestamp_begin"); - stream_packet_context_quarks[Q_TIMESTAMP_END] = - g_quark_from_string("timestamp_end"); - stream_packet_context_quarks[Q_EVENTS_DISCARDED] = - g_quark_from_string("events_discarded"); - stream_packet_context_quarks[Q_CONTENT_SIZE] = - g_quark_from_string("content_size"); - stream_packet_context_quarks[Q_PACKET_SIZE] = - g_quark_from_string("packet_size"); - stream_packet_context_quarks[Q_PACKET_SEQ_NUM] = - g_quark_from_string("packet_seq_num"); -} - BT_HIDDEN -bt_self_component_status pretty_init( - bt_self_component_sink *comp, - const bt_value *params, - UNUSED_VAR void *init_method_data) +bt_component_class_init_method_status pretty_init( + bt_self_component_sink *comp, const bt_value *params, + __attribute__((unused)) void *init_method_data) { - bt_self_component_status ret; + bt_component_class_init_method_status ret = + BT_COMPONENT_CLASS_INIT_METHOD_STATUS_OK; struct pretty_component *pretty = create_pretty(); if (!pretty) { - ret = BT_SELF_COMPONENT_STATUS_NOMEM; + ret = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_MEMORY_ERROR; goto end; } - ret = bt_self_component_sink_add_input_port(comp, in_port_name, - NULL, NULL); - if (ret != BT_SELF_COMPONENT_STATUS_OK) { - goto end; + if (bt_self_component_sink_add_input_port(comp, + in_port_name, NULL, NULL) < 0) { + ret = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_MEMORY_ERROR; + goto error; } pretty->out = stdout; @@ -671,14 +637,13 @@ bt_self_component_status pretty_init( pretty->last_real_timestamp = -1ULL; if (apply_params(pretty, params)) { - ret = BT_SELF_COMPONENT_STATUS_ERROR; + ret = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_ERROR; goto error; } set_use_colors(pretty); bt_self_component_set_data( bt_self_component_sink_as_self_component(comp), pretty); - init_stream_packet_context_quarks(); end: return ret;