lib: add option field classes with integer selectors
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 2 Oct 2019 18:30:17 +0000 (14:30 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 9 Oct 2019 18:14:29 +0000 (14:14 -0400)
commit467673c1a8e30cc146cddffa1970bbb430052680
treed2b7993ed8e75d83b6db4cf83046c8a30fdcfa1d
parent05189245f61dcc2ae98aa58ef7a26b44c4904cda
lib: add option field classes with integer selectors

This patch adds two new option field classes which have unsigned and
signed integer field classes as selectors. The purpose of this patch is
to be able to use the same selector for an option field class and a
contained, optional variant field class so that you can save space. For
example (pseudo-TSDL):

    enum : integer { size = 8; } {
        NONE,
        BANANA,
        APPLE,
    } tag;

    option <tag> {
        variant <tag> {
            string BANANA <1>;
            int APPLE <2>;
        } <1...0xff>;
    } opt_var;

Above, the optional variant field does not exist when the `tag` field is
0. If `tag` is anything else, then the variant field exists, and the
selected variant field's option also depends on this same value (1 and 2
select existing options).

Library changes
===============
There are now four option field classes:

Option without selector:
    Create with:

        bt_field_class *bt_field_class_option_without_selector_create(
            bt_trace_class *trace_class,
            bt_field_class *content_field_class);

Option with boolean selector:
    Create with:

        bt_field_class *bt_field_class_option_with_selector_bool_create(
            bt_trace_class *trace_class,
            bt_field_class *content_field_class,
            bt_field_class *selector_field_class);

    `selector_field_class` must be a boolean field class.

    By default, the selector is not reversed, in that when the selector
    boolean field is true, the option's field exists.

    You can reverse this logic with:

        void bt_field_class_option_with_selector_bool_set_selector_is_reversed(
            bt_field_class *field_class, bt_bool selector_is_reversed);

    You can get this property with:

        bt_bool
        bt_field_class_option_with_selector_bool_selector_is_reversed(
            const bt_field_class *field_class);

Option with unsigned integer selector:
Option with signed integer selector:
    Create with one of:

        bt_field_class *
        bt_field_class_option_with_selector_integer_unsigned_create(
            bt_trace_class *trace_class,
            bt_field_class *content_field_class,
            bt_field_class *selector_field_class,
            const bt_integer_range_set_unsigned *range_set);

        bt_field_class *
        bt_field_class_option_with_selector_integer_signed_create(
            bt_trace_class *trace_class,
            bt_field_class *content_field_class,
            bt_field_class *selector_field_class,
            const bt_integer_range_set_signed *range_set);

    For both versions:

    * `selector_field_class` must be an integer field class.

    * `range_set` tells, for such an option field, which values of the
      selector field make it contain the optional field.

    * `range_set` must contain at least one integer range.

    * On success, the function freezes `range_set`.

    You can borrow the integer range sets with:

        const bt_integer_range_set_unsigned *
        bt_field_class_option_with_selector_integer_unsigned_borrow_ranges_const(
            const bt_field_class *field_class);

        const bt_integer_range_set_signed *
        bt_field_class_option_with_selector_integer_signed_borrow_ranges_const(
            const bt_field_class *field_class);

Python bindings changes
=======================
There are new Python classes in `field_class.py` to wrap the new field
classes.

To create the new field classes, use:

* _TraceClass.create_option_without_selector_field_class()
* _TraceClass.create_option_with_bool_selector_field_class()
* _TraceClass.create_option_with_integer_selector_field_class()

_TraceClass.create_option_with_integer_selector_field_class() relies on
the type of `selector_fc` to create either an option with unsigned
integer selector field class or an option with signed integer selector
field class.

Notable component class changes
===============================
`flt.lttng-utils.debug-info`:
    Copies all option field classes and their properties.

`sink.text.details`:
    Writes all the option field class properties:

    * Whether or not the selector is reversed for an option with boolean
      selector field class.

      It looks like this:

          opt: Option (boolean selector) (Selector field path [Event payload: 2]):
            Selector is reversed: Yes
            Content: Unsigned integer (64-bit, Base 10)

    * The sorted integer ranges for an option with integer selector
      field class.

      It looks like this:

          opt: Option (signed integer selector) (Selector field path [Event payload: 1]):
            Selector ranges: [1, 1548] [1634] [2960, 3505]
            Content: Unsigned integer (64-bit, Base 10)

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I31e1deba974bf30274d567a73a00ea80d028f7ae
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2122
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
21 files changed:
include/babeltrace2/trace-ir/field-class-const.h
include/babeltrace2/trace-ir/field-class.h
src/bindings/python/bt2/bt2/__init__.py
src/bindings/python/bt2/bt2/field.py
src/bindings/python/bt2/bt2/field_class.py
src/bindings/python/bt2/bt2/trace_class.py
src/common/common.h
src/lib/lib-logging.c
src/lib/trace-ir/field-class.c
src/lib/trace-ir/field-class.h
src/lib/trace-ir/field.c
src/lib/trace-ir/field.h
src/lib/trace-ir/resolve-field-path.c
src/plugins/ctf/fs-sink/translate-trace-ir-to-ctf-ir.c
src/plugins/lttng-utils/debug-info/trace-ir-data-copy.c
src/plugins/lttng-utils/debug-info/trace-ir-metadata-field-class-copy.c
src/plugins/text/details/write.c
src/plugins/text/pretty/print.c
tests/bindings/python/bt2/test_field.py
tests/bindings/python/bt2/test_field_class.py
tests/bindings/python/bt2/test_package.py
This page took 0.027363 seconds and 4 git commands to generate.