text plugin: add color support
[babeltrace.git] / plugins / trimmer / iterator.c
index 133d63dda94ca97e7bcd3307e477ee6aef301cf2..04557cba3ad4b491ba0e429791bc48463b43622f 100644 (file)
 
 #include "trimmer.h"
 #include "iterator.h"
-#include <babeltrace/plugin/notification/iterator.h>
-#include <babeltrace/plugin/notification/notification.h>
-#include <babeltrace/plugin/notification/event.h>
-#include <babeltrace/plugin/notification/stream.h>
-#include <babeltrace/plugin/notification/packet.h>
-#include <babeltrace/plugin/filter.h>
+#include <babeltrace/component/notification/iterator.h>
+#include <babeltrace/component/notification/notification.h>
+#include <babeltrace/component/notification/event.h>
+#include <babeltrace/component/notification/stream.h>
+#include <babeltrace/component/notification/packet.h>
+#include <babeltrace/component/component-filter.h>
 #include <babeltrace/ctf-ir/event.h>
 #include <babeltrace/ctf-ir/stream.h>
 #include <babeltrace/ctf-ir/stream-class.h>
-#include <babeltrace/ctf-ir/clock.h>
+#include <babeltrace/ctf-ir/clock-class.h>
 #include <babeltrace/ctf-ir/packet.h>
 #include <babeltrace/ctf-ir/trace.h>
 #include <babeltrace/ctf-ir/fields.h>
 #include <assert.h>
+#include <plugins-common.h>
 
-static
+BT_HIDDEN
 void trimmer_iterator_destroy(struct bt_notification_iterator *it)
 {
        struct trimmer_iterator *it_data;
@@ -59,15 +60,18 @@ void trimmer_iterator_destroy(struct bt_notification_iterator *it)
 }
 
 BT_HIDDEN
-enum bt_component_status trimmer_iterator_init(struct bt_component *component,
-               struct bt_notification_iterator *iterator)
+enum bt_notification_iterator_status trimmer_iterator_init(
+               struct bt_component *component,
+               struct bt_notification_iterator *iterator,
+               UNUSED_VAR void *init_method_data)
 {
-       enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
+       enum bt_notification_iterator_status ret =
+               BT_NOTIFICATION_ITERATOR_STATUS_OK;
        enum bt_notification_iterator_status it_ret;
        struct trimmer_iterator *it_data = g_new0(struct trimmer_iterator, 1);
 
        if (!it_data) {
-               ret = BT_COMPONENT_STATUS_NOMEM;
+               ret = BT_NOTIFICATION_ITERATOR_STATUS_NOMEM;
                goto end;
        }
 
@@ -76,34 +80,6 @@ enum bt_component_status trimmer_iterator_init(struct bt_component *component,
        if (it_ret) {
                goto end;
        }
-
-       it_ret = bt_notification_iterator_set_destroy_cb(iterator,
-                       trimmer_iterator_destroy);
-       if (it_ret) {
-               ret = BT_COMPONENT_STATUS_ERROR;
-               goto end;
-       }
-
-       it_ret = bt_notification_iterator_set_next_cb(iterator,
-                       trimmer_iterator_next);
-       if (it_ret) {
-               ret = BT_COMPONENT_STATUS_ERROR;
-               goto end;
-       }
-
-       it_ret = bt_notification_iterator_set_get_cb(iterator,
-                       trimmer_iterator_get);
-       if (it_ret) {
-               ret = BT_COMPONENT_STATUS_ERROR;
-               goto end;
-       }
-
-       it_ret = bt_notification_iterator_set_seek_time_cb(iterator,
-                       trimmer_iterator_seek_time);
-       if (it_ret) {
-               ret = BT_COMPONENT_STATUS_ERROR;
-               goto end;
-       }
 end:
        return ret;
 }
@@ -199,7 +175,7 @@ evaluate_event_notification(struct bt_notification *notification,
        int clock_ret;
        struct bt_ctf_event *event = NULL;
        bool in_range = true;
-       struct bt_ctf_clock *clock = NULL;
+       struct bt_ctf_clock_class *clock_class = NULL;
        struct bt_ctf_trace *trace = NULL;
        struct bt_ctf_stream *stream = NULL;
        struct bt_ctf_stream_class *stream_class = NULL;
@@ -221,12 +197,12 @@ evaluate_event_notification(struct bt_notification *notification,
        assert(trace);
 
        /* FIXME multi-clock? */
-       clock = bt_ctf_trace_get_clock(trace, 0);
-       if (!clock) {
+       clock_class = bt_ctf_trace_get_clock_class(trace, 0);
+       if (!clock_class) {
                goto end;
        }
 
-       clock_value = bt_ctf_event_get_clock_value(event, clock);
+       clock_value = bt_ctf_event_get_clock_value(event, clock_class);
        if (!clock_value) {
                printf_error("Failed to retrieve clock value");
                ret = BT_NOTIFICATION_ITERATOR_STATUS_ERROR;
@@ -260,11 +236,10 @@ evaluate_event_notification(struct bt_notification *notification,
        }
        if (end->set && ts > end->value) {
                in_range = false;
-               ret = BT_NOTIFICATION_ITERATOR_STATUS_END;
        }
 end:
        bt_put(event);
-       bt_put(clock);
+       bt_put(clock_class);
        bt_put(trace);
        bt_put(stream);
        bt_put(stream_class);
@@ -280,13 +255,14 @@ int ns_from_integer_field(struct bt_ctf_field *integer, int64_t *ns)
        int is_signed;
        uint64_t raw_clock_value;
        struct bt_ctf_field_type *integer_type = NULL;
-       struct bt_ctf_clock *clock = NULL;
+       struct bt_ctf_clock_class *clock_class = NULL;
        struct bt_ctf_clock_value *clock_value = NULL;
 
        integer_type = bt_ctf_field_get_type(integer);
        assert(integer_type);
-       clock = bt_ctf_field_type_integer_get_mapped_clock(integer_type);
-       if (!clock) {
+       clock_class = bt_ctf_field_type_integer_get_mapped_clock_class(
+               integer_type);
+       if (!clock_class) {
                ret = -1;
                goto end;
        }
@@ -303,7 +279,7 @@ int ns_from_integer_field(struct bt_ctf_field *integer, int64_t *ns)
                goto end;
        }
 
-       clock_value = bt_ctf_clock_value_create(clock, raw_clock_value);
+       clock_value = bt_ctf_clock_value_create(clock_class, raw_clock_value);
         if (!clock_value) {
                goto end;
        }
@@ -311,7 +287,7 @@ int ns_from_integer_field(struct bt_ctf_field *integer, int64_t *ns)
        ret = bt_ctf_clock_value_get_value_ns_from_epoch(clock_value, ns);
 end:
        bt_put(integer_type);
-       bt_put(clock);
+       bt_put(clock_class);
        bt_put(clock_value);
        return ret;
 }
@@ -378,9 +354,6 @@ enum bt_notification_iterator_status evaluate_packet_notification(
         * packet.
         */
        in_range = (pkt_end_ns >= begin_ns) && (pkt_begin_ns <= end_ns);
-       if (pkt_begin_ns > end_ns) {
-               ret = BT_NOTIFICATION_ITERATOR_STATUS_END;
-       }
 end:
        *_packet_in_range = in_range;
        bt_put(packet);
@@ -401,6 +374,7 @@ enum bt_notification_iterator_status evaluate_notification(
        enum bt_notification_iterator_status ret =
                        BT_NOTIFICATION_ITERATOR_STATUS_OK;
 
+       *in_range = true;
        type = bt_notification_get_type(notification);
        switch (type) {
        case BT_NOTIFICATION_TYPE_EVENT:
@@ -468,6 +442,10 @@ enum bt_notification_iterator_status trimmer_iterator_next(
                } else {
                        bt_put(notification);
                }
+
+               if (ret != BT_NOTIFICATION_ITERATOR_STATUS_OK) {
+                       break;
+               }
        }
 end:
        bt_put(source_it);
This page took 0.028608 seconds and 4 git commands to generate.