Notification iterator: transform precondition checks to BT_ASSERT_PRE()
[babeltrace.git] / plugins / text / pretty / pretty.c
index 9c994095871e556d149edf0fef49bdbe50482b00..8b5ecd2c63a14bbd1681da21bde951c338b763f1 100644 (file)
  * SOFTWARE.
  */
 
-#include <babeltrace/plugin/plugin-dev.h>
-#include <babeltrace/graph/component.h>
-#include <babeltrace/graph/private-component.h>
-#include <babeltrace/graph/private-component-sink.h>
-#include <babeltrace/graph/component-sink.h>
-#include <babeltrace/graph/port.h>
-#include <babeltrace/graph/private-port.h>
-#include <babeltrace/graph/connection.h>
-#include <babeltrace/graph/private-connection.h>
-#include <babeltrace/graph/notification.h>
-#include <babeltrace/graph/notification-iterator.h>
-#include <babeltrace/graph/notification-event.h>
+#include <babeltrace/babeltrace.h>
 #include <babeltrace/values.h>
 #include <babeltrace/compiler-internal.h>
 #include <babeltrace/common-internal.h>
 #include <stdio.h>
 #include <stdbool.h>
 #include <glib.h>
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
 
 #include "pretty.h"
 
+GQuark stream_packet_context_quarks[STREAM_PACKET_CONTEXT_QUARKS_LEN];
+
 static
 const char *plugin_options[] = {
        "color",
@@ -140,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:
@@ -149,13 +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:
+       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;
@@ -167,23 +157,18 @@ void pretty_port_connected(
                struct bt_private_port *self_port,
                struct bt_port *other_port)
 {
+       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_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);
-       pretty->input_iterator =
-               bt_private_connection_create_notification_iterator(connection,
-                       notif_types);
-
-       if (!pretty->input_iterator) {
+       BT_ASSERT(connection);
+       conn_status = bt_private_connection_create_notification_iterator(
+               connection, &pretty->input_iterator);
+       if (conn_status != BT_CONNECTION_STATUS_OK) {
                pretty->error = true;
        }
 
@@ -224,7 +209,7 @@ enum bt_component_status pretty_consume(struct bt_private_component *component)
        }
 
        notification = bt_notification_iterator_get_notification(it);
-       assert(notification);
+       BT_ASSERT(notification);
        ret = handle_notification(pretty, notification);
 
 end:
@@ -734,22 +719,18 @@ enum bt_component_status pretty_init(
 {
        enum bt_component_status ret;
        struct pretty_component *pretty = create_pretty();
-       void *priv_port;
 
        if (!pretty) {
                ret = BT_COMPONENT_STATUS_NOMEM;
                goto end;
        }
 
-       priv_port = bt_private_component_sink_add_input_private_port(component,
-               "in", NULL);
-       if (!priv_port) {
-               ret = BT_COMPONENT_STATUS_NOMEM;
+       ret = bt_private_component_sink_add_input_private_port(component,
+               "in", NULL, NULL);
+       if (ret != BT_COMPONENT_STATUS_OK) {
                goto end;
        }
 
-       bt_put(priv_port);
-
        pretty->out = stdout;
        pretty->err = stderr;
 
This page took 0.025959 seconds and 4 git commands to generate.