lib: simplify the public notification iterator interfaces
[babeltrace.git] / plugins / text / pretty / pretty.c
index ad76d8237fe503e0cb931e8575bbc744f7319ee1..776266765e25a99656ce799813de158459070012 100644 (file)
@@ -35,7 +35,7 @@
 #include <stdio.h>
 #include <stdbool.h>
 #include <glib.h>
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
 
 #include "pretty.h"
 
@@ -131,7 +131,7 @@ enum bt_component_status handle_notification(struct pretty_component *pretty,
 {
        enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
 
-       assert(pretty);
+       BT_ASSERT(pretty);
 
        switch (bt_notification_get_type(notification)) {
        case BT_NOTIFICATION_TYPE_EVENT:
@@ -140,17 +140,12 @@ enum bt_component_status handle_notification(struct pretty_component *pretty,
        case BT_NOTIFICATION_TYPE_INACTIVITY:
                fprintf(stderr, "Inactivity notification\n");
                break;
-       case BT_NOTIFICATION_TYPE_PACKET_BEGIN:
-       case BT_NOTIFICATION_TYPE_PACKET_END:
-       case BT_NOTIFICATION_TYPE_STREAM_BEGIN:
-       case BT_NOTIFICATION_TYPE_STREAM_END:
-               break;
        case BT_NOTIFICATION_TYPE_DISCARDED_PACKETS:
        case BT_NOTIFICATION_TYPE_DISCARDED_EVENTS:
                ret = pretty_print_discarded_elements(pretty, notification);
                break;
        default:
-               fprintf(stderr, "Unhandled notification type\n");
+               break;
        }
 
        return ret;
@@ -165,20 +160,14 @@ void pretty_port_connected(
        enum bt_connection_status conn_status;
        struct bt_private_connection *connection;
        struct pretty_component *pretty;
-       static const enum bt_notification_type notif_types[] = {
-               BT_NOTIFICATION_TYPE_EVENT,
-               BT_NOTIFICATION_TYPE_DISCARDED_PACKETS,
-               BT_NOTIFICATION_TYPE_DISCARDED_EVENTS,
-               BT_NOTIFICATION_TYPE_SENTINEL,
-       };
 
        pretty = bt_private_component_get_user_data(component);
-       assert(pretty);
-       assert(!pretty->input_iterator);
+       BT_ASSERT(pretty);
+       BT_ASSERT(!pretty->input_iterator);
        connection = bt_private_port_get_private_connection(self_port);
-       assert(connection);
+       BT_ASSERT(connection);
        conn_status = bt_private_connection_create_notification_iterator(
-               connection, notif_types, &pretty->input_iterator);
+               connection, &pretty->input_iterator);
        if (conn_status != BT_CONNECTION_STATUS_OK) {
                pretty->error = true;
        }
@@ -190,7 +179,7 @@ BT_HIDDEN
 enum bt_component_status pretty_consume(struct bt_private_component *component)
 {
        enum bt_component_status ret;
-       struct bt_notification *notification = NULL;
+       struct bt_notification *notif = NULL;
        struct bt_notification_iterator *it;
        struct pretty_component *pretty =
                bt_private_component_get_user_data(component);
@@ -202,7 +191,7 @@ enum bt_component_status pretty_consume(struct bt_private_component *component)
        }
 
        it = pretty->input_iterator;
-       it_ret = bt_notification_iterator_next(it);
+       it_ret = bt_private_connection_notification_iterator_next(it, &notif);
 
        switch (it_ret) {
        case BT_NOTIFICATION_ITERATOR_STATUS_END:
@@ -219,12 +208,11 @@ enum bt_component_status pretty_consume(struct bt_private_component *component)
                goto end;
        }
 
-       notification = bt_notification_iterator_get_notification(it);
-       assert(notification);
-       ret = handle_notification(pretty, notification);
+       BT_ASSERT(notif);
+       ret = handle_notification(pretty, notif);
 
 end:
-       bt_put(notification);
+       bt_put(notif);
        return ret;
 }
 
@@ -257,7 +245,7 @@ bt_bool check_param_exists(const char *key, struct bt_value *object, void *data)
        struct pretty_component *pretty = data;
        struct bt_value *plugin_opt_map = pretty->plugin_opt_map;
 
-       if (!bt_value_map_get(plugin_opt_map, key)) {
+       if (!bt_value_map_has_key(plugin_opt_map, key)) {
                fprintf(pretty->err,
                        "[warning] Parameter \"%s\" unknown to \"text.pretty\" sink component\n", key);
        }
@@ -274,7 +262,7 @@ enum bt_component_status apply_one_string(const char *key,
        enum bt_value_status status;
        const char *str;
 
-       value = bt_value_map_get(params, key);
+       value = bt_value_map_borrow(params, key);
        if (!value) {
                goto end;
        }
@@ -291,7 +279,6 @@ enum bt_component_status apply_one_string(const char *key,
        }
        *option = g_strdup(str);
 end:
-       bt_put(value);
        return ret;
 }
 
@@ -306,7 +293,7 @@ enum bt_component_status apply_one_bool(const char *key,
        enum bt_value_status status;
        bt_bool bool_val;
 
-       value = bt_value_map_get(params, key);
+       value = bt_value_map_borrow(params, key);
        if (!value) {
                goto end;
        }
@@ -322,8 +309,8 @@ enum bt_component_status apply_one_bool(const char *key,
        if (found) {
                *found = true;
        }
+
 end:
-       bt_put(value);
        return ret;
 }
 
@@ -389,7 +376,7 @@ enum bt_component_status apply_params(struct pretty_component *pretty,
                struct bt_value *color_value;
                const char *color;
 
-               color_value = bt_value_map_get(params, "color");
+               color_value = bt_value_map_borrow(params, "color");
                if (!color_value) {
                        goto end;
                }
@@ -408,8 +395,6 @@ enum bt_component_status apply_params(struct pretty_component *pretty,
                                warn_wrong_color_param(pretty);
                        }
                }
-
-               bt_put(color_value);
        }
 
        ret = apply_one_string("path", params, &pretty->options.output_path);
This page took 0.026295 seconds and 4 git commands to generate.