tap-driver.sh: flush stdout after each test result
[babeltrace.git] / plugins / text / pretty / pretty.c
index 30d7d54f2da65fe2054697ecb1b71ef3a69e2b87..7c548391ab79e4cecf8d33a0fccd47715b011cf6 100644 (file)
  * SOFTWARE.
  */
 
-#include <babeltrace/babeltrace.h>
-#include <babeltrace/values.h>
-#include <babeltrace/compiler-internal.h>
-#include <babeltrace/common-internal.h>
+#define BT_LOG_TAG "PLUGIN-TEXT-PRETTY-SINK"
+#include "logging.h"
+
+#include <babeltrace2/babeltrace.h>
+#include <babeltrace2/compiler-internal.h>
+#include <babeltrace2/common-internal.h>
 #include <plugins-common.h>
 #include <stdio.h>
 #include <stdbool.h>
 #include <glib.h>
-#include <babeltrace/assert-internal.h>
+#include <babeltrace2/assert-internal.h>
 
 #include "pretty.h"
 
@@ -63,10 +65,13 @@ const char *plugin_options[] = {
        "field-callsite",
 };
 
+static
+const char * const in_port_name = "in";
+
 static
 void destroy_pretty_data(struct pretty_component *pretty)
 {
-       bt_object_put_ref(pretty->iterator);
+       bt_self_component_port_input_message_iterator_put_ref(pretty->iterator);
 
        if (pretty->string) {
                (void) g_string_free(pretty->string, TRUE);
@@ -114,36 +119,37 @@ error:
 }
 
 BT_HIDDEN
-void pretty_finalize(struct bt_self_component_sink *comp)
+void pretty_finalize(bt_self_component_sink *comp)
 {
        destroy_pretty_data(
                bt_self_component_get_data(
-                       bt_self_component_sink_borrow_self_component(comp)));
+                       bt_self_component_sink_as_self_component(comp)));
 }
 
 static
-enum bt_self_component_status handle_notification(
+bt_self_component_status handle_message(
                struct pretty_component *pretty,
-               struct bt_notification *notification)
+               const bt_message *message)
 {
-       enum bt_self_component_status ret = BT_SELF_COMPONENT_STATUS_OK;
+       bt_self_component_status ret = BT_SELF_COMPONENT_STATUS_OK;
 
        BT_ASSERT(pretty);
 
-       switch (bt_notification_get_type(notification)) {
-       case BT_NOTIFICATION_TYPE_PACKET_BEGIN:
-               if (pretty_print_packet(pretty, notification)) {
+       switch (bt_message_get_type(message)) {
+       case BT_MESSAGE_TYPE_EVENT:
+               if (pretty_print_event(pretty, message)) {
                        ret = BT_SELF_COMPONENT_STATUS_ERROR;
                }
                break;
-       case BT_NOTIFICATION_TYPE_EVENT:
-               if (pretty_print_event(pretty, notification)) {
+       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;
                }
                break;
-       case BT_NOTIFICATION_TYPE_INACTIVITY:
-               fprintf(stderr, "Inactivity notification\n");
-               break;
        default:
                break;
        }
@@ -152,20 +158,19 @@ enum bt_self_component_status handle_notification(
 }
 
 BT_HIDDEN
-enum bt_self_component_status pretty_port_connected(
-               struct bt_self_component_sink *comp,
-               struct bt_self_component_port_input *self_port,
-               struct bt_port_output *other_port)
+bt_self_component_status pretty_graph_is_configured(
+               bt_self_component_sink *comp)
 {
-       enum bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK;
+       bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK;
        struct pretty_component *pretty;
 
        pretty = bt_self_component_get_data(
-                       bt_self_component_sink_borrow_self_component(comp));
+                       bt_self_component_sink_as_self_component(comp));
        BT_ASSERT(pretty);
        BT_ASSERT(!pretty->iterator);
-       pretty->iterator = bt_self_component_port_input_notification_iterator_create(
-               self_port);
+       pretty->iterator = bt_self_component_port_input_message_iterator_create(
+               bt_self_component_sink_borrow_input_port_by_name(comp,
+                       in_port_name));
        if (!pretty->iterator) {
                status = BT_SELF_COMPONENT_STATUS_NOMEM;
        }
@@ -174,70 +179,71 @@ enum bt_self_component_status pretty_port_connected(
 }
 
 BT_HIDDEN
-enum bt_self_component_status pretty_consume(
-               struct bt_self_component_sink *comp)
+bt_self_component_status pretty_consume(
+               bt_self_component_sink *comp)
 {
-       enum bt_self_component_status ret;
-       bt_notification_array notifs;
-       struct bt_self_component_port_input_notification_iterator *it;
+       bt_self_component_status ret;
+       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_borrow_self_component(comp));
-       enum bt_notification_iterator_status it_ret;
+               bt_self_component_sink_as_self_component(comp));
+       bt_message_iterator_status it_ret;
        uint64_t count = 0;
        uint64_t i = 0;
 
        it = pretty->iterator;
-       it_ret = bt_self_component_port_input_notification_iterator_next(it,
-               &notifs, &count);
+       it_ret = bt_self_component_port_input_message_iterator_next(it,
+               &msgs, &count);
 
        switch (it_ret) {
-       case BT_NOTIFICATION_ITERATOR_STATUS_OK:
+       case BT_MESSAGE_ITERATOR_STATUS_OK:
                break;
-       case BT_NOTIFICATION_ITERATOR_STATUS_NOMEM:
+       case BT_MESSAGE_ITERATOR_STATUS_NOMEM:
                ret = BT_SELF_COMPONENT_STATUS_NOMEM;
                goto end;
-       case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN:
+       case BT_MESSAGE_ITERATOR_STATUS_AGAIN:
                ret = BT_SELF_COMPONENT_STATUS_AGAIN;
                goto end;
-       case BT_NOTIFICATION_ITERATOR_STATUS_END:
+       case BT_MESSAGE_ITERATOR_STATUS_END:
                ret = BT_SELF_COMPONENT_STATUS_END;
-               BT_OBJECT_PUT_REF_AND_RESET(pretty->iterator);
+               BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_PUT_REF_AND_RESET(
+                       pretty->iterator);
                goto end;
        default:
                ret = BT_SELF_COMPONENT_STATUS_ERROR;
                goto end;
        }
 
-       BT_ASSERT(it_ret == BT_NOTIFICATION_ITERATOR_STATUS_OK);
+       BT_ASSERT(it_ret == BT_MESSAGE_ITERATOR_STATUS_OK);
 
        for (i = 0; i < count; i++) {
-               ret = handle_notification(pretty, notifs[i]);
+               ret = handle_message(pretty, msgs[i]);
                if (ret) {
                        goto end;
                }
 
-               bt_object_put_ref(notifs[i]);
+               bt_message_put_ref(msgs[i]);
        }
 
 end:
        for (; i < count; i++) {
-               bt_object_put_ref(notifs[i]);
+               bt_message_put_ref(msgs[i]);
        }
 
        return ret;
 }
 
 static
-int add_params_to_map(struct bt_private_value *plugin_opt_map)
+int add_params_to_map(bt_value *plugin_opt_map)
 {
        int ret = 0;
        unsigned int i;
 
        for (i = 0; i < BT_ARRAY_SIZE(plugin_options); i++) {
                const char *key = plugin_options[i];
-               enum bt_value_status status;
+               bt_value_status status;
 
-               status = bt_private_value_map_insert_entry(plugin_opt_map, key,
+               status = bt_value_map_insert_entry(plugin_opt_map, key,
                        bt_value_null);
                switch (status) {
                case BT_VALUE_STATUS_OK:
@@ -252,13 +258,13 @@ end:
 }
 
 static
-bt_bool check_param_exists(const char *key, struct bt_value *object, void *data)
+bt_bool check_param_exists(const char *key, const bt_value *object,
+               void *data)
 {
        struct pretty_component *pretty = data;
 
-       if (!bt_value_map_has_entry(
-                       bt_private_value_borrow_value(pretty->plugin_opt_map),
-                       key)) {
+       if (!bt_value_map_has_entry(pretty->plugin_opt_map,
+                                   key)) {
                fprintf(pretty->err,
                        "[warning] Parameter \"%s\" unknown to \"text.pretty\" sink component\n", key);
        }
@@ -266,12 +272,12 @@ bt_bool check_param_exists(const char *key, struct bt_value *object, void *data)
 }
 
 static
-void apply_one_string(const char *key, struct bt_value *params, char **option)
+void apply_one_string(const char *key, const bt_value *params, char **option)
 {
-       struct bt_value *value = NULL;
+       const bt_value *value = NULL;
        const char *str;
 
-       value = bt_value_map_borrow_entry_value(params, key);
+       value = bt_value_map_borrow_entry_value_const(params, key);
        if (!value) {
                goto end;
        }
@@ -286,13 +292,13 @@ end:
 }
 
 static
-void apply_one_bool(const char *key, struct bt_value *params, bool *option,
+void apply_one_bool(const char *key, const bt_value *params, bool *option,
                bool *found)
 {
-       struct bt_value *value = NULL;
+       const bt_value *value = NULL;
        bt_bool bool_val;
 
-       value = bt_value_map_borrow_entry_value(params, key);
+       value = bt_value_map_borrow_entry_value_const(params, key);
        if (!value) {
                goto end;
        }
@@ -337,14 +343,14 @@ end:
 }
 
 static
-int apply_params(struct pretty_component *pretty, struct bt_value *params)
+int apply_params(struct pretty_component *pretty, const bt_value *params)
 {
        int ret = 0;
-       enum bt_value_status status;
+       bt_value_status status;
        bool value, found;
        char *str = NULL;
 
-       pretty->plugin_opt_map = bt_private_value_map_create();
+       pretty->plugin_opt_map = bt_value_map_create();
        if (!pretty->plugin_opt_map) {
                ret = -1;
                goto end;
@@ -354,7 +360,8 @@ int apply_params(struct pretty_component *pretty, struct bt_value *params)
                goto end;
        }
        /* Report unknown parameters. */
-       status = bt_value_map_foreach_entry(params, check_param_exists, pretty);
+       status = bt_value_map_foreach_entry_const(params,
+               check_param_exists, pretty);
        switch (status) {
        case BT_VALUE_STATUS_OK:
                break;
@@ -365,10 +372,11 @@ int apply_params(struct pretty_component *pretty, struct bt_value *params)
        /* Known parameters. */
        pretty->options.color = PRETTY_COLOR_OPT_AUTO;
        if (bt_value_map_has_entry(params, "color")) {
-               struct bt_value *color_value;
+               const bt_value *color_value;
                const char *color;
 
-               color_value = bt_value_map_borrow_entry_value(params, "color");
+               color_value = bt_value_map_borrow_entry_value_const(params,
+                       "color");
                if (!color_value) {
                        goto end;
                }
@@ -591,7 +599,7 @@ int apply_params(struct pretty_component *pretty, struct bt_value *params)
        }
 
 end:
-       bt_object_put_ref(pretty->plugin_opt_map);
+       bt_value_put_ref(pretty->plugin_opt_map);
        pretty->plugin_opt_map = NULL;
        g_free(str);
        return ret;
@@ -634,12 +642,12 @@ void init_stream_packet_context_quarks(void)
 }
 
 BT_HIDDEN
-enum bt_self_component_status pretty_init(
-               struct bt_self_component_sink *comp,
-               struct bt_value *params,
+bt_self_component_status pretty_init(
+               bt_self_component_sink *comp,
+               const bt_value *params,
                UNUSED_VAR void *init_method_data)
 {
-       enum bt_self_component_status ret;
+       bt_self_component_status ret;
        struct pretty_component *pretty = create_pretty();
 
        if (!pretty) {
@@ -647,7 +655,8 @@ enum bt_self_component_status pretty_init(
                goto end;
        }
 
-       ret = bt_self_component_sink_add_input_port(comp, "in", NULL, NULL);
+       ret = bt_self_component_sink_add_input_port(comp, in_port_name,
+               NULL, NULL);
        if (ret != BT_SELF_COMPONENT_STATUS_OK) {
                goto end;
        }
@@ -668,7 +677,7 @@ enum bt_self_component_status pretty_init(
 
        set_use_colors(pretty);
        bt_self_component_set_data(
-               bt_self_component_sink_borrow_self_component(comp), pretty);
+               bt_self_component_sink_as_self_component(comp), pretty);
        init_stream_packet_context_quarks();
 
 end:
This page took 0.027914 seconds and 4 git commands to generate.