lib: add option field classes with integer selectors
[babeltrace.git] / src / plugins / text / details / write.c
index aa45d3d08e746abbd8ba5d59225be8d11363246a..8b18bf027d611d92957169030b6bc8c631d51195 100644 (file)
@@ -931,8 +931,11 @@ void write_field_class(struct details_write_ctx *ctx, const bt_field_class *fc)
        case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION:
                type = "Signed enumeration";
                break;
-       case BT_FIELD_CLASS_TYPE_REAL:
-               type = "Real";
+       case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL:
+               type = "Single-precision real";
+               break;
+       case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL:
+               type = "Double-precision real";
                break;
        case BT_FIELD_CLASS_TYPE_STRING:
                type = "String";
@@ -946,8 +949,17 @@ void write_field_class(struct details_write_ctx *ctx, const bt_field_class *fc)
        case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY:
                type = "Dynamic array";
                break;
-       case BT_FIELD_CLASS_TYPE_OPTION:
-               type = "Option";
+       case BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR:
+               type = "Option (no selector)";
+               break;
+       case BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR:
+               type = "Option (boolean selector)";
+               break;
+       case BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR:
+               type = "Option (unsigned integer selector)";
+               break;
+       case BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR:
+               type = "Option (signed integer selector)";
                break;
        case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR:
                type = "Variant (no selector)";
@@ -986,14 +998,6 @@ void write_field_class(struct details_write_ctx *ctx, const bt_field_class *fc)
                        plural(mapping_count));
                break;
        }
-       case BT_FIELD_CLASS_TYPE_REAL:
-               if (bt_field_class_real_is_single_precision(fc)) {
-                       g_string_append(ctx->str, " (Single precision)");
-               } else {
-                       g_string_append(ctx->str, " (Double precision)");
-               }
-
-               break;
        case BT_FIELD_CLASS_TYPE_STRUCTURE:
        {
                uint64_t member_count =
@@ -1025,17 +1029,17 @@ void write_field_class(struct details_write_ctx *ctx, const bt_field_class *fc)
                }
 
                break;
-       case BT_FIELD_CLASS_TYPE_OPTION:
+       case BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR:
+       case BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR:
+       case BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR:
        {
                const bt_field_path *selector_field_path =
-                       bt_field_class_option_borrow_selector_field_path_const(fc);
-
-               if (selector_field_path) {
-                       g_string_append(ctx->str, " (Selector field path ");
-                       write_field_path(ctx, selector_field_path);
-                       g_string_append_c(ctx->str, ')');
-               }
+                       bt_field_class_option_with_selector_borrow_selector_field_path_const(
+                               fc);
 
+               g_string_append(ctx->str, " (Selector field path ");
+               write_field_path(ctx, selector_field_path);
+               g_string_append_c(ctx->str, ')');
                break;
        }
        case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR:
@@ -1180,18 +1184,56 @@ void write_field_class(struct details_write_ctx *ctx, const bt_field_class *fc)
                write_field_class(ctx,
                        bt_field_class_array_borrow_element_field_class_const(fc));
                break;
-       case BT_FIELD_CLASS_TYPE_OPTION:
+       case BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR:
+       case BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR:
+       case BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR:
+       case BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR:
+       {
+               const void *ranges = NULL;
+               bool selector_is_signed = false;
+
                if (wrote_user_attrs) {
                        write_nl(ctx);
                } else {
                        g_string_append(ctx->str, ":\n");
                }
 
+               if (fc_type == BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR) {
+                       write_bool_prop_line(ctx, "Selector is reversed",
+                               bt_field_class_option_with_selector_bool_selector_is_reversed(fc));
+               } else if (fc_type == BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR) {
+                       ranges = bt_field_class_option_with_selector_integer_unsigned_borrow_selector_ranges_const(fc);
+               } else if (fc_type == BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR) {
+                       ranges = bt_field_class_option_with_selector_integer_signed_borrow_selector_ranges_const(fc);
+                       selector_is_signed = true;
+               }
+
+               if (ranges) {
+                       GArray *sorted_ranges = range_set_to_int_ranges(
+                               ranges, selector_is_signed);
+                       uint64_t i;
+
+                       BT_ASSERT(sorted_ranges);
+                       BT_ASSERT(sorted_ranges->len > 0);
+                       write_prop_name_line(ctx, "Selector ranges");
+
+                       for (i = 0; i < sorted_ranges->len; i++) {
+                               write_sp(ctx);
+                               write_int_range(ctx,
+                                       int_range_at(sorted_ranges, i),
+                                       selector_is_signed);
+                       }
+
+                       write_nl(ctx);
+                       g_array_free(sorted_ranges, TRUE);
+               }
+
                write_prop_name_line(ctx, "Content");
                write_sp(ctx);
                write_field_class(ctx,
                        bt_field_class_option_borrow_field_class_const(fc));
                break;
+       }
        case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR:
        case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR:
        case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR:
@@ -1596,7 +1638,6 @@ int try_write_meta(struct details_write_ctx *ctx, const bt_trace_class *tc,
                 * rewrite `sc`.
                 */
                write_trace_class(ctx, tc);
-               write_nl(ctx);
 
                /*
                 * Mark this trace class as written, as well as all
@@ -1648,7 +1689,6 @@ int try_write_meta(struct details_write_ctx *ctx, const bt_trace_class *tc,
                 * classes, so we don't need to rewrite `ec`.
                 */
                write_stream_class(ctx, sc);
-               write_nl(ctx);
 
                /*
                 * Mark this stream class as written, as well as all its
@@ -1681,7 +1721,6 @@ int try_write_meta(struct details_write_ctx *ctx, const bt_trace_class *tc,
                }
 
                write_event_class(ctx, ec);
-               write_nl(ctx);
                details_did_write_meta_object(ctx, tc, ec);
                goto end;
        }
@@ -1857,9 +1896,13 @@ void write_field(struct details_write_ctx *ctx, const bt_field *field,
 
                break;
        }
-       case BT_FIELD_CLASS_TYPE_REAL:
+       case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL:
+               write_sp(ctx);
+               write_float_prop_value(ctx, bt_field_real_single_precision_get_value(field));
+               break;
+       case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL:
                write_sp(ctx);
-               write_float_prop_value(ctx, bt_field_real_get_value(field));
+               write_float_prop_value(ctx, bt_field_real_double_precision_get_value(field));
                break;
        case BT_FIELD_CLASS_TYPE_STRING:
                write_sp(ctx);
@@ -1925,7 +1968,10 @@ void write_field(struct details_write_ctx *ctx, const bt_field *field,
                decr_indent(ctx);
                break;
        }
-       case BT_FIELD_CLASS_TYPE_OPTION:
+       case BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR:
+       case BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR:
+       case BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR:
+       case BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR:
        {
                const bt_field *content_field =
                        bt_field_option_borrow_field_const(field);
@@ -1982,6 +2028,18 @@ int write_event_message(struct details_write_ctx *ctx,
                goto end;
        }
 
+       if (!ctx->details_comp->cfg.with_data) {
+               goto end;
+       }
+
+       if (ctx->str->len > 0) {
+               /*
+                * Output buffer contains metadata: separate blocks with
+                * newline.
+                */
+               write_nl(ctx);
+       }
+
        /* Write time */
        if (bt_stream_class_borrow_default_clock_class_const(sc)) {
                write_time(ctx,
@@ -2038,7 +2096,6 @@ int write_event_message(struct details_write_ctx *ctx,
        decr_indent(ctx);
 
 end:
-
        return ret;
 }
 
@@ -2219,6 +2276,18 @@ int write_stream_beginning_message(struct details_write_ctx *ctx,
                goto end;
        }
 
+       if (!ctx->details_comp->cfg.with_data) {
+               goto end;
+       }
+
+       if (ctx->str->len > 0) {
+               /*
+                * Output buffer contains metadata: separate blocks with
+                * newline.
+                */
+               write_nl(ctx);
+       }
+
        /* Write time */
        if (cc) {
                const bt_clock_snapshot *cs;
@@ -2282,6 +2351,10 @@ int write_stream_end_message(struct details_write_ctx *ctx,
        const bt_clock_class *cc =
                bt_stream_class_borrow_default_clock_class_const(sc);
 
+       if (!ctx->details_comp->cfg.with_data) {
+               goto end;
+       }
+
        /* Write time */
        if (cc) {
                const bt_clock_snapshot *cs;
@@ -2319,6 +2392,10 @@ int write_packet_beginning_message(struct details_write_ctx *ctx,
        const bt_stream_class *sc = bt_stream_borrow_class_const(stream);
        const bt_field *field;
 
+       if (!ctx->details_comp->cfg.with_data) {
+               goto end;
+       }
+
        /* Write time */
        if (bt_stream_class_packets_have_beginning_default_clock_snapshot(sc)) {
                write_time(ctx,
@@ -2396,6 +2473,7 @@ static
 int write_discarded_events_message(struct details_write_ctx *ctx,
                const bt_message *msg)
 {
+       int ret = 0;
        const bt_stream *stream = bt_message_discarded_events_borrow_stream_const(
                msg);
        const bt_stream_class *sc = bt_stream_borrow_class_const(stream);
@@ -2403,6 +2481,10 @@ int write_discarded_events_message(struct details_write_ctx *ctx,
        const bt_clock_snapshot *end_cs = NULL;
        uint64_t count;
 
+       if (!ctx->details_comp->cfg.with_data) {
+               goto end;
+       }
+
        if (bt_stream_class_discarded_events_have_default_clock_snapshots(sc)) {
                beginning_cs =
                        bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const(
@@ -2417,14 +2499,18 @@ int write_discarded_events_message(struct details_write_ctx *ctx,
                count = UINT64_C(-1);
        }
 
-       return write_discarded_items_message(ctx, "events", stream,
+       ret = write_discarded_items_message(ctx, "events", stream,
                beginning_cs, end_cs, count);
+
+end:
+       return ret;
 }
 
 static
 int write_discarded_packets_message(struct details_write_ctx *ctx,
                const bt_message *msg)
 {
+       int ret = 0;
        const bt_stream *stream = bt_message_discarded_packets_borrow_stream_const(
                msg);
        const bt_stream_class *sc = bt_stream_borrow_class_const(stream);
@@ -2432,6 +2518,10 @@ int write_discarded_packets_message(struct details_write_ctx *ctx,
        const bt_clock_snapshot *end_cs = NULL;
        uint64_t count;
 
+       if (!ctx->details_comp->cfg.with_data) {
+               goto end;
+       }
+
        if (bt_stream_class_discarded_packets_have_default_clock_snapshots(sc)) {
                beginning_cs =
                        bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const(
@@ -2446,8 +2536,11 @@ int write_discarded_packets_message(struct details_write_ctx *ctx,
                count = UINT64_C(-1);
        }
 
-       return write_discarded_items_message(ctx, "packets", stream,
+       ret = write_discarded_items_message(ctx, "packets", stream,
                beginning_cs, end_cs, count);
+
+end:
+       return ret;
 }
 
 static
@@ -2460,6 +2553,10 @@ int write_packet_end_message(struct details_write_ctx *ctx,
        const bt_stream *stream = bt_packet_borrow_stream_const(packet);
        const bt_stream_class *sc = bt_stream_borrow_class_const(stream);
 
+       if (!ctx->details_comp->cfg.with_data) {
+               goto end;
+       }
+
        /* Write time */
        if (bt_stream_class_packets_have_end_default_clock_snapshot(sc)) {
                write_time(ctx,
@@ -2528,10 +2625,6 @@ int details_write_message(struct details_comp *details_comp,
        /* Reset output buffer */
        g_string_assign(details_comp->str, "");
 
-       if (details_comp->printed_something && !details_comp->cfg.compact) {
-               write_nl(&ctx);
-       }
-
        switch (bt_message_get_type(msg)) {
        case BT_MESSAGE_TYPE_EVENT:
                ret = write_event_message(&ctx, msg);
@@ -2561,5 +2654,17 @@ int details_write_message(struct details_comp *details_comp,
                abort();
        }
 
+       /*
+        * If this component printed at least one character so far, and
+        * we're not in compact mode, and there's something in the
+        * output buffer for this message, then prepend a newline to the
+        * output buffer to visually separate message blocks.
+        */
+       if (details_comp->printed_something && !details_comp->cfg.compact &&
+                       details_comp->str->len > 0) {
+               /* TODO: Optimize this */
+               g_string_prepend_c(details_comp->str, '\n');
+       }
+
        return ret;
 }
This page took 0.028348 seconds and 4 git commands to generate.