tap-driver.sh: flush stdout after each test result
[babeltrace.git] / plugins / ctf / fs-sink / translate-ctf-ir-to-tsdl.c
index fef1d040076cd33ed39eacbe7a5994ae99707c0a..571599534971cf0a954a19cd429441e177205d5a 100644 (file)
 #define BT_LOG_TAG "PLUGIN-CTF-FS-SINK-TRANSLATE-CTF-IR-TO-TSDL"
 #include "logging.h"
 
-#include <babeltrace/babeltrace.h>
-#include <babeltrace/babeltrace-internal.h>
+#include <babeltrace2/babeltrace.h>
+#include <babeltrace2/babeltrace-internal.h>
 #include <stdio.h>
 #include <stdbool.h>
 #include <string.h>
 #include <glib.h>
-#include <babeltrace/assert-internal.h>
-#include <babeltrace/endian-internal.h>
+#include <babeltrace2/assert-internal.h>
+#include <babeltrace2/endian-internal.h>
 
 #include "fs-sink-ctf-meta.h"
 
@@ -227,23 +227,30 @@ void append_integer_field_class(struct ctx *ctx,
 
                for (i = 0; i < bt_field_class_enumeration_get_mapping_count(ir_fc); i++) {
                        const char *label;
-                       const bt_field_class_unsigned_enumeration_mapping_ranges *u_ranges;
-                       const bt_field_class_signed_enumeration_mapping_ranges *i_ranges;
+                       const bt_field_class_enumeration_mapping *mapping;
+                       const bt_field_class_unsigned_enumeration_mapping *u_mapping;
+                       const bt_field_class_signed_enumeration_mapping *i_mapping;
                        uint64_t range_count;
                        uint64_t range_i;
 
                        if (is_signed) {
-                               bt_field_class_signed_enumeration_borrow_mapping_by_index_const(
-                                       ir_fc, i, &label, &i_ranges);
-                               range_count = bt_field_class_signed_enumeration_mapping_ranges_get_range_count(
-                                       i_ranges);
+                               i_mapping = bt_field_class_signed_enumeration_borrow_mapping_by_index_const(
+                                       ir_fc, i);
+                               mapping = bt_field_class_signed_enumeration_mapping_as_mapping_const(
+                                       i_mapping);
                        } else {
-                               bt_field_class_unsigned_enumeration_borrow_mapping_by_index_const(
-                                       ir_fc, i, &label, &u_ranges);
-                               range_count = bt_field_class_unsigned_enumeration_mapping_ranges_get_range_count(
-                                       u_ranges);
+                               u_mapping = bt_field_class_unsigned_enumeration_borrow_mapping_by_index_const(
+                                       ir_fc, i);
+                               mapping = bt_field_class_unsigned_enumeration_mapping_as_mapping_const(
+                                       u_mapping);
                        }
 
+                       label = bt_field_class_enumeration_mapping_get_label(
+                               mapping);
+                       range_count =
+                               bt_field_class_enumeration_mapping_get_range_count(
+                                       mapping);
+
                        for (range_i = 0; range_i < range_count; range_i++) {
                                append_indent(ctx);
 
@@ -271,8 +278,8 @@ void append_integer_field_class(struct ctx *ctx,
                                if (is_signed) {
                                        int64_t lower, upper;
 
-                                       bt_field_class_signed_enumeration_mapping_ranges_get_range_by_index(
-                                               i_ranges, range_i,
+                                       bt_field_class_signed_enumeration_mapping_get_range_by_index(
+                                               i_mapping, range_i,
                                                &lower, &upper);
 
                                        if (lower == upper) {
@@ -287,8 +294,8 @@ void append_integer_field_class(struct ctx *ctx,
                                } else {
                                        uint64_t lower, upper;
 
-                                       bt_field_class_unsigned_enumeration_mapping_ranges_get_range_by_index(
-                                               u_ranges, range_i,
+                                       bt_field_class_unsigned_enumeration_mapping_get_range_by_index(
+                                               u_mapping, range_i,
                                                &lower, &upper);
 
                                        if (lower == upper) {
@@ -703,12 +710,15 @@ void append_stream_class(struct ctx *ctx,
                BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL,
                NULL, "content_size", true);
 
-       if (sc->default_clock_class) {
+       if (sc->packets_have_ts_begin) {
                append_indent(ctx);
                append_integer_field_class_from_props(ctx, 64, 8, false,
                        BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL,
                        sc->default_clock_class_name->str,
                        "timestamp_begin", true);
+       }
+
+       if (sc->packets_have_ts_end) {
                append_indent(ctx);
                append_integer_field_class_from_props(ctx, 64, 8, false,
                        BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL,
@@ -716,10 +726,18 @@ void append_stream_class(struct ctx *ctx,
                        "timestamp_end", true);
        }
 
-       append_indent(ctx);
-       append_integer_field_class_from_props(ctx, 64, 8, false,
-               BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL,
-               NULL, "events_discarded", true);
+       if (sc->has_discarded_events) {
+               append_indent(ctx);
+               append_integer_field_class_from_props(ctx, 64, 8, false,
+                       BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL,
+                       NULL, "events_discarded", true);
+       }
+
+       /*
+        * Unconditionnally write the packet sequence number as, even if
+        * there's no possible discarded packets message, it's still
+        * useful information to have.
+        */
        append_indent(ctx);
        append_integer_field_class_from_props(ctx, 64, 8, false,
                BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL,
@@ -860,9 +878,9 @@ void translate_trace_class_ctf_ir_to_tsdl(struct fs_sink_ctf_trace_class *tc,
                        g_string_append_printf(tsdl, "%s = ", name);
 
                        switch (bt_value_get_type(val)) {
-                       case BT_VALUE_TYPE_INTEGER:
+                       case BT_VALUE_TYPE_SIGNED_INTEGER:
                                g_string_append_printf(tsdl, "%" PRId64,
-                                       bt_value_integer_get(val));
+                                       bt_value_signed_integer_get(val));
                                break;
                        case BT_VALUE_TYPE_STRING:
                                append_quoted_string(&ctx, bt_value_string_get(val));
This page took 0.028916 seconds and 4 git commands to generate.