Fix: ctf: notif-iter.c: update_clock() uses the wrong FT sometimes
[babeltrace.git] / plugins / ctf / common / notif-iter / notif-iter.c
index 82831dade02e15f34071200ca6d989026df0cf1a..f6fe230c6b84a9b3090589d3fa74a0320532f571 100644 (file)
 #include <babeltrace/ctf-ir/stream-class.h>
 #include <babeltrace/ctf-ir/packet.h>
 #include <babeltrace/ctf-ir/stream.h>
-#include <babeltrace/ctf-ir/clock.h>
+#include <babeltrace/ctf-ir/clock-class.h>
 #include <babeltrace/ctf-ir/event-class.h>
-#include <babeltrace/plugin/notification/packet.h>
-#include <babeltrace/plugin/notification/event.h>
-#include <babeltrace/plugin/notification/stream.h>
+#include <babeltrace/graph/notification-packet.h>
+#include <babeltrace/graph/notification-event.h>
+#include <babeltrace/graph/notification-stream.h>
+#include <babeltrace/graph/clock-class-priority-map.h>
 #include <babeltrace/ref.h>
 #include <glib.h>
 
 #define PRINT_ERR_STREAM       notit->err_stream
 #define PRINT_PREFIX           "ctf-notif-iter"
-#include "print.h"
+#include "../print.h"
 
 #include "notif-iter.h"
 #include "../btr/btr.h"
@@ -161,6 +162,9 @@ struct bt_ctf_notif_iter {
                struct bt_ctf_event_class *event_class;
        } meta;
 
+       /* Clock class priority map (owned by this) */
+       struct bt_clock_class_priority_map *cc_prio_map;
+
        /* Current packet (NULL if not created yet) */
        struct bt_ctf_packet *packet;
 
@@ -228,7 +232,7 @@ struct bt_ctf_notif_iter {
        /* Current content size (bits) (-1 if unknown) */
        int64_t cur_content_size;
 
-       /* bt_ctf_clock to uint64_t. */
+       /* bt_ctf_clock_class to uint64_t. */
        GHashTable *clock_states;
 
        /*
@@ -597,14 +601,14 @@ static inline
 bool is_struct_type(struct bt_ctf_field_type *field_type)
 {
        return bt_ctf_field_type_get_type_id(field_type) ==
-                       BT_CTF_TYPE_ID_STRUCT;
+                       BT_CTF_FIELD_TYPE_ID_STRUCT;
 }
 
 static inline
 bool is_variant_type(struct bt_ctf_field_type *field_type)
 {
        return bt_ctf_field_type_get_type_id(field_type) ==
-                       BT_CTF_TYPE_ID_VARIANT;
+                       BT_CTF_FIELD_TYPE_ID_VARIANT;
 }
 
 static
@@ -1408,17 +1412,17 @@ struct bt_ctf_field *get_next_field(struct bt_ctf_notif_iter *notit)
        }
 
        switch (bt_ctf_field_type_get_type_id(base_type)) {
-       case BT_CTF_TYPE_ID_STRUCT:
+       case BT_CTF_FIELD_TYPE_ID_STRUCT:
                next_field = bt_ctf_field_structure_get_field_by_index(
                        base_field, index);
                break;
-       case BT_CTF_TYPE_ID_ARRAY:
+       case BT_CTF_FIELD_TYPE_ID_ARRAY:
                next_field = bt_ctf_field_array_get_field(base_field, index);
                break;
-       case BT_CTF_TYPE_ID_SEQUENCE:
+       case BT_CTF_FIELD_TYPE_ID_SEQUENCE:
                next_field = bt_ctf_field_sequence_get_field(base_field, index);
                break;
-       case BT_CTF_TYPE_ID_VARIANT:
+       case BT_CTF_FIELD_TYPE_ID_VARIANT:
                next_field = bt_ctf_field_variant_get_current_field(base_field);
                break;
        default:
@@ -1487,26 +1491,33 @@ end:
 
 static
 enum bt_ctf_btr_status update_clock(struct bt_ctf_notif_iter *notit,
-               struct bt_ctf_field_type *int_field_type,
                struct bt_ctf_field *int_field)
 {
-       gboolean clock_found;
+       gboolean clock_class_found;
        uint64_t *clock_state;
+       struct bt_ctf_field_type *int_field_type = NULL;
        enum bt_ctf_btr_status ret = BT_CTF_BTR_STATUS_OK;
-       struct bt_ctf_clock *clock = bt_ctf_field_type_integer_get_mapped_clock(
-                       int_field_type);
+       struct bt_ctf_clock_class *clock_class = NULL;
 
-       if (likely(!clock)) {
-               goto end_no_clock;
+       int_field_type = bt_ctf_field_get_type(int_field);
+       if (unlikely(!int_field_type)) {
+               goto end;
+       }
+
+       clock_class = bt_ctf_field_type_integer_get_mapped_clock_class(
+               int_field_type);
+       if (likely(!clock_class)) {
+               goto end;
        }
 
-       clock_found = g_hash_table_lookup_extended(notit->clock_states,
-                       clock, NULL, (gpointer) &clock_state);
-       if (unlikely(!clock_found)) {
-               const char *clock_name = bt_ctf_clock_get_name(clock);
+       clock_class_found = g_hash_table_lookup_extended(notit->clock_states,
+                       clock_class, NULL, (gpointer) &clock_state);
+       if (unlikely(!clock_class_found)) {
+               const char *clock_class_name =
+                       bt_ctf_clock_class_get_name(clock_class);
 
-               PERR("Unknown clock %s mapped to integer encountered in stream\n",
-                               clock_name ? : "NULL");
+               PERR("Unknown clock class %s mapped to integer encountered in stream\n",
+                               clock_class_name ? : "NULL");
                ret = BT_CTF_BTR_STATUS_ERROR;
                goto end;
        }
@@ -1517,22 +1528,22 @@ enum bt_ctf_btr_status update_clock(struct bt_ctf_notif_iter *notit,
                        ret = BT_CTF_BTR_STATUS_ENOMEM;
                        goto end;
                }
-               g_hash_table_insert(notit->clock_states, bt_get(clock),
+               g_hash_table_insert(notit->clock_states, bt_get(clock_class),
                                clock_state);
        }
 
        /* Update the clock's state. */
        update_clock_state(clock_state, int_field);
 end:
-       bt_put(clock);
-end_no_clock:
+       bt_put(int_field_type);
+       bt_put(clock_class);
        return ret;
 }
 
 static
 enum bt_ctf_btr_status btr_unsigned_int_common(uint64_t value,
                struct bt_ctf_field_type *type, void *data,
-               struct bt_ctf_field **_field)
+               struct bt_ctf_field **out_int_field)
 {
        enum bt_ctf_btr_status status = BT_CTF_BTR_STATUS_OK;
        struct bt_ctf_field *field = NULL;
@@ -1549,12 +1560,12 @@ enum bt_ctf_btr_status btr_unsigned_int_common(uint64_t value,
        }
 
        switch(bt_ctf_field_type_get_type_id(type)) {
-       case BT_CTF_TYPE_ID_INTEGER:
+       case BT_CTF_FIELD_TYPE_ID_INTEGER:
                /* Integer field is created field */
                BT_MOVE(int_field, field);
                bt_get(type);
                break;
-       case BT_CTF_TYPE_ID_ENUM:
+       case BT_CTF_FIELD_TYPE_ID_ENUM:
                int_field = bt_ctf_field_enumeration_get_container(field);
                type = bt_ctf_field_get_type(int_field);
                break;
@@ -1573,7 +1584,7 @@ enum bt_ctf_btr_status btr_unsigned_int_common(uint64_t value,
        ret = bt_ctf_field_unsigned_integer_set_value(int_field, value);
        assert(!ret);
        stack_top(notit->stack)->index++;
-       *_field = int_field;
+       *out_int_field = int_field;
 
 end:
        BT_PUT(field);
@@ -1619,7 +1630,7 @@ enum bt_ctf_btr_status btr_unsigned_int_cb(uint64_t value,
                goto end;
        }
 
-       status = update_clock(notit, type, field);
+       status = update_clock(notit, field);
        BT_PUT(field);
 end:
        return status;
@@ -1644,12 +1655,12 @@ enum bt_ctf_btr_status btr_signed_int_cb(int64_t value,
        }
 
        switch(bt_ctf_field_type_get_type_id(type)) {
-       case BT_CTF_TYPE_ID_INTEGER:
+       case BT_CTF_FIELD_TYPE_ID_INTEGER:
                /* Integer field is created field */
                BT_MOVE(int_field, field);
                bt_get(type);
                break;
-       case BT_CTF_TYPE_ID_ENUM:
+       case BT_CTF_FIELD_TYPE_ID_ENUM:
                int_field = bt_ctf_field_enumeration_get_container(field);
                type = bt_ctf_field_get_type(int_field);
                break;
@@ -1668,7 +1679,7 @@ enum bt_ctf_btr_status btr_signed_int_cb(int64_t value,
        ret = bt_ctf_field_signed_integer_set_value(int_field, value);
        assert(!ret);
        stack_top(notit->stack)->index++;
-       status = update_clock(notit, type, int_field);
+       status = update_clock(notit, int_field);
 end:
        BT_PUT(field);
        BT_PUT(int_field);
@@ -2017,21 +2028,22 @@ int set_event_clocks(struct bt_ctf_event *event,
 {
        int ret;
        GHashTableIter iter;
-       struct bt_ctf_clock *clock;
+       struct bt_ctf_clock_class *clock_class;
        uint64_t *clock_state;
 
        g_hash_table_iter_init(&iter, notit->clock_states);
 
-       while (g_hash_table_iter_next(&iter, (gpointer) &clock,
+       while (g_hash_table_iter_next(&iter, (gpointer) &clock_class,
                        (gpointer) &clock_state)) {
                struct bt_ctf_clock_value *clock_value;
 
-               clock_value = bt_ctf_clock_value_create(clock, *clock_state);
+               clock_value = bt_ctf_clock_value_create(clock_class,
+                       *clock_state);
                if (!clock_value) {
                        ret = -1;
                        goto end;
                }
-               ret = bt_ctf_event_set_clock_value(event, clock, clock_value);
+               ret = bt_ctf_event_set_clock_value(event, clock_value);
                bt_put(clock_value);
                if (ret) {
                        goto end;
@@ -2192,7 +2204,7 @@ void notify_event(struct bt_ctf_notif_iter *notit,
                goto end;
        }
 
-       ret = bt_notification_event_create(event);
+       ret = bt_notification_event_create(event, notit->cc_prio_map);
        if (!ret) {
                goto end;
        }
@@ -2228,25 +2240,25 @@ end:
 static
 int init_clock_states(GHashTable *clock_states, struct bt_ctf_trace *trace)
 {
-       int clock_count, i, ret = 0;
+       int clock_class_count, i, ret = 0;
 
-       clock_count = bt_ctf_trace_get_clock_count(trace);
-       if (clock_count <= 0) {
+       clock_class_count = bt_ctf_trace_get_clock_class_count(trace);
+       if (clock_class_count <= 0) {
                ret = -1;
                goto end;
        }
 
-       for (i = 0; i < clock_count; i++) {
-               struct bt_ctf_clock *clock;
+       for (i = 0; i < clock_class_count; i++) {
+               struct bt_ctf_clock_class *clock_class;
 
-               clock = bt_ctf_trace_get_clock(trace, i);
-               if (!clock) {
+               clock_class = bt_ctf_trace_get_clock_class(trace, i);
+               if (!clock_class) {
                        ret = -1;
                        goto end;
                }
 
-               g_hash_table_insert(clock_states, bt_get(clock), NULL);
-               bt_put(clock);
+               g_hash_table_insert(clock_states, bt_get(clock_class), NULL);
+               bt_put(clock_class);
        }
 end:
        return ret;
@@ -2300,6 +2312,7 @@ end:
 
 BT_HIDDEN
 struct bt_ctf_notif_iter *bt_ctf_notif_iter_create(struct bt_ctf_trace *trace,
+               struct bt_clock_class_priority_map *cc_prio_map,
                size_t max_request_sz,
                struct bt_ctf_notif_iter_medium_ops medops,
                void *data, FILE *err_stream)
@@ -2324,7 +2337,9 @@ struct bt_ctf_notif_iter *bt_ctf_notif_iter_create(struct bt_ctf_trace *trace,
        };
 
        assert(trace);
+       assert(cc_prio_map);
        assert(medops.request_bytes);
+       assert(medops.get_stream);
        notit = g_new0(struct bt_ctf_notif_iter, 1);
        if (!notit) {
                PERR("Failed to allocate memory for CTF notification iterator\n");
@@ -2341,6 +2356,7 @@ struct bt_ctf_notif_iter *bt_ctf_notif_iter_create(struct bt_ctf_trace *trace,
                PERR("Failed to initialize stream clock states\n");
                goto error;
        }
+       notit->cc_prio_map = bt_get(cc_prio_map);
        notit->meta.trace = bt_get(trace);
        notit->medium.medops = medops;
        notit->medium.max_request_sz = max_request_sz;
@@ -2384,6 +2400,7 @@ error:
 
 void bt_ctf_notif_iter_destroy(struct bt_ctf_notif_iter *notit)
 {
+       BT_PUT(notit->cc_prio_map);
        BT_PUT(notit->meta.trace);
        BT_PUT(notit->meta.stream_class);
        BT_PUT(notit->meta.event_class);
@@ -2457,8 +2474,8 @@ enum bt_ctf_notif_iter_status bt_ctf_notif_iter_get_next_notification(
                                                bt_ctf_field_get_type(
                                                        notit->cur_timestamp_end);
 
-                               btr_status = update_clock(notit, field_type,
-                                               notit->cur_timestamp_end);
+                               btr_status = update_clock(notit,
+                                       notit->cur_timestamp_end);
                                BT_PUT(field_type);
                                if (btr_status != BT_CTF_BTR_STATUS_OK) {
                                        status = BT_CTF_NOTIF_ITER_STATUS_ERROR;
This page took 0.030326 seconds and 4 git commands to generate.