lib: Fix function name to match declaration
[babeltrace.git] / lib / trace-ir / field-class.c
index ed7b2121b9513212aeb7dc97a97f14d4a9575bd4..dad075e80df0a582204a3fa6b69e44099038c291 100644 (file)
 #include <babeltrace/trace-ir/field-const.h>
 #include <babeltrace/trace-ir/field.h>
 #include <babeltrace/trace-ir/utils-internal.h>
-#include <babeltrace/object.h>
 #include <babeltrace/trace-ir/clock-class.h>
 #include <babeltrace/trace-ir/clock-class-internal.h>
 #include <babeltrace/object-internal.h>
-#include <babeltrace/object.h>
 #include <babeltrace/compiler-internal.h>
 #include <babeltrace/endian-internal.h>
 #include <babeltrace/assert-internal.h>
@@ -83,10 +81,12 @@ void destroy_integer_field_class(struct bt_object *obj)
 }
 
 static inline
-struct bt_field_class *create_integer_field_class(enum bt_field_class_type type)
+struct bt_field_class *create_integer_field_class(bt_trace_class *trace_class,
+               enum bt_field_class_type type)
 {
        struct bt_field_class_integer *int_fc = NULL;
 
+       BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class");
        BT_LOGD("Creating default integer field class object: type=%s",
                bt_common_field_class_type_string(type));
        int_fc = g_new0(struct bt_field_class_integer, 1);
@@ -106,16 +106,17 @@ end:
        return (void *) int_fc;
 }
 
-struct bt_field_class *
-bt_field_class_unsigned_integer_create(void)
+struct bt_field_class *bt_field_class_unsigned_integer_create(
+               bt_trace_class *trace_class)
 {
-       return create_integer_field_class(
+       return create_integer_field_class(trace_class,
                BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER);
 }
 
-struct bt_field_class *bt_field_class_signed_integer_create(void)
+struct bt_field_class *bt_field_class_signed_integer_create(
+               bt_trace_class *trace_class)
 {
-       return create_integer_field_class(
+       return create_integer_field_class(trace_class,
                BT_FIELD_CLASS_TYPE_SIGNED_INTEGER);
 }
 
@@ -228,10 +229,11 @@ void destroy_enumeration_field_class(struct bt_object *obj)
 
 static
 struct bt_field_class *create_enumeration_field_class(
-               enum bt_field_class_type type)
+               bt_trace_class *trace_class, enum bt_field_class_type type)
 {
        struct bt_field_class_enumeration *enum_fc = NULL;
 
+       BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class");
        BT_LOGD("Creating default enumeration field class object: type=%s",
                bt_common_field_class_type_string(type));
        enum_fc = g_new0(struct bt_field_class_enumeration, 1);
@@ -265,15 +267,17 @@ end:
        return (void *) enum_fc;
 }
 
-struct bt_field_class *bt_field_class_unsigned_enumeration_create(void)
+struct bt_field_class *bt_field_class_unsigned_enumeration_create(
+               bt_trace_class *trace_class)
 {
-       return create_enumeration_field_class(
+       return create_enumeration_field_class(trace_class,
                BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION);
 }
 
-struct bt_field_class *bt_field_class_signed_enumeration_create(void)
+struct bt_field_class *bt_field_class_signed_enumeration_create(
+               bt_trace_class *trace_class)
 {
-       return create_enumeration_field_class(
+       return create_enumeration_field_class(trace_class,
                BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION);
 }
 
@@ -372,7 +376,7 @@ void bt_field_class_unsigned_enumeration_mapping_ranges_get_range_by_index(
 }
 
 void bt_field_class_signed_enumeration_mapping_ranges_get_range_by_index(
-               const struct bt_field_class_unsigned_enumeration_mapping_ranges *ranges,
+               const struct bt_field_class_signed_enumeration_mapping_ranges *ranges,
                uint64_t index, int64_t *lower, int64_t *upper)
 {
        get_enumeration_field_class_mapping_range_at_index(
@@ -382,7 +386,8 @@ void bt_field_class_signed_enumeration_mapping_ranges_get_range_by_index(
 
 
 
-int bt_field_class_unsigned_enumeration_get_mapping_labels_by_value(
+enum bt_field_class_status
+bt_field_class_unsigned_enumeration_get_mapping_labels_by_value(
                const struct bt_field_class *fc, uint64_t value,
                bt_field_class_enumeration_mapping_label_array *label_array,
                uint64_t *count)
@@ -418,10 +423,11 @@ int bt_field_class_unsigned_enumeration_get_mapping_labels_by_value(
 
        *label_array = (void *) enum_fc->label_buf->pdata;
        *count = (uint64_t) enum_fc->label_buf->len;
-       return 0;
+       return BT_FIELD_CLASS_STATUS_OK;
 }
 
-int bt_field_class_signed_enumeration_get_mapping_labels_by_value(
+enum bt_field_class_status
+bt_field_class_signed_enumeration_get_mapping_labels_by_value(
                const struct bt_field_class *fc, int64_t value,
                bt_field_class_enumeration_mapping_label_array *label_array,
                uint64_t *count)
@@ -457,14 +463,15 @@ int bt_field_class_signed_enumeration_get_mapping_labels_by_value(
 
        *label_array = (void *) enum_fc->label_buf->pdata;
        *count = (uint64_t) enum_fc->label_buf->len;
-       return 0;
+       return BT_FIELD_CLASS_STATUS_OK;
 }
 
 static inline
-int add_mapping_to_enumeration_field_class(struct bt_field_class *fc,
+enum bt_field_class_status add_mapping_to_enumeration_field_class(
+               struct bt_field_class *fc,
                const char *label, uint64_t lower, uint64_t upper)
 {
-       int ret = 0;
+       int ret = BT_FIELD_CLASS_STATUS_OK;
        uint64_t i;
        struct bt_field_class_enumeration *enum_fc = (void *) fc;
        struct bt_field_class_enumeration_mapping *mapping = NULL;
@@ -495,7 +502,7 @@ int add_mapping_to_enumeration_field_class(struct bt_field_class *fc,
                        finalize_enumeration_field_class_mapping(mapping);
                        g_array_set_size(enum_fc->mappings,
                                enum_fc->mappings->len - 1);
-                       ret = -1;
+                       ret = BT_FIELD_CLASS_STATUS_NOMEM;
                        goto end;
                }
 
@@ -504,7 +511,7 @@ int add_mapping_to_enumeration_field_class(struct bt_field_class *fc,
                        finalize_enumeration_field_class_mapping(mapping);
                        g_array_set_size(enum_fc->mappings,
                                enum_fc->mappings->len - 1);
-                       ret = -1;
+                       ret = BT_FIELD_CLASS_STATUS_NOMEM;
                        goto end;
                }
        }
@@ -524,7 +531,7 @@ end:
        return ret;
 }
 
-int bt_field_class_unsigned_enumeration_map_range(
+enum bt_field_class_status bt_field_class_unsigned_enumeration_map_range(
                struct bt_field_class *fc, const char *label,
                uint64_t range_lower, uint64_t range_upper)
 {
@@ -549,7 +556,7 @@ int bt_field_class_unsigned_enumeration_map_range(
                range_upper);
 }
 
-int bt_field_class_signed_enumeration_map_range(
+enum bt_field_class_status bt_field_class_signed_enumeration_map_range(
                struct bt_field_class *fc, const char *label,
                int64_t range_lower, int64_t range_upper)
 {
@@ -582,10 +589,11 @@ void destroy_real_field_class(struct bt_object *obj)
        g_free(obj);
 }
 
-struct bt_field_class *bt_field_class_real_create(void)
+struct bt_field_class *bt_field_class_real_create(bt_trace_class *trace_class)
 {
        struct bt_field_class_real *real_fc = NULL;
 
+       BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class");
        BT_LOGD_STR("Creating default real field class object.");
        real_fc = g_new0(struct bt_field_class_real, 1);
        if (!real_fc) {
@@ -699,16 +707,18 @@ static
 void destroy_structure_field_class(struct bt_object *obj)
 {
        BT_ASSERT(obj);
-       BT_LIB_LOGD("Destroying string field class object: %!+F", obj);
+       BT_LIB_LOGD("Destroying structure field class object: %!+F", obj);
        finalize_named_field_classes_container((void *) obj);
        g_free(obj);
 }
 
-struct bt_field_class *bt_field_class_structure_create(void)
+struct bt_field_class *bt_field_class_structure_create(
+               bt_trace_class *trace_class)
 {
        int ret;
        struct bt_field_class_structure *struct_fc = NULL;
 
+       BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class");
        BT_LOGD_STR("Creating default structure field class object.");
        struct_fc = g_new0(struct bt_field_class_structure, 1);
        if (!struct_fc) {
@@ -733,11 +743,11 @@ end:
 }
 
 static
-int append_named_field_class_to_container_field_class(
+enum bt_field_class_status append_named_field_class_to_container_field_class(
                struct bt_field_class_named_field_class_container *container_fc,
                const char *name, struct bt_field_class *fc)
 {
-       int ret = 0;
+       int ret = BT_FIELD_CLASS_STATUS_OK;
        struct bt_named_field_class *named_fc;
        GString *name_str;
 
@@ -752,7 +762,7 @@ int append_named_field_class_to_container_field_class(
        name_str = g_string_new(name);
        if (!name_str) {
                BT_LOGE_STR("Failed to allocate a GString.");
-               ret = -1;
+               ret = BT_FIELD_CLASS_STATUS_NOMEM;
                goto end;
        }
 
@@ -765,18 +775,26 @@ int append_named_field_class_to_container_field_class(
        bt_object_get_no_null_check(fc);
        g_hash_table_insert(container_fc->name_to_index, named_fc->name->str,
                GUINT_TO_POINTER(container_fc->named_fcs->len - 1));
+
+       /*
+        * Freeze the field class, but not the named field class (the
+        * user can still modify it, if possible, until the container
+        * itself is frozen).
+        */
        bt_field_class_freeze(fc);
 
 end:
        return ret;
 }
 
-int bt_field_class_structure_append_member(struct bt_field_class *fc,
-               const char *name, struct bt_field_class *member_fc)
+enum bt_field_class_status bt_field_class_structure_append_member(
+               struct bt_field_class *fc, const char *name,
+               struct bt_field_class *member_fc)
 {
 
        BT_ASSERT_PRE_NON_NULL(fc, "Field class");
-       BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, "Field class");
+       BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE,
+               "Field class");
        return append_named_field_class_to_container_field_class((void *) fc,
                name, member_fc);
 }
@@ -787,45 +805,53 @@ uint64_t bt_field_class_structure_get_member_count(
        struct bt_field_class_structure *struct_fc = (void *) fc;
 
        BT_ASSERT_PRE_NON_NULL(fc, "Field class");
-       BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, "Field class");
+       BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE,
+               "Field class");
        return (uint64_t) struct_fc->common.named_fcs->len;
 }
 
 static
-void borrow_named_field_class_from_container_field_class_at_index_const(
-               const struct bt_field_class_named_field_class_container *fc,
-               uint64_t index, const char **name,
-               const struct bt_field_class **out_fc)
+struct bt_named_field_class *
+borrow_named_field_class_from_container_field_class_at_index(
+               struct bt_field_class_named_field_class_container *fc,
+               uint64_t index)
 {
-       const struct bt_named_field_class *named_fc;
-
        BT_ASSERT(fc);
-       BT_ASSERT_PRE_NON_NULL(name, "Name");
-       BT_ASSERT_PRE_NON_NULL(out_fc, "Field class (output)");
        BT_ASSERT_PRE_VALID_INDEX(index, fc->named_fcs->len);
-       named_fc = BT_FIELD_CLASS_NAMED_FC_AT_INDEX(fc, index);
-       *name = named_fc->name->str;
-       *out_fc = named_fc->fc;
+       return BT_FIELD_CLASS_NAMED_FC_AT_INDEX(fc, index);
 }
 
-void bt_field_class_structure_borrow_member_by_index_const(
-               const struct bt_field_class *fc, uint64_t index,
-               const char **name, const struct bt_field_class **out_fc)
+const struct bt_field_class_structure_member *
+bt_field_class_structure_borrow_member_by_index_const(
+               const struct bt_field_class *fc, uint64_t index)
 {
        BT_ASSERT_PRE_NON_NULL(fc, "Field class");
-       BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, "Field class");
-       borrow_named_field_class_from_container_field_class_at_index_const(
-               (void *) fc, index, name, out_fc);
+       BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE,
+               "Field class");
+       return (const void *)
+               borrow_named_field_class_from_container_field_class_at_index(
+                       (void *) fc, index);
+}
+
+struct bt_field_class_structure_member *
+bt_field_class_structure_borrow_member_by_index(
+               struct bt_field_class *fc, uint64_t index)
+{
+       BT_ASSERT_PRE_NON_NULL(fc, "Field class");
+       BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE,
+               "Field class");
+       return (void *)
+               borrow_named_field_class_from_container_field_class_at_index(
+                       (void *) fc, index);
 }
 
 static
-const struct bt_field_class *
-borrow_field_class_from_container_field_class_by_name_const(
-               const struct bt_field_class_named_field_class_container *fc,
+struct bt_named_field_class *
+borrow_named_field_class_from_container_field_class_by_name(
+               struct bt_field_class_named_field_class_container *fc,
                const char *name)
 {
-       const struct bt_field_class *ret_fc = NULL;
-       const struct bt_named_field_class *named_fc;
+       struct bt_named_field_class *named_fc = NULL;
        gpointer orig_key;
        gpointer value;
 
@@ -838,22 +864,64 @@ borrow_field_class_from_container_field_class_by_name_const(
 
        named_fc = BT_FIELD_CLASS_NAMED_FC_AT_INDEX(fc,
                GPOINTER_TO_UINT(value));
-       ret_fc = named_fc->fc;
 
 end:
-       return ret_fc;
+       return named_fc;
 }
 
-const struct bt_field_class *
-bt_field_class_structure_borrow_member_field_class_by_name(
+const struct bt_field_class_structure_member *
+bt_field_class_structure_borrow_member_by_name_const(
                const struct bt_field_class *fc, const char *name)
 {
        BT_ASSERT_PRE_NON_NULL(fc, "Field class");
-       BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, "Field class");
-       return borrow_field_class_from_container_field_class_by_name_const(
+       BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE,
+               "Field class");
+       return (const void *)
+               borrow_named_field_class_from_container_field_class_by_name(
                        (void *) fc, name);
 }
 
+struct bt_field_class_structure_member *
+bt_field_class_structure_borrow_member_by_name(
+               struct bt_field_class *fc, const char *name)
+{
+       BT_ASSERT_PRE_NON_NULL(fc, "Field class");
+       BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE,
+               "Field class");
+       return (void *)
+               borrow_named_field_class_from_container_field_class_by_name(
+                       (void *) fc, name);
+}
+
+const char *bt_field_class_structure_member_get_name(
+               const struct bt_field_class_structure_member *member)
+{
+       const struct bt_named_field_class *named_fc = (const void *) member;
+
+       BT_ASSERT_PRE_NON_NULL(member, "Structure field class member");
+       return named_fc->name->str;
+}
+
+const struct bt_field_class *
+bt_field_class_structure_member_borrow_field_class_const(
+               const struct bt_field_class_structure_member *member)
+{
+       const struct bt_named_field_class *named_fc = (const void *) member;
+
+       BT_ASSERT_PRE_NON_NULL(member, "Structure field class member");
+       return named_fc->fc;
+}
+
+struct bt_field_class *
+bt_field_class_structure_member_borrow_field_class(
+               struct bt_field_class_structure_member *member)
+{
+       struct bt_named_field_class *named_fc = (void *) member;
+
+       BT_ASSERT_PRE_NON_NULL(member, "Structure field class member");
+       return named_fc->fc;
+}
+
 static
 void destroy_variant_field_class(struct bt_object *obj)
 {
@@ -869,11 +937,13 @@ void destroy_variant_field_class(struct bt_object *obj)
        g_free(fc);
 }
 
-struct bt_field_class *bt_field_class_variant_create(void)
+struct bt_field_class *bt_field_class_variant_create(
+               bt_trace_class *trace_class)
 {
        int ret;
        struct bt_field_class_variant *var_fc = NULL;
 
+       BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class");
        BT_LOGD_STR("Creating default variant field class object.");
        var_fc = g_new0(struct bt_field_class_variant, 1);
        if (!var_fc) {
@@ -897,7 +967,7 @@ end:
        return (void *) var_fc;
 }
 
-int bt_field_class_variant_set_selector_field_class(
+enum bt_field_class_status bt_field_class_variant_set_selector_field_class(
                struct bt_field_class *fc,
                struct bt_field_class *selector_fc)
 {
@@ -911,10 +981,10 @@ int bt_field_class_variant_set_selector_field_class(
        var_fc->selector_fc = selector_fc;
        bt_object_get_no_null_check(selector_fc);
        bt_field_class_freeze(selector_fc);
-       return 0;
+       return BT_FIELD_CLASS_STATUS_OK;
 }
 
-int bt_field_class_variant_append_option(
+enum bt_field_class_status bt_field_class_variant_append_option(
                struct bt_field_class *fc,
                const char *name, struct bt_field_class *option_fc)
 {
@@ -925,14 +995,26 @@ int bt_field_class_variant_append_option(
                name, option_fc);
 }
 
-const struct bt_field_class *
-bt_field_class_variant_borrow_option_field_class_by_name_const(
+const struct bt_field_class_variant_option *
+bt_field_class_variant_borrow_option_by_name_const(
                const struct bt_field_class *fc, const char *name)
 {
        BT_ASSERT_PRE_NON_NULL(fc, "Field class");
        BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_VARIANT, "Field class");
-       return borrow_field_class_from_container_field_class_by_name_const(
-               (void *) fc, name);
+       return (const void *)
+               borrow_named_field_class_from_container_field_class_by_name(
+                       (void *) fc, name);
+}
+
+struct bt_field_class_variant_option *
+bt_field_class_variant_borrow_option_by_name(
+               struct bt_field_class *fc, const char *name)
+{
+       BT_ASSERT_PRE_NON_NULL(fc, "Field class");
+       BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_VARIANT, "Field class");
+       return (void *)
+               borrow_named_field_class_from_container_field_class_by_name(
+                       (void *) fc, name);
 }
 
 uint64_t bt_field_class_variant_get_option_count(const struct bt_field_class *fc)
@@ -944,14 +1026,55 @@ uint64_t bt_field_class_variant_get_option_count(const struct bt_field_class *fc
        return (uint64_t) var_fc->common.named_fcs->len;
 }
 
-void bt_field_class_variant_borrow_option_by_index_const(
-               const struct bt_field_class *fc, uint64_t index,
-               const char **name, const struct bt_field_class **out_fc)
+const struct bt_field_class_variant_option *
+bt_field_class_variant_borrow_option_by_index_const(
+               const struct bt_field_class *fc, uint64_t index)
+{
+       BT_ASSERT_PRE_NON_NULL(fc, "Field class");
+       BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_VARIANT, "Field class");
+       return (const void *)
+               borrow_named_field_class_from_container_field_class_at_index(
+                       (void *) fc, index);
+}
+
+struct bt_field_class_variant_option *
+bt_field_class_variant_borrow_option_by_index(
+               struct bt_field_class *fc, uint64_t index)
 {
        BT_ASSERT_PRE_NON_NULL(fc, "Field class");
        BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_VARIANT, "Field class");
-       borrow_named_field_class_from_container_field_class_at_index_const(
-               (void *) fc, index, name, out_fc);
+       return (void *)
+               borrow_named_field_class_from_container_field_class_at_index(
+                       (void *) fc, index);
+}
+
+const char *bt_field_class_variant_option_get_name(
+               const struct bt_field_class_variant_option *option)
+{
+       const struct bt_named_field_class *named_fc = (const void *) option;
+
+       BT_ASSERT_PRE_NON_NULL(option, "Variant field class option");
+       return named_fc->name->str;
+}
+
+const struct bt_field_class *
+bt_field_class_variant_option_borrow_field_class_const(
+               const struct bt_field_class_variant_option *option)
+{
+       const struct bt_named_field_class *named_fc = (const void *) option;
+
+       BT_ASSERT_PRE_NON_NULL(option, "Variant field class option");
+       return named_fc->fc;
+}
+
+struct bt_field_class *
+bt_field_class_variant_option_borrow_field_class(
+               struct bt_field_class_variant_option *option)
+{
+       struct bt_named_field_class *named_fc = (void *) option;
+
+       BT_ASSERT_PRE_NON_NULL(option, "Variant field class option");
+       return named_fc->fc;
 }
 
 const struct bt_field_path *
@@ -996,11 +1119,12 @@ void destroy_static_array_field_class(struct bt_object *obj)
 }
 
 struct bt_field_class *
-bt_field_class_static_array_create(struct bt_field_class *element_fc,
-               uint64_t length)
+bt_field_class_static_array_create(bt_trace_class *trace_class,
+               struct bt_field_class *element_fc, uint64_t length)
 {
        struct bt_field_class_static_array *array_fc = NULL;
 
+       BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class");
        BT_ASSERT_PRE_NON_NULL(element_fc, "Element field class");
        BT_LOGD_STR("Creating default static array field class object.");
        array_fc = g_new0(struct bt_field_class_static_array, 1);
@@ -1033,6 +1157,16 @@ bt_field_class_array_borrow_element_field_class_const(
        return array_fc->element_fc;
 }
 
+struct bt_field_class *
+bt_field_class_array_borrow_element_field_class(struct bt_field_class *fc)
+{
+       struct bt_field_class_array *array_fc = (void *) fc;
+
+       BT_ASSERT_PRE_NON_NULL(fc, "Field class");
+       BT_ASSERT_PRE_FC_IS_ARRAY(fc, "Field class");
+       return array_fc->element_fc;
+}
+
 uint64_t bt_field_class_static_array_get_length(const struct bt_field_class *fc)
 {
        const struct bt_field_class_static_array *array_fc = (const void *) fc;
@@ -1059,10 +1193,12 @@ void destroy_dynamic_array_field_class(struct bt_object *obj)
 }
 
 struct bt_field_class *bt_field_class_dynamic_array_create(
+               bt_trace_class *trace_class,
                struct bt_field_class *element_fc)
 {
        struct bt_field_class_dynamic_array *array_fc = NULL;
 
+       BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class");
        BT_ASSERT_PRE_NON_NULL(element_fc, "Element field class");
        BT_LOGD_STR("Creating default dynamic array field class object.");
        array_fc = g_new0(struct bt_field_class_dynamic_array, 1);
@@ -1084,7 +1220,7 @@ end:
        return (void *) array_fc;
 }
 
-int bt_field_class_dynamic_array_set_length_field_class(
+enum bt_field_class_status bt_field_class_dynamic_array_set_length_field_class(
                struct bt_field_class *fc,
                struct bt_field_class *length_fc)
 {
@@ -1099,7 +1235,7 @@ int bt_field_class_dynamic_array_set_length_field_class(
        array_fc->length_fc = length_fc;
        bt_object_get_no_null_check(length_fc);
        bt_field_class_freeze(length_fc);
-       return 0;
+       return BT_FIELD_CLASS_STATUS_OK;
 }
 
 const struct bt_field_path *
@@ -1122,10 +1258,11 @@ void destroy_string_field_class(struct bt_object *obj)
        g_free(obj);
 }
 
-struct bt_field_class *bt_field_class_string_create(void)
+struct bt_field_class *bt_field_class_string_create(bt_trace_class *trace_class)
 {
        struct bt_field_class_string *string_fc = NULL;
 
+       BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class");
        BT_LOGD_STR("Creating default string field class object.");
        string_fc = g_new0(struct bt_field_class_string, 1);
        if (!string_fc) {
@@ -1146,14 +1283,46 @@ end:
 }
 
 BT_HIDDEN
-void _bt_field_class_freeze(const struct bt_field_class *fc)
+void _bt_field_class_freeze(const struct bt_field_class *c_fc)
 {
+       struct bt_field_class *fc = (void *) c_fc;
+
        /*
         * Element/member/option field classes are frozen when added to
         * their owner.
         */
        BT_ASSERT(fc);
-       ((struct bt_field_class *) fc)->frozen = true;
+       fc->frozen = true;
+
+       switch (fc->type) {
+       case BT_FIELD_CLASS_TYPE_STRUCTURE:
+       case BT_FIELD_CLASS_TYPE_VARIANT:
+       {
+               struct bt_field_class_named_field_class_container *container_fc =
+                       (void *) fc;
+               uint64_t i;
+
+               for (i = 0; i < container_fc->named_fcs->len; i++) {
+                       struct bt_named_field_class *named_fc =
+                               BT_FIELD_CLASS_NAMED_FC_AT_INDEX(
+                                       container_fc, i);
+
+                       bt_named_field_class_freeze(named_fc);
+               }
+
+               break;
+       }
+       default:
+               break;
+       }
+}
+
+BT_HIDDEN
+void _bt_named_field_class_freeze(const struct bt_named_field_class *named_fc)
+{
+       BT_ASSERT(named_fc);
+       ((struct bt_named_field_class *) named_fc)->frozen = true;
+       bt_field_class_freeze(named_fc->fc);
 }
 
 BT_HIDDEN
@@ -1196,3 +1365,13 @@ void _bt_field_class_make_part_of_trace_class(const struct bt_field_class *c_fc)
                break;
        }
 }
+
+void bt_field_class_get_ref(const struct bt_field_class *field_class)
+{
+       bt_object_get_ref(field_class);
+}
+
+void bt_field_class_put_ref(const struct bt_field_class *field_class)
+{
+       bt_object_put_ref(field_class);
+}
This page took 0.045594 seconds and 4 git commands to generate.