Clean-up: modernize pretty_xml.cpp
[lttng-tools.git] / src / bin / lttng-sessiond / ust-field-convert.cpp
index 67fcdf1b21b786e2a90e7a0d10e19835b9d6f68d..b51ba7bfc2c7e55ea4749b0e2d41807a7a33deed 100644 (file)
 
 namespace lst = lttng::sessiond::trace;
 namespace lsu = lttng::sessiond::ust;
-namespace {
 
+/*
+ * fmtlib helper that must be under the same namespace as lttng_ust_ctl_abstract_types
+ * (global).
+ */
+static int format_as(lttng_ust_ctl_abstract_types type)
+{
+       return fmt::underlying(type);
+}
+
+namespace {
 /*
  * Type enclosing the session information that may be required during the decoding
  * of the lttng_ust_ctl_field array provided by applications on registration of
@@ -81,7 +90,7 @@ ust_ctl_encoding_to_string_field_encoding(UstCtlEncodingType encoding)
 
        const auto encoding_it = encoding_conversion_map.find(encoding);
        if (encoding_it == encoding_conversion_map.end()) {
-               LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+               LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                        "Unknown lttng_ust_ctl_string_encodings value `{}` encountered when decoding integer field",
                        encoding));
        }
@@ -100,7 +109,7 @@ enum lst::integer_type::base ust_ctl_base_to_integer_field_base(UstCtlBaseType b
 
        const auto base_it = base_conversion_map.find(base);
        if (base_it == base_conversion_map.end()) {
-               LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+               LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                        "Unknown integer base value `{}` encountered when decoding integer field",
                        base));
        }
@@ -116,7 +125,7 @@ create_integer_type_from_ust_ctl_fields(const lttng_ust_ctl_field *current,
                                        lsu::ctl_field_quirks quirks __attribute__((unused)))
 {
        if (current >= end) {
-               LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+               LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                        "End of {} array reached unexpectedly during decoding", typeid(*current)));
        }
 
@@ -145,7 +154,7 @@ create_floating_point_type_from_ust_ctl_fields(const lttng_ust_ctl_field *curren
                                               lsu::ctl_field_quirks quirks __attribute__((unused)))
 {
        if (current >= end) {
-               LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+               LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                        "End of {} array reached unexpectedly during decoding", typeid(*current)));
        }
 
@@ -162,7 +171,7 @@ create_floating_point_type_from_ust_ctl_fields(const lttng_ust_ctl_field *curren
                        current->type.u._float.exp_dig,
                        current->type.u._float.mant_dig);
        } catch (lttng::invalid_argument_error& ex) {
-               LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+               LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                        "Invalid floating point attribute in {}: {}", typeid(*current), ex.what()));
        }
 }
@@ -175,7 +184,7 @@ create_enumeration_type_from_ust_ctl_fields(const lttng_ust_ctl_field *current,
                                            lsu::ctl_field_quirks quirks __attribute__((unused)))
 {
        if (current >= end) {
-               LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+               LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                        "End of {} array reached unexpectedly during decoding", typeid(*current)));
        }
 
@@ -189,15 +198,15 @@ create_enumeration_type_from_ust_ctl_fields(const lttng_ust_ctl_field *current,
                /* Nestable enumeration fields are followed by their container type. */
                ++current;
                if (current >= end) {
-                       LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+                       LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                                "Array of {} is too short to contain nestable enumeration's container",
                                typeid(*current)));
                }
 
                if (current->type.atype != lttng_ust_ctl_atype_integer) {
-                       LTTNG_THROW_PROTOCOL_ERROR(
-                               fmt::format("Invalid type of nestable enum container: type id = {}",
-                                           current->type.atype));
+                       LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
+                               "Invalid type of nestable enum container: type id = {}",
+                               current->type.atype));
                }
 
                enum_container_uctl_type = &current->type.u.integer;
@@ -250,7 +259,7 @@ create_string_type_from_ust_ctl_fields(const lttng_ust_ctl_field *current,
                                       lsu::ctl_field_quirks quirks __attribute__((unused)))
 {
        if (current >= end) {
-               LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+               LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                        "End of {} array reached unexpectedly during decoding", typeid(*current)));
        }
 
@@ -292,7 +301,7 @@ create_array_type_from_ust_ctl_fields(const lttng_ust_ctl_field *current,
                                      lsu::ctl_field_quirks quirks __attribute__((unused)))
 {
        if (current >= end) {
-               LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+               LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                        "End of {} array reached unexpectedly during decoding", typeid(*current)));
        }
 
@@ -306,7 +315,7 @@ create_array_type_from_ust_ctl_fields(const lttng_ust_ctl_field *current,
 
        const auto& element_uctl_type = array_uctl_field.type.u.legacy.array.elem_type;
        if (element_uctl_type.atype != lttng_ust_ctl_atype_integer) {
-               LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+               LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                        "Unexpected legacy array element type: atype = {}, expected atype = lttng_ust_ctl_atype_integer ({})",
                        element_uctl_type.atype,
                        lttng_ust_ctl_atype_integer));
@@ -328,7 +337,7 @@ create_array_type_from_ust_ctl_fields(const lttng_ust_ctl_field *current,
                        static_cast<const lst::integer_type&>(*element_type).size;
 
                if (integer_element_size != 8) {
-                       LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+                       LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                                "Unexpected legacy array element type: integer has encoding but size is not 8: size = {}",
                                integer_element_size));
                }
@@ -354,7 +363,7 @@ lst::type::cuptr create_array_nestable_type_from_ust_ctl_fields(
        lsu::ctl_field_quirks quirks)
 {
        if (current >= end) {
-               LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+               LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                        "End of {} array reached unexpectedly during decoding", typeid(*current)));
        }
 
@@ -391,7 +400,7 @@ lst::type::cuptr create_array_nestable_type_from_ust_ctl_fields(
                        static_cast<const lst::integer_type&>(*element_type).size;
 
                if (integer_element_size != 8) {
-                       LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+                       LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                                "Unexpected array element type: integer has encoding but size is not 8: size = {}",
                                integer_element_size));
                }
@@ -420,7 +429,7 @@ lst::type::cuptr create_sequence_type_from_ust_ctl_fields(
        lsu::ctl_field_quirks quirks __attribute__((unused)))
 {
        if (current >= end) {
-               LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+               LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                        "End of {} array reached unexpectedly during decoding", typeid(*current)));
        }
 
@@ -430,14 +439,14 @@ lst::type::cuptr create_sequence_type_from_ust_ctl_fields(
        const auto sequence_alignment = 0U;
 
        if (element_uctl_type.atype != lttng_ust_ctl_atype_integer) {
-               LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+               LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                        "Unexpected legacy sequence element type: atype = {}, expected atype = lttng_ust_ctl_atype_integer ({})",
                        element_uctl_type.atype,
                        lttng_ust_ctl_atype_integer));
        }
 
        if (length_uctl_type.atype != lttng_ust_ctl_atype_integer) {
-               LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+               LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                        "Unexpected legacy sequence length field type: atype = {}, expected atype = lttng_ust_ctl_atype_integer ({})",
                        length_uctl_type.atype,
                        lttng_ust_ctl_atype_integer));
@@ -451,7 +460,7 @@ lst::type::cuptr create_sequence_type_from_ust_ctl_fields(
                        element_uctl_type.u.basic.integer.encoding);
        }
 
-       auto length_field_name = fmt::format("_{}_length", sequence_uctl_field.name);
+       auto length_field_name = lttng::format("_{}_length", sequence_uctl_field.name);
        auto element_type =
                create_integer_type_from_ust_ctl_basic_type(element_uctl_type, session_attributes);
        auto length_type =
@@ -475,7 +484,7 @@ lst::type::cuptr create_sequence_type_from_ust_ctl_fields(
                        static_cast<const lst::integer_type&>(*element_type).size;
 
                if (integer_element_size != 8) {
-                       LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+                       LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                                "Unexpected legacy array element type: integer has encoding but size is not 8: size = {}",
                                integer_element_size));
                }
@@ -501,7 +510,7 @@ lst::type::cuptr create_sequence_nestable_type_from_ust_ctl_fields(
        lsu::ctl_field_quirks quirks)
 {
        if (current >= end) {
-               LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+               LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                        "End of {} array reached unexpectedly during decoding", typeid(*current)));
        }
 
@@ -539,7 +548,7 @@ lst::type::cuptr create_sequence_nestable_type_from_ust_ctl_fields(
 
        lst::field_location::elements length_field_location_elements =
                current_field_location_elements;
-       length_field_location_elements.emplace_back(std::move(length_field_name));
+       length_field_location_elements.emplace_back(length_field_name);
 
        lst::field_location length_field_location{ lookup_root,
                                                   std::move(length_field_location_elements) };
@@ -558,7 +567,7 @@ lst::type::cuptr create_sequence_nestable_type_from_ust_ctl_fields(
                        static_cast<const lst::integer_type&>(*element_type).size;
 
                if (integer_element_size != 8) {
-                       LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+                       LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                                "Unexpected array element type: integer has encoding but size is not 8: size = {}",
                                integer_element_size));
                }
@@ -581,7 +590,7 @@ create_structure_field_from_ust_ctl_fields(const lttng_ust_ctl_field *current,
                                           lsu::ctl_field_quirks quirks __attribute__((unused)))
 {
        if (current >= end) {
-               LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+               LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                        "End of {} array reached unexpectedly during decoding", typeid(*current)));
        }
 
@@ -598,7 +607,7 @@ create_structure_field_from_ust_ctl_fields(const lttng_ust_ctl_field *current,
        }
 
        if (field_count != 0) {
-               LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+               LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                        "Only empty structures are supported by LTTng-UST: nr_fields = {}",
                        field_count));
        }
@@ -631,7 +640,7 @@ create_typed_variant_choices(const lttng_ust_ctl_field *current,
                        end,
                        session_attributes,
                        next_ust_ctl_field,
-                       [&choices, typed_enumeration, &selector_field, quirks](
+                       [&choices, &typed_enumeration, &selector_field, quirks](
                                lst::field::uptr field) {
                                /*
                                 * Find the enumeration mapping that matches the
@@ -664,7 +673,7 @@ create_typed_variant_choices(const lttng_ust_ctl_field *current,
                                        });
 
                                if (mapping_it == typed_enumeration.mappings_->end()) {
-                                       LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+                                       LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                                                "Invalid variant choice: `{}` does not match any mapping in `{}` enumeration",
                                                field->name,
                                                selector_field.name));
@@ -694,7 +703,7 @@ lst::type::cuptr create_variant_field_from_ust_ctl_fields(
        lsu::ctl_field_quirks quirks)
 {
        if (current >= end) {
-               LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+               LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                        "End of {} array reached unexpectedly during decoding", typeid(*current)));
        }
 
@@ -846,11 +855,11 @@ create_type_from_ust_ctl_fields(const lttng_ust_ctl_field *current,
                                                                quirks);
        default:
                LTTNG_THROW_PROTOCOL_ERROR(
-                       fmt::format("Unknown {} value `{}` encountered while converting {} to {}",
-                                   typeid(current->type.atype),
-                                   current->type.atype,
-                                   typeid(*current),
-                                   typeid(lst::type::cuptr::element_type)));
+                       lttng::format("Unknown {} value `{}` encountered while converting {} to {}",
+                                     typeid(current->type.atype),
+                                     current->type.atype,
+                                     typeid(*current),
+                                     typeid(lst::type::cuptr::element_type)));
        }
 }
 
@@ -868,7 +877,7 @@ void create_field_from_ust_ctl_fields(const lttng_ust_ctl_field *current,
 
        if (lttng_strnlen(current->name, sizeof(current->name)) == sizeof(current->name)) {
                LTTNG_THROW_PROTOCOL_ERROR(
-                       fmt::format("Name of {} is not null-terminated", typeid(*current)));
+                       lttng::format("Name of {} is not null-terminated", typeid(*current)));
        }
 
        publish_field(lttng::make_unique<lst::field>(
@@ -888,7 +897,7 @@ std::vector<lst::field::cuptr>::iterator
 lookup_field_in_vector(std::vector<lst::field::cuptr>& fields, const lst::field_location& location)
 {
        if (location.elements_.size() != 1) {
-               LTTNG_THROW_ERROR(fmt::format(
+               LTTNG_THROW_ERROR(lttng::format(
                        "Unexpected field location received during field look-up: location = {}",
                        location));
        }
@@ -907,7 +916,7 @@ lookup_field_in_vector(std::vector<lst::field::cuptr>& fields, const lst::field_
 
        if (field_it == fields.end()) {
                LTTNG_THROW_PROTOCOL_ERROR(
-                       fmt::format("Failed to look-up field: location = {}", location));
+                       lttng::format("Failed to look-up field: location = {}", location));
        }
 
        return field_it;
This page took 0.0282 seconds and 4 git commands to generate.