+BT_HIDDEN
+void bt_field_type_common_initialize(struct bt_field_type_common *ft,
+ bool init_bo, bt_object_release_func release_func,
+ struct bt_field_type_common_methods *methods)
+{
+ BT_ASSERT(ft && (ft->id > BT_FIELD_TYPE_ID_UNKNOWN) &&
+ (ft->id < BT_FIELD_TYPE_ID_NR));
+
+ bt_object_init_shared(&ft->base, release_func);
+ ft->methods = methods;
+
+ if (init_bo) {
+ int ret;
+ const enum bt_byte_order bo = BT_BYTE_ORDER_NATIVE;
+
+ BT_LOGD("Setting initial field type's byte order: bo=%s",
+ bt_common_byte_order_string(bo));
+ ret = bt_field_type_common_set_byte_order(ft, bo);
+ BT_ASSERT(ret == 0);
+ }
+
+ ft->alignment = 1;
+}
+
+BT_HIDDEN
+void bt_field_type_common_integer_initialize(
+ struct bt_field_type_common *ft,
+ unsigned int size, bt_object_release_func release_func,
+ struct bt_field_type_common_methods *methods)
+{
+ struct bt_field_type_common_integer *int_ft = BT_FROM_COMMON(ft);
+
+ BT_ASSERT(size > 0);
+ BT_LOGD("Initializing common integer field type object: size=%u",
+ size);
+ ft->id = BT_FIELD_TYPE_ID_INTEGER;
+ int_ft->size = size;
+ int_ft->base = BT_INTEGER_BASE_DECIMAL;
+ int_ft->encoding = BT_STRING_ENCODING_NONE;
+ bt_field_type_common_initialize(ft, true, release_func, methods);
+ BT_LOGD("Initialized common integer field type object: addr=%p, size=%u",
+ ft, size);
+}
+
+BT_HIDDEN
+void bt_field_type_common_floating_point_initialize(
+ struct bt_field_type_common *ft,
+ bt_object_release_func release_func,
+ struct bt_field_type_common_methods *methods)
+{
+ struct bt_field_type_common_floating_point *flt_ft = BT_FROM_COMMON(ft);
+
+ BT_LOGD_STR("Initializing common floating point number field type object.");
+ ft->id = BT_FIELD_TYPE_ID_FLOAT;
+ flt_ft->exp_dig = sizeof(float) * CHAR_BIT - FLT_MANT_DIG;
+ flt_ft->mant_dig = FLT_MANT_DIG;
+ bt_field_type_common_initialize(ft, true, release_func, methods);
+ BT_LOGD("Initialized common floating point number field type object: addr=%p, "
+ "exp-size=%u, mant-size=%u", ft, flt_ft->exp_dig,
+ flt_ft->mant_dig);
+}
+
+BT_HIDDEN
+void bt_field_type_common_enumeration_initialize(
+ struct bt_field_type_common *ft,
+ struct bt_field_type_common *container_ft,
+ bt_object_release_func release_func,
+ struct bt_field_type_common_methods *methods)
+{
+ struct bt_field_type_common_enumeration *enum_ft = BT_FROM_COMMON(ft);
+
+ BT_ASSERT(container_ft);
+ BT_LOGD("Initializing common enumeration field type object: int-ft-addr=%p",
+ container_ft);
+ ft->id = BT_FIELD_TYPE_ID_ENUM;
+ enum_ft->container_ft = bt_get(container_ft);
+ enum_ft->entries = g_ptr_array_new_with_free_func(
+ (GDestroyNotify) destroy_enumeration_mapping);
+ bt_field_type_common_initialize(ft, false, release_func, methods);
+ BT_LOGD("Initialized common enumeration field type object: addr=%p, "
+ "int-ft-addr=%p, int-ft-size=%u", ft, container_ft,
+ bt_field_type_common_integer_get_size(container_ft));
+}
+
+BT_HIDDEN
+void bt_field_type_common_string_initialize(
+ struct bt_field_type_common *ft,
+ bt_object_release_func release_func,
+ struct bt_field_type_common_methods *methods)
+{
+ struct bt_field_type_common_string *string_ft = BT_FROM_COMMON(ft);
+
+ BT_LOGD_STR("Initializing common string field type object.");
+ ft->id = BT_FIELD_TYPE_ID_STRING;
+ bt_field_type_common_initialize(ft, true, release_func, methods);
+ string_ft->encoding = BT_STRING_ENCODING_UTF8;
+ ft->alignment = CHAR_BIT;
+ BT_LOGD("Initialized common string field type object: addr=%p", ft);
+}
+
+BT_HIDDEN
+void bt_field_type_common_structure_initialize(
+ struct bt_field_type_common *ft,
+ bt_object_release_func release_func,
+ struct bt_field_type_common_methods *methods)
+{
+ struct bt_field_type_common_structure *struct_ft = BT_FROM_COMMON(ft);
+
+ BT_LOGD_STR("Initializing common structure field type object.");
+ ft->id = BT_FIELD_TYPE_ID_STRUCT;
+ struct_ft->fields = g_array_new(FALSE, TRUE,
+ sizeof(struct bt_field_type_common_structure_field));
+ struct_ft->field_name_to_index = g_hash_table_new(NULL, NULL);
+ bt_field_type_common_initialize(ft, true, release_func, methods);
+ BT_LOGD("Initialized common structure field type object: addr=%p", ft);
+}
+
+BT_HIDDEN
+void bt_field_type_common_array_initialize(
+ struct bt_field_type_common *ft,
+ struct bt_field_type_common *element_ft,
+ unsigned int length, bt_object_release_func release_func,
+ struct bt_field_type_common_methods *methods)
+{
+ struct bt_field_type_common_array *array_ft = BT_FROM_COMMON(ft);
+
+ BT_ASSERT(element_ft);
+ BT_LOGD("Initializing common array field type object: element-ft-addr=%p, "
+ "length=%u", element_ft, length);
+ ft->id = BT_FIELD_TYPE_ID_ARRAY;
+ array_ft->element_ft = bt_get(element_ft);
+ array_ft->length = length;
+ bt_field_type_common_initialize(ft, false, release_func, methods);
+ BT_LOGD("Initialized common array field type object: addr=%p, "
+ "element-ft-addr=%p, length=%u", ft, element_ft, length);
+}
+
+BT_HIDDEN
+void bt_field_type_common_sequence_initialize(
+ struct bt_field_type_common *ft,
+ struct bt_field_type_common *element_ft,
+ const char *length_field_name,
+ bt_object_release_func release_func,
+ struct bt_field_type_common_methods *methods)
+{
+ struct bt_field_type_common_sequence *seq_ft = BT_FROM_COMMON(ft);
+
+ BT_ASSERT(element_ft);
+ BT_ASSERT(length_field_name);
+ BT_ASSERT(bt_identifier_is_valid(length_field_name));
+ BT_LOGD("Initializing common sequence field type object: element-ft-addr=%p, "
+ "length-field-name=\"%s\"", element_ft, length_field_name);
+ ft->id = BT_FIELD_TYPE_ID_SEQUENCE;
+ seq_ft->element_ft = bt_get(element_ft);
+ seq_ft->length_field_name = g_string_new(length_field_name);
+ bt_field_type_common_initialize(ft, false, release_func, methods);
+ BT_LOGD("Initialized common sequence field type object: addr=%p, "
+ "element-ft-addr=%p, length-field-name=\"%s\"",
+ ft, element_ft, length_field_name);
+}
+
+BT_HIDDEN
+void bt_field_type_common_variant_initialize(
+ struct bt_field_type_common *ft,
+ struct bt_field_type_common *tag_ft,
+ const char *tag_name,
+ bt_object_release_func release_func,
+ struct bt_field_type_common_methods *methods)
+{
+ struct bt_field_type_common_variant *var_ft = BT_FROM_COMMON(ft);
+
+ BT_ASSERT(!tag_name || bt_identifier_is_valid(tag_name));
+ BT_LOGD("Initializing common variant field type object: "
+ "tag-ft-addr=%p, tag-field-name=\"%s\"",
+ tag_ft, tag_name);
+ ft->id = BT_FIELD_TYPE_ID_VARIANT;
+ var_ft->tag_name = g_string_new(tag_name);
+ var_ft->choice_name_to_index = g_hash_table_new(NULL, NULL);
+ var_ft->choices = g_array_new(FALSE, TRUE,
+ sizeof(struct bt_field_type_common_variant_choice));
+
+ if (tag_ft) {
+ var_ft->tag_ft = bt_get(tag_ft);
+ }
+
+ bt_field_type_common_initialize(ft, true, release_func, methods);
+ /* A variant's alignment is undefined */
+ ft->alignment = 0;
+ BT_LOGD("Initialized common variant field type object: addr=%p, "
+ "tag-ft-addr=%p, tag-field-name=\"%s\"",
+ ft, tag_ft, tag_name);
+}
+
+BT_HIDDEN
+void bt_field_type_common_integer_destroy(struct bt_object *obj)
+{
+ struct bt_field_type_common_integer *ft = (void *) obj;
+
+ if (!ft) {
+ return;
+ }
+
+ BT_LOGD("Destroying integer field type object: addr=%p", ft);
+ BT_LOGD_STR("Putting mapped clock class.");
+ bt_put(ft->mapped_clock_class);
+ g_free(ft);
+}
+
+BT_HIDDEN
+void bt_field_type_common_floating_point_destroy(struct bt_object *obj)
+{
+ struct bt_field_type_common_floating_point *ft = (void *) obj;
+
+ if (!ft) {
+ return;
+ }
+
+ BT_LOGD("Destroying floating point number field type object: addr=%p", ft);
+ g_free(ft);
+}
+
+BT_HIDDEN
+void bt_field_type_common_enumeration_destroy_recursive(struct bt_object *obj)
+{
+ struct bt_field_type_common_enumeration *ft = (void *) obj;
+
+ if (!ft) {
+ return;
+ }
+
+ BT_LOGD("Destroying enumeration field type object: addr=%p", ft);
+ g_ptr_array_free(ft->entries, TRUE);
+ BT_LOGD_STR("Putting container field type.");
+ bt_put(ft->container_ft);
+ g_free(ft);
+}
+
+BT_HIDDEN
+void bt_field_type_common_string_destroy(struct bt_object *obj)
+{
+ struct bt_field_type_common_string *ft = (void *) obj;
+
+ if (!ft) {
+ return;
+ }
+
+ BT_LOGD("Destroying string field type object: addr=%p", ft);
+ g_free(ft);
+}
+