Rename: field type -> field class
[babeltrace.git] / plugins / utils / trimmer / iterator.c
index d8d8b0c6c9166880baee82d03c737c18fad2556b..335bcfd14ea1fb4f9e123a1324588d417cea77fa 100644 (file)
 
 #include <babeltrace/compat/time-internal.h>
 #include <babeltrace/compat/utc-internal.h>
-#include <babeltrace/graph/notification-iterator.h>
-#include <babeltrace/graph/private-notification-iterator.h>
-#include <babeltrace/graph/notification.h>
-#include <babeltrace/graph/notification-event.h>
-#include <babeltrace/graph/notification-stream.h>
-#include <babeltrace/graph/notification-packet.h>
-#include <babeltrace/graph/component-filter.h>
-#include <babeltrace/graph/private-component-filter.h>
-#include <babeltrace/graph/private-port.h>
-#include <babeltrace/graph/private-connection.h>
-#include <babeltrace/graph/private-component.h>
-#include <babeltrace/graph/connection.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-class.h>
-#include <babeltrace/ctf-ir/packet.h>
-#include <babeltrace/ctf-ir/trace.h>
-#include <babeltrace/ctf-ir/fields.h>
-#include <assert.h>
+#include <babeltrace/babeltrace.h>
+#include <babeltrace/assert-internal.h>
 #include <plugins-common.h>
 
 #include "trimmer.h"
 static
 gboolean close_packets(gpointer key, gpointer value, gpointer user_data)
 {
-       struct bt_ctf_packet *writer_packet = value;
+       struct bt_packet *writer_packet = value;
 
        bt_put(writer_packet);
        return TRUE;
 }
 
 BT_HIDDEN
-void trimmer_iterator_finalize(struct bt_private_notification_iterator *it)
+void trimmer_iterator_finalize(struct bt_private_connection_private_notification_iterator *it)
 {
        struct trimmer_iterator *trim_it;
 
-       trim_it = bt_private_notification_iterator_get_user_data(it);
-       assert(trim_it);
+       trim_it = bt_private_connection_private_notification_iterator_get_user_data(it);
+       BT_ASSERT(trim_it);
 
        bt_put(trim_it->input_iterator);
        g_hash_table_foreach_remove(trim_it->packet_map,
@@ -83,7 +65,7 @@ void trimmer_iterator_finalize(struct bt_private_notification_iterator *it)
 
 BT_HIDDEN
 enum bt_notification_iterator_status trimmer_iterator_init(
-               struct bt_private_notification_iterator *iterator,
+               struct bt_private_connection_private_notification_iterator *iterator,
                struct bt_private_port *port)
 {
        enum bt_notification_iterator_status ret =
@@ -93,15 +75,8 @@ enum bt_notification_iterator_status trimmer_iterator_init(
        struct bt_private_port *input_port = NULL;
        struct bt_private_connection *connection = NULL;
        struct bt_private_component *component =
-               bt_private_notification_iterator_get_private_component(iterator);
+               bt_private_connection_private_notification_iterator_get_private_component(iterator);
        struct trimmer_iterator *it_data = g_new0(struct trimmer_iterator, 1);
-       static const enum bt_notification_type notif_types[] = {
-               BT_NOTIFICATION_TYPE_EVENT,
-               BT_NOTIFICATION_TYPE_STREAM_END,
-               BT_NOTIFICATION_TYPE_PACKET_BEGIN,
-               BT_NOTIFICATION_TYPE_PACKET_END,
-               BT_NOTIFICATION_TYPE_SENTINEL,
-       };
 
        if (!it_data) {
                ret = BT_NOTIFICATION_ITERATOR_STATUS_NOMEM;
@@ -111,12 +86,12 @@ enum bt_notification_iterator_status trimmer_iterator_init(
        /* Create a new iterator on the upstream component. */
        input_port = bt_private_component_filter_get_input_private_port_by_name(
                component, "in");
-       assert(input_port);
+       BT_ASSERT(input_port);
        connection = bt_private_port_get_private_connection(input_port);
-       assert(connection);
+       BT_ASSERT(connection);
 
        conn_status = bt_private_connection_create_notification_iterator(connection,
-                       notif_types, &it_data->input_iterator);
+                       &it_data->input_iterator);
        if (conn_status != BT_CONNECTION_STATUS_OK) {
                ret = BT_NOTIFICATION_ITERATOR_STATUS_ERROR;
                goto end;
@@ -126,7 +101,7 @@ enum bt_notification_iterator_status trimmer_iterator_init(
        it_data->packet_map = g_hash_table_new_full(g_direct_hash,
                        g_direct_equal, NULL, NULL);
 
-       it_ret = bt_private_notification_iterator_set_user_data(iterator,
+       it_ret = bt_private_connection_private_notification_iterator_set_user_data(iterator,
                it_data);
        if (it_ret) {
                goto end;
@@ -207,50 +182,50 @@ struct bt_notification *evaluate_event_notification(
 {
        int64_t ts;
        int clock_ret;
-       struct bt_ctf_event *event = NULL, *writer_event;
+       struct bt_event *event = NULL, *writer_event;
        bool in_range = true;
-       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;
-       struct bt_ctf_clock_value *clock_value = NULL;
+       struct bt_clock_class *clock_class = NULL;
+       struct bt_trace *trace = NULL;
+       struct bt_stream *stream = NULL;
+       struct bt_stream_class *stream_class = NULL;
+       struct bt_clock_value *clock_value = NULL;
        bool lazy_update = false;
        struct bt_notification *new_notification = NULL;
        struct bt_clock_class_priority_map *cc_prio_map;
 
        event = bt_notification_event_get_event(notification);
-       assert(event);
+       BT_ASSERT(event);
        cc_prio_map = bt_notification_event_get_clock_class_priority_map(
                        notification);
-       assert(cc_prio_map);
+       BT_ASSERT(cc_prio_map);
        writer_event = trimmer_output_event(trim_it, event);
-       assert(writer_event);
+       BT_ASSERT(writer_event);
        new_notification = bt_notification_event_create(writer_event, cc_prio_map);
-       assert(new_notification);
+       BT_ASSERT(new_notification);
        bt_put(cc_prio_map);
 
-       stream = bt_ctf_event_get_stream(event);
-       assert(stream);
+       stream = bt_event_get_stream(event);
+       BT_ASSERT(stream);
 
-       stream_class = bt_ctf_stream_get_class(stream);
-       assert(stream_class);
+       stream_class = bt_stream_get_class(stream);
+       BT_ASSERT(stream_class);
 
-       trace = bt_ctf_stream_class_get_trace(stream_class);
-       assert(trace);
+       trace = bt_stream_class_get_trace(stream_class);
+       BT_ASSERT(trace);
 
        /* FIXME multi-clock? */
-       clock_class = bt_ctf_trace_get_clock_class_by_index(trace, 0);
+       clock_class = bt_trace_get_clock_class_by_index(trace, 0);
        if (!clock_class) {
                goto end;
        }
 
-       clock_value = bt_ctf_event_get_clock_value(event, clock_class);
+       clock_value = bt_event_get_clock_value(event, clock_class);
        if (!clock_value) {
                BT_LOGE_STR("Failed to retrieve clock value.");
                goto error;
        }
 
-       clock_ret = bt_ctf_clock_value_get_value_ns_from_epoch(
+       clock_ret = bt_clock_value_get_value_ns_from_epoch(
                        clock_value, &ts);
        if (clock_ret) {
                BT_LOGE_STR("Failed to retrieve clock value timestamp.");
@@ -293,27 +268,27 @@ end:
 }
 
 static
-int ns_from_integer_field(struct bt_ctf_field *integer, int64_t *ns)
+int ns_from_integer_field(struct bt_field *integer, int64_t *ns)
 {
        int ret = 0;
        int is_signed;
        uint64_t raw_clock_value;
-       struct bt_ctf_field_type *integer_type = 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_class = bt_ctf_field_type_integer_get_mapped_clock_class(
-               integer_type);
+       struct bt_field_class *integer_class = NULL;
+       struct bt_clock_class *clock_class = NULL;
+       struct bt_clock_value *clock_value = NULL;
+
+       integer_class = bt_field_get_class(integer);
+       BT_ASSERT(integer_class);
+       clock_class = bt_field_class_integer_get_mapped_clock_class(
+               integer_class);
        if (!clock_class) {
                ret = -1;
                goto end;
        }
 
-       is_signed = bt_ctf_field_type_integer_get_signed(integer_type);
+       is_signed = bt_field_class_integer_is_signed(integer_class);
        if (!is_signed) {
-               ret = bt_ctf_field_unsigned_integer_get_value(integer,
+               ret = bt_field_unsigned_integer_get_value(integer,
                                &raw_clock_value);
                if (ret) {
                        goto end;
@@ -324,14 +299,14 @@ int ns_from_integer_field(struct bt_ctf_field *integer, int64_t *ns)
                goto end;
        }
 
-       clock_value = bt_ctf_clock_value_create(clock_class, raw_clock_value);
+       clock_value = bt_clock_value_create(clock_class, raw_clock_value);
         if (!clock_value) {
                goto end;
        }
 
-       ret = bt_ctf_clock_value_get_value_ns_from_epoch(clock_value, ns);
+       ret = bt_clock_value_get_value_ns_from_epoch(clock_value, ns);
 end:
-       bt_put(integer_type);
+       bt_put(integer_class);
        bt_put(clock_class);
        bt_put(clock_value);
        return ret;
@@ -354,40 +329,40 @@ static uint64_t ns_from_value(uint64_t frequency, uint64_t value)
  * timestamp minus the offset.
  */
 static
-int64_t get_raw_timestamp(struct bt_ctf_packet *writer_packet,
+int64_t get_raw_timestamp(struct bt_packet *writer_packet,
                int64_t timestamp)
 {
-       struct bt_ctf_clock_class *writer_clock_class;
+       struct bt_clock_class *writer_clock_class;
        int64_t sec_offset, cycles_offset, ns;
-       struct bt_ctf_trace *writer_trace;
-       struct bt_ctf_stream *writer_stream;
-       struct bt_ctf_stream_class *writer_stream_class;
+       struct bt_trace *writer_trace;
+       struct bt_stream *writer_stream;
+       struct bt_stream_class *writer_stream_class;
        int ret;
        uint64_t freq;
 
-       writer_stream = bt_ctf_packet_get_stream(writer_packet);
-       assert(writer_stream);
+       writer_stream = bt_packet_get_stream(writer_packet);
+       BT_ASSERT(writer_stream);
 
-       writer_stream_class = bt_ctf_stream_get_class(writer_stream);
-       assert(writer_stream_class);
+       writer_stream_class = bt_stream_get_class(writer_stream);
+       BT_ASSERT(writer_stream_class);
 
-       writer_trace = bt_ctf_stream_class_get_trace(writer_stream_class);
-       assert(writer_trace);
+       writer_trace = bt_stream_class_get_trace(writer_stream_class);
+       BT_ASSERT(writer_trace);
 
        /* FIXME multi-clock? */
-       writer_clock_class = bt_ctf_trace_get_clock_class_by_index(
+       writer_clock_class = bt_trace_get_clock_class_by_index(
                writer_trace, 0);
-       assert(writer_clock_class);
+       BT_ASSERT(writer_clock_class);
 
-       ret = bt_ctf_clock_class_get_offset_s(writer_clock_class, &sec_offset);
-       assert(!ret);
+       ret = bt_clock_class_get_offset_s(writer_clock_class, &sec_offset);
+       BT_ASSERT(!ret);
        ns = sec_offset * NSEC_PER_SEC;
 
-       freq = bt_ctf_clock_class_get_frequency(writer_clock_class);
-       assert(freq != -1ULL);
+       freq = bt_clock_class_get_frequency(writer_clock_class);
+       BT_ASSERT(freq != -1ULL);
 
-       ret = bt_ctf_clock_class_get_offset_cycles(writer_clock_class, &cycles_offset);
-       assert(!ret);
+       ret = bt_clock_class_get_offset_cycles(writer_clock_class, &cycles_offset);
+       BT_ASSERT(!ret);
 
        ns += ns_from_value(freq, cycles_offset);
 
@@ -408,8 +383,8 @@ struct bt_notification *evaluate_packet_notification(
 {
        int64_t begin_ns, pkt_begin_ns, end_ns, pkt_end_ns;
        bool in_range = true;
-       struct bt_ctf_packet *packet = NULL, *writer_packet = NULL;
-       struct bt_ctf_field *packet_context = NULL,
+       struct bt_packet *packet = NULL, *writer_packet = NULL;
+       struct bt_field *packet_context = NULL,
                        *timestamp_begin = NULL,
                        *timestamp_end = NULL;
        struct bt_notification *new_notification = NULL;
@@ -419,37 +394,37 @@ struct bt_notification *evaluate_packet_notification(
         switch (bt_notification_get_type(notification)) {
        case BT_NOTIFICATION_TYPE_PACKET_BEGIN:
                packet = bt_notification_packet_begin_get_packet(notification);
-               assert(packet);
+               BT_ASSERT(packet);
                writer_packet = trimmer_new_packet(trim_it, packet);
-               assert(writer_packet);
+               BT_ASSERT(writer_packet);
                break;
        case BT_NOTIFICATION_TYPE_PACKET_END:
                packet = bt_notification_packet_end_get_packet(notification);
-               assert(packet);
+               BT_ASSERT(packet);
                writer_packet = trimmer_close_packet(trim_it, packet);
-               assert(writer_packet);
+               BT_ASSERT(writer_packet);
                break;
        default:
                goto end;
        }
 
-       packet_context = bt_ctf_packet_get_context(writer_packet);
+       packet_context = bt_packet_get_context(writer_packet);
        if (!packet_context) {
                goto end_no_notif;
        }
 
-       if (!bt_ctf_field_is_structure(packet_context)) {
+       if (!bt_field_is_structure(packet_context)) {
                goto end_no_notif;
        }
 
-       timestamp_begin = bt_ctf_field_structure_get_field(
+       timestamp_begin = bt_field_structure_get_field_by_name(
                        packet_context, "timestamp_begin");
-       if (!timestamp_begin || !bt_ctf_field_is_integer(timestamp_begin)) {
+       if (!timestamp_begin || !bt_field_is_integer(timestamp_begin)) {
                goto end_no_notif;
        }
-       timestamp_end = bt_ctf_field_structure_get_field(
+       timestamp_end = bt_field_structure_get_field_by_name(
                        packet_context, "timestamp_end");
-       if (!timestamp_end || !bt_ctf_field_is_integer(timestamp_end)) {
+       if (!timestamp_end || !bt_field_is_integer(timestamp_end)) {
                goto end_no_notif;
        }
 
@@ -492,25 +467,25 @@ struct bt_notification *evaluate_packet_notification(
                ret = update_packet_context_field(trim_it->err, writer_packet,
                                "timestamp_begin",
                                get_raw_timestamp(writer_packet, begin_ns));
-               assert(!ret);
+               BT_ASSERT(!ret);
        }
 
        if (end_ns < pkt_end_ns) {
                ret = update_packet_context_field(trim_it->err, writer_packet,
                                "timestamp_end",
                                get_raw_timestamp(writer_packet, end_ns));
-               assert(!ret);
+               BT_ASSERT(!ret);
        }
 
 end:
         switch (bt_notification_get_type(notification)) {
        case BT_NOTIFICATION_TYPE_PACKET_BEGIN:
                new_notification = bt_notification_packet_begin_create(writer_packet);
-               assert(new_notification);
+               BT_ASSERT(new_notification);
                break;
        case BT_NOTIFICATION_TYPE_PACKET_END:
                new_notification = bt_notification_packet_end_create(writer_packet);
-               assert(new_notification);
+               BT_ASSERT(new_notification);
                break;
        default:
                break;
@@ -530,10 +505,10 @@ struct bt_notification *evaluate_stream_notification(
                struct bt_notification *notification,
                struct trimmer_iterator *trim_it)
 {
-       struct bt_ctf_stream *stream;
+       struct bt_stream *stream;
 
        stream = bt_notification_stream_end_get_stream(notification);
-       assert(stream);
+       BT_ASSERT(stream);
 
        /* FIXME: useless copy */
        return bt_notification_stream_end_create(stream);
@@ -568,7 +543,6 @@ enum bt_notification_iterator_status evaluate_notification(
                                trim_it);
                break;
        default:
-               puts("Unhandled notification type");
                break;
        }
        BT_PUT(*notification);
@@ -582,30 +556,30 @@ enum bt_notification_iterator_status evaluate_notification(
 }
 
 BT_HIDDEN
-struct bt_notification_iterator_next_return trimmer_iterator_next(
-               struct bt_private_notification_iterator *iterator)
+struct bt_notification_iterator_next_method_return trimmer_iterator_next(
+               struct bt_private_connection_private_notification_iterator *iterator)
 {
        struct trimmer_iterator *trim_it = NULL;
        struct bt_private_component *component = NULL;
        struct trimmer *trimmer = NULL;
        struct bt_notification_iterator *source_it = NULL;
-       struct bt_notification_iterator_next_return ret = {
+       struct bt_notification_iterator_next_method_return ret = {
                .status = BT_NOTIFICATION_ITERATOR_STATUS_OK,
                .notification = NULL,
        };
        bool notification_in_range = false;
 
-       trim_it = bt_private_notification_iterator_get_user_data(iterator);
-       assert(trim_it);
+       trim_it = bt_private_connection_private_notification_iterator_get_user_data(iterator);
+       BT_ASSERT(trim_it);
 
-       component = bt_private_notification_iterator_get_private_component(
+       component = bt_private_connection_private_notification_iterator_get_private_component(
                iterator);
-       assert(component);
+       BT_ASSERT(component);
        trimmer = bt_private_component_get_user_data(component);
-       assert(trimmer);
+       BT_ASSERT(trimmer);
 
        source_it = trim_it->input_iterator;
-       assert(source_it);
+       BT_ASSERT(source_it);
 
        while (!notification_in_range) {
                ret.status = bt_notification_iterator_next(source_it);
This page took 0.032272 seconds and 4 git commands to generate.