sink.text.details: print option field classes and fields
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 12 Aug 2019 22:25:17 +0000 (18:25 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 4 Sep 2019 15:58:21 +0000 (11:58 -0400)
The component prints `None` when there's no current optional field.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Iaa0634ce6806508fa8b07fc70e0e021af9363b8d
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1900
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
src/plugins/text/details/write.c

index f6d0eea813c22c6df1410208528af1ec9e1e000c..fa150b6abe6bfb54b438686d4aaf30bf6d1c1345 100644 (file)
@@ -230,6 +230,14 @@ void write_str_prop_value(struct details_write_ctx *ctx, const char *value)
                color_bold(ctx), value, color_reset(ctx));
 }
 
+static inline
+void write_none_prop_value(struct details_write_ctx *ctx, const char *value)
+{
+       g_string_append_printf(ctx->str, "%s%s%s%s",
+               color_bold(ctx), color_fg_magenta(ctx),
+               value, color_reset(ctx));
+}
+
 static inline
 void write_uint_str_prop_value(struct details_write_ctx *ctx, const char *value)
 {
@@ -799,6 +807,9 @@ 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";
+               break;
        case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR:
                type = "Variant (no selector)";
                break;
@@ -912,6 +923,27 @@ void write_field_class(struct details_write_ctx *ctx, const bt_field_class *fc)
                        bt_field_class_array_borrow_element_field_class_const(fc));
                decr_indent(ctx);
                break;
+       case BT_FIELD_CLASS_TYPE_OPTION:
+       {
+               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, ')');
+               }
+
+               g_string_append_c(ctx->str, ':');
+               write_nl(ctx);
+               incr_indent(ctx);
+               write_compound_member_name(ctx, "Content");
+               write_sp(ctx);
+               write_field_class(ctx,
+                       bt_field_class_option_borrow_field_class_const(fc));
+               decr_indent(ctx);
+               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:
@@ -1599,6 +1631,20 @@ void write_field(struct details_write_ctx *ctx, const bt_field *field,
                decr_indent(ctx);
                break;
        }
+       case BT_FIELD_CLASS_TYPE_OPTION:
+       {
+               const bt_field *content_field =
+                       bt_field_option_borrow_field_const(field);
+
+               if (!content_field) {
+                       write_sp(ctx);
+                       write_none_prop_value(ctx, "None");
+               } else {
+                       write_field(ctx, content_field, NULL);
+               }
+
+               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:
This page took 0.026102 seconds and 4 git commands to generate.