- field_type = bt_ctf_field_type_sequence_get_element_type(field->type);
- if (sequence->elements->pdata[(size_t) index]) {
- new_field = sequence->elements->pdata[(size_t) index];
- goto end;
- }
-
- /* We don't want to modify this field if it's frozen */
- if (field->frozen) {
- /*
- * Not logging a warning here because the user could
- * legitimately check if a sequence field is set with
- * this function: if the preconditions are satisfied,
- * a NULL return value means this.
- */
- BT_LOGV("Not creating a field because sequence field is frozen: "
- "sequence-field-addr=%p, index=%" PRIu64, field, index);
- goto end;
- }
-
- new_field = bt_ctf_field_create(field_type);
- sequence->elements->pdata[(size_t) index] = new_field;
-end:
- if (field_type) {
- bt_put(field_type);
- }
- if (new_field) {
- bt_get(new_field);
- }
- return new_field;
-}
-
-struct bt_ctf_field *bt_ctf_field_variant_get_field(struct bt_ctf_field *field,
- struct bt_ctf_field *tag_field)
-{
- struct bt_ctf_field *new_field = NULL;
- struct bt_ctf_field_variant *variant;
- struct bt_ctf_field_type_variant *variant_type;
- struct bt_ctf_field_type *field_type;
- struct bt_ctf_field *tag_enum = NULL;
- struct bt_ctf_field_integer *tag_enum_integer;
- int64_t tag_enum_value;
-
- if (!field) {
- BT_LOGW_STR("Invalid parameter: field is NULL.");
- goto end;
- }
-
- if (!tag_field) {
- BT_LOGW_STR("Invalid parameter: tag field is NULL.");
- goto end;
- }
-
- if (bt_ctf_field_type_get_type_id(field->type) !=
- BT_CTF_FIELD_TYPE_ID_VARIANT) {
- BT_LOGW("Invalid parameter: field's type is not a variant field type: "
- "field-addr=%p, ft-addr=%p, ft-id=%s", field,
- field->type,
- bt_ctf_field_type_id_string(field->type->id));
- goto end;
- }
-
- if (bt_ctf_field_type_get_type_id(tag_field->type) !=
- BT_CTF_FIELD_TYPE_ID_ENUM) {
- BT_LOGW("Invalid parameter: tag field's type is not an enumeration field type: "
- "field-addr=%p, ft-addr=%p, ft-id=%s", tag_field,
- tag_field->type,
- bt_ctf_field_type_id_string(tag_field->type->id));
- goto end;
- }
-
- variant = container_of(field, struct bt_ctf_field_variant, parent);
- variant_type = container_of(field->type,
- struct bt_ctf_field_type_variant, parent);
- tag_enum = bt_ctf_field_enumeration_get_container(tag_field);
- if (!tag_enum) {
- goto end;
- }
-
- tag_enum_integer = container_of(tag_enum, struct bt_ctf_field_integer,
- parent);
-
- if (bt_ctf_field_validate(tag_field) < 0) {
- BT_LOGW("Invalid parameter: tag field is invalid: "
- "variant-field-addr=%p, tag-field-addr=%p",
- field, tag_field);
- goto end;
- }
-
- tag_enum_value = tag_enum_integer->payload.signd;
-
- /*
- * If the variant currently has a tag and a payload, and if the
- * requested tag value is the same as the current one, return
- * the current payload instead of creating a fresh one.
- */
- if (variant->tag && variant->payload) {
- struct bt_ctf_field *cur_tag_container = NULL;
- struct bt_ctf_field_integer *cur_tag_enum_integer;
- int64_t cur_tag_value;
-
- cur_tag_container =
- bt_ctf_field_enumeration_get_container(variant->tag);
- assert(cur_tag_container);
- cur_tag_enum_integer = container_of(cur_tag_container,
- struct bt_ctf_field_integer, parent);
- bt_put(cur_tag_container);
- cur_tag_value = cur_tag_enum_integer->payload.signd;
-
- if (cur_tag_value == tag_enum_value) {
- new_field = variant->payload;
- bt_get(new_field);
- goto end;
- }
- }
-
- /* We don't want to modify this field if it's frozen */
- if (field->frozen) {
- /*
- * Not logging a warning here because the user could
- * legitimately check if a variant field is set with
- * this function: if the preconditions are satisfied,
- * a NULL return value means this.
- */
- BT_LOGV("Not creating a field because variant field is frozen: "
- "variant-field-addr=%p, tag-field-addr=%p",
- field, tag_field);
- goto end;
- }
-
- field_type = bt_ctf_field_type_variant_get_field_type_signed(
- variant_type, tag_enum_value);
- if (!field_type) {
- BT_LOGW("Cannot get variant field type's field: "
- "variant-field-addr=%p, variant-ft-addr=%p, "
- "tag-value-signed=%" PRId64,
- field, variant_type, tag_enum_value);
- goto end;
- }
-
- new_field = bt_ctf_field_create(field_type);
- if (!new_field) {
- BT_LOGW("Cannot create field: "
- "variant-field-addr=%p, variant-ft-addr=%p, "
- "field-ft-addr=%p", field, field->type, field_type);
- goto end;
- }
-
- bt_put(variant->tag);
- bt_put(variant->payload);
- bt_get(new_field);
- bt_get(tag_field);
- variant->tag = tag_field;
- variant->payload = new_field;
-end:
- bt_put(tag_enum);
- return new_field;
-}
-
-struct bt_ctf_field *bt_ctf_field_variant_get_current_field(
- struct bt_ctf_field *variant_field)
-{
- struct bt_ctf_field *current_field = NULL;
- struct bt_ctf_field_variant *variant;
-
- if (!variant_field) {
- BT_LOGW_STR("Invalid parameter: field is NULL.");
- goto end;
- }
-
- if (bt_ctf_field_type_get_type_id(variant_field->type) !=
- BT_CTF_FIELD_TYPE_ID_VARIANT) {
- BT_LOGW("Invalid parameter: field's type is not a variant field type: "
- "field-addr=%p, ft-addr=%p, ft-id=%s", variant_field,
- variant_field->type,
- bt_ctf_field_type_id_string(variant_field->type->id));
- goto end;
- }
-
- variant = container_of(variant_field, struct bt_ctf_field_variant,
- parent);
-
- if (variant->payload) {
- current_field = variant->payload;
- bt_get(current_field);
- goto end;
- }
-
-end:
- return current_field;
-}
-
-struct bt_ctf_field *bt_ctf_field_variant_get_tag(
- struct bt_ctf_field *variant_field)
-{
- struct bt_ctf_field *tag = NULL;
- struct bt_ctf_field_variant *variant;
-
- if (!variant_field) {
- BT_LOGW_STR("Invalid parameter: field is NULL.");
- goto end;
- }
-
- if (bt_ctf_field_type_get_type_id(variant_field->type) !=
- BT_CTF_FIELD_TYPE_ID_VARIANT) {
- BT_LOGW("Invalid parameter: field's type is not a variant field type: "
- "field-addr=%p, ft-addr=%p, ft-id=%s", variant_field,
- variant_field->type,
- bt_ctf_field_type_id_string(variant_field->type->id));
- goto end;
- }
-
- variant = container_of(variant_field, struct bt_ctf_field_variant,
- parent);
- if (variant->tag) {
- tag = bt_get(variant->tag);
- }
-end:
- return tag;
-}
-
-struct bt_ctf_field *bt_ctf_field_enumeration_get_container(
- struct bt_ctf_field *field)
-{
- struct bt_ctf_field *container = NULL;
- struct bt_ctf_field_enumeration *enumeration;
-
- if (!field) {
- BT_LOGW_STR("Invalid parameter: field is NULL.");
- goto end;
- }
-
- if (bt_ctf_field_type_get_type_id(field->type) !=
- BT_CTF_FIELD_TYPE_ID_ENUM) {
- BT_LOGW("Invalid parameter: field's type is not an enumeration field type: "
- "field-addr=%p, ft-addr=%p, ft-id=%s", field,
- field->type,
- bt_ctf_field_type_id_string(field->type->id));
- goto end;
- }
-
- enumeration = container_of(field, struct bt_ctf_field_enumeration,
- parent);
- if (!enumeration->payload) {
- /* We don't want to modify this field if it's frozen */
- if (field->frozen) {
- /*
- * Not logging a warning here because the user
- * could legitimately check if an enumeration's
- * container field is set with this function: if
- * the preconditions are satisfied, a NULL
- * return value means this.
- */
- BT_LOGV("Not creating a field because enumeration field is frozen: "
- "enum-field-addr=%p", field);
- goto end;
- }
-
- struct bt_ctf_field_type_enumeration *enumeration_type =
- container_of(field->type,
- struct bt_ctf_field_type_enumeration, parent);
- enumeration->payload =
- bt_ctf_field_create(enumeration_type->container);
- }
-
- container = enumeration->payload;
- bt_get(container);
-end:
- return container;
-}
-
-struct bt_ctf_field_type_enumeration_mapping_iterator *
-bt_ctf_field_enumeration_get_mappings(struct bt_ctf_field *field)
-{
- int ret;
- struct bt_ctf_field *container = NULL;
- struct bt_ctf_field_type *container_type = NULL;
- struct bt_ctf_field_type_integer *integer_type = NULL;
- struct bt_ctf_field_type_enumeration_mapping_iterator *iter = NULL;
-
- container = bt_ctf_field_enumeration_get_container(field);
- if (!container) {
- BT_LOGW("Invalid parameter: enumeration field has no container field: "
- "addr=%p", field);
- goto end;
- }
-
- container_type = bt_ctf_field_get_type(container);
- assert(container_type);
- integer_type = container_of(container_type,
- struct bt_ctf_field_type_integer, parent);
-
- if (!integer_type->is_signed) {
- uint64_t value;
-
- ret = bt_ctf_field_unsigned_integer_get_value(container,
- &value);
- if (ret) {
- BT_LOGW("Cannot get value from signed enumeration field's payload field: "
- "enum-field-addr=%p, payload-field-addr=%p",
- field, container);
- goto error_put_container_type;
- }
- iter = bt_ctf_field_type_enumeration_find_mappings_by_unsigned_value(
- field->type, value);
- } else {
- int64_t value;
-
- ret = bt_ctf_field_signed_integer_get_value(container,
- &value);
- if (ret) {
- BT_LOGW("Cannot get value from unsigned enumeration field's payload field: "
- "enum-field-addr=%p, payload-field-addr=%p",
- field, container);
- goto error_put_container_type;
- }
- iter = bt_ctf_field_type_enumeration_find_mappings_by_signed_value(
- field->type, value);
- }
-
-error_put_container_type:
- bt_put(container_type);
- bt_put(container);
-end:
- return iter;
-}
-
-int bt_ctf_field_signed_integer_get_value(struct bt_ctf_field *field,
- int64_t *value)
-{
- int ret = 0;
- struct bt_ctf_field_integer *integer;
- struct bt_ctf_field_type_integer *integer_type;
-
- if (!field) {
- BT_LOGW_STR("Invalid parameter: field is NULL.");
- ret = -1;
- goto end;
- }
-
- if (!value) {
- BT_LOGW_STR("Invalid parameter: value is NULL.");
- ret = -1;
- goto end;
- }
-
- if (!field->payload_set) {
- BT_LOGV("Field's payload is not set: addr=%p", field);
- ret = -1;
- goto end;
- }
-
- if (bt_ctf_field_type_get_type_id(field->type) !=
- BT_CTF_FIELD_TYPE_ID_INTEGER) {
- BT_LOGW("Invalid parameter: field's type is not an integer field type: "
- "field-addr=%p, ft-addr=%p, ft-id=%s", field,
- field->type,
- bt_ctf_field_type_id_string(field->type->id));
- ret = -1;
- goto end;
- }
-
- integer_type = container_of(field->type,
- struct bt_ctf_field_type_integer, parent);
- if (!integer_type->is_signed) {
- BT_LOGW("Invalid parameter: integer field's type is not signed: "
- "field-addr=%p, ft-addr=%p", field, field->type);
- ret = -1;
- goto end;
- }
-
- integer = container_of(field,
- struct bt_ctf_field_integer, parent);
- *value = integer->payload.signd;
-end:
- return ret;
-}
-
-int bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *field,
- int64_t value)
-{
- int ret = 0;
- struct bt_ctf_field_integer *integer;
- struct bt_ctf_field_type_integer *integer_type;
- unsigned int size;
- int64_t min_value, max_value;
-
- if (!field) {
- BT_LOGW_STR("Invalid parameter: field is NULL.");
- ret = -1;
- goto end;
- }
-
- if (field->frozen) {
- BT_LOGW("Invalid parameter: field is frozen: addr=%p",
- field);
- ret = -1;
- goto end;
- }
-
- if (bt_ctf_field_type_get_type_id(field->type) !=
- BT_CTF_FIELD_TYPE_ID_INTEGER) {
- BT_LOGW("Invalid parameter: field's type is not an integer field type: "
- "field-addr=%p, ft-addr=%p, ft-id=%s", field,
- field->type,
- bt_ctf_field_type_id_string(field->type->id));
- ret = -1;
- goto end;
- }
-
- integer = container_of(field, struct bt_ctf_field_integer, parent);
- integer_type = container_of(field->type,
- struct bt_ctf_field_type_integer, parent);
- if (!integer_type->is_signed) {
- BT_LOGW("Invalid parameter: integer field's type is not signed: "
- "field-addr=%p, ft-addr=%p", field, field->type);
- ret = -1;
- goto end;
- }
-
- size = integer_type->size;
- min_value = -(1ULL << (size - 1));
- max_value = (1ULL << (size - 1)) - 1;
- if (value < min_value || value > max_value) {
- BT_LOGW("Invalid parameter: value is out of bounds: "
- "addr=%p, value=%" PRId64 ", "
- "min-value=%" PRId64 ", max-value=%" PRId64,
- field, value, min_value, max_value);
- ret = -1;
- goto end;
- }
-
- integer->payload.signd = value;
- integer->parent.payload_set = true;
-end:
- return ret;
-}
-
-int bt_ctf_field_unsigned_integer_get_value(struct bt_ctf_field *field,
- uint64_t *value)
-{
- int ret = 0;
- struct bt_ctf_field_integer *integer;
- struct bt_ctf_field_type_integer *integer_type;
-
- if (!field) {
- BT_LOGW_STR("Invalid parameter: field is NULL.");
- ret = -1;
- goto end;
- }
-
- if (!value) {
- BT_LOGW_STR("Invalid parameter: value is NULL.");
- ret = -1;
- goto end;
- }
-
- if (!field->payload_set) {
- BT_LOGV("Field's payload is not set: addr=%p", field);
- ret = -1;
- goto end;
- }
-
- if (bt_ctf_field_type_get_type_id(field->type) !=
- BT_CTF_FIELD_TYPE_ID_INTEGER) {
- BT_LOGW("Invalid parameter: field's type is not an integer field type: "
- "field-addr=%p, ft-addr=%p, ft-id=%s", field,
- field->type,
- bt_ctf_field_type_id_string(field->type->id));
- ret = -1;
- goto end;
- }
-
- integer_type = container_of(field->type,
- struct bt_ctf_field_type_integer, parent);
- if (integer_type->is_signed) {
- BT_LOGW("Invalid parameter: integer field's type is signed: "
- "field-addr=%p, ft-addr=%p", field, field->type);
- ret = -1;
- goto end;
- }
-
- integer = container_of(field,
- struct bt_ctf_field_integer, parent);
- *value = integer->payload.unsignd;
-end:
- return ret;
-}
-
-int bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *field,
- uint64_t value)
-{
- int ret = 0;
- struct bt_ctf_field_integer *integer;
- struct bt_ctf_field_type_integer *integer_type;
- unsigned int size;
- uint64_t max_value;
-
- if (!field) {
- BT_LOGW_STR("Invalid parameter: field is NULL.");
- ret = -1;
- goto end;
- }
-
- if (field->frozen) {
- BT_LOGW("Invalid parameter: field is frozen: addr=%p",
- field);
- ret = -1;
- goto end;
- }
-
- if (bt_ctf_field_type_get_type_id(field->type) !=
- BT_CTF_FIELD_TYPE_ID_INTEGER) {
- BT_LOGW("Invalid parameter: field's type is not an integer field type: "
- "field-addr=%p, ft-addr=%p, ft-id=%s", field,
- field->type,
- bt_ctf_field_type_id_string(field->type->id));
- ret = -1;
- goto end;
- }
-
- integer = container_of(field, struct bt_ctf_field_integer, parent);
- integer_type = container_of(field->type,
- struct bt_ctf_field_type_integer, parent);
- if (integer_type->is_signed) {
- BT_LOGW("Invalid parameter: integer field's type is signed: "
- "field-addr=%p, ft-addr=%p", field, field->type);
- ret = -1;
- goto end;
- }
-
- size = integer_type->size;
- max_value = (size == 64) ? UINT64_MAX : ((uint64_t) 1 << size) - 1;
- if (value > max_value) {
- BT_LOGW("Invalid parameter: value is out of bounds: "
- "addr=%p, value=%" PRIu64 ", "
- "min-value=%" PRIu64 ", max-value=%" PRIu64,
- field, value, (uint64_t) 0, max_value);
- ret = -1;
- goto end;
- }
-
- integer->payload.unsignd = value;
- integer->parent.payload_set = true;
-end:
- return ret;
-}
-
-int bt_ctf_field_floating_point_get_value(struct bt_ctf_field *field,
- double *value)
-{
- int ret = 0;
- struct bt_ctf_field_floating_point *floating_point;
-
- if (!field) {
- BT_LOGW_STR("Invalid parameter: field is NULL.");
- ret = -1;
- goto end;
- }
-
- if (!value) {
- BT_LOGW_STR("Invalid parameter: value is NULL.");
- ret = -1;
- goto end;
- }
-
- if (!field->payload_set) {
- BT_LOGV("Field's payload is not set: addr=%p", field);
- ret = -1;
- goto end;
- }
-
- if (bt_ctf_field_type_get_type_id(field->type) !=
- BT_CTF_FIELD_TYPE_ID_FLOAT) {
- BT_LOGW("Invalid parameter: field's type is not a floating point number field type: "
- "field-addr=%p, ft-addr=%p, ft-id=%s", field,
- field->type,
- bt_ctf_field_type_id_string(field->type->id));
- ret = -1;
- goto end;
- }
-
- floating_point = container_of(field,
- struct bt_ctf_field_floating_point, parent);
- *value = floating_point->payload;
-end:
- return ret;
-}
-
-int bt_ctf_field_floating_point_set_value(struct bt_ctf_field *field,
- double value)
-{
- int ret = 0;
- struct bt_ctf_field_floating_point *floating_point;
-
- if (!field) {
- BT_LOGW_STR("Invalid parameter: field is NULL.");
- ret = -1;
- goto end;
- }
-
- if (field->frozen) {
- BT_LOGW("Invalid parameter: field is frozen: addr=%p",
- field);
- ret = -1;
- goto end;
- }
-
- if (bt_ctf_field_type_get_type_id(field->type) !=
- BT_CTF_FIELD_TYPE_ID_FLOAT) {
- BT_LOGW("Invalid parameter: field's type is not a floating point number field type: "
- "field-addr=%p, ft-addr=%p, ft-id=%s", field,
- field->type,
- bt_ctf_field_type_id_string(field->type->id));
- ret = -1;
- goto end;
- }
-
- floating_point = container_of(field, struct bt_ctf_field_floating_point,
- parent);
- floating_point->payload = value;
- floating_point->parent.payload_set = true;
-end:
- return ret;
-}
-
-const char *bt_ctf_field_string_get_value(struct bt_ctf_field *field)
-{
- const char *ret = NULL;
- struct bt_ctf_field_string *string;
-
- if (!field) {
- BT_LOGW_STR("Invalid parameter: field is NULL.");
- goto end;
- }
-
- if (!field->payload_set) {
- BT_LOGV("Field's payload is not set: addr=%p", field);
- goto end;
- }
-
- if (bt_ctf_field_type_get_type_id(field->type) !=
- BT_CTF_FIELD_TYPE_ID_STRING) {
- BT_LOGW("Invalid parameter: field's type is not a string field type: "
- "field-addr=%p, ft-addr=%p, ft-id=%s", field,
- field->type,
- bt_ctf_field_type_id_string(field->type->id));
- goto end;
- }
-
- string = container_of(field,
- struct bt_ctf_field_string, parent);
- ret = string->payload->str;
-end:
- return ret;
-}
-
-int bt_ctf_field_string_set_value(struct bt_ctf_field *field,
- const char *value)
-{
- int ret = 0;
- struct bt_ctf_field_string *string;
-
- if (!field) {
- BT_LOGW_STR("Invalid parameter: field is NULL.");
- ret = -1;
- goto end;
- }
-
- if (!value) {
- BT_LOGW_STR("Invalid parameter: value is NULL.");
- ret = -1;
- goto end;
- }
-
- if (field->frozen) {
- BT_LOGW("Invalid parameter: field is frozen: addr=%p",
- field);
- ret = -1;
- goto end;
- }
-
- if (bt_ctf_field_type_get_type_id(field->type) !=
- BT_CTF_FIELD_TYPE_ID_STRING) {
- BT_LOGW("Invalid parameter: field's type is not a string field type: "
- "field-addr=%p, ft-addr=%p, ft-id=%s", field,
- field->type,
- bt_ctf_field_type_id_string(field->type->id));
- ret = -1;
- goto end;
- }
-
- string = container_of(field, struct bt_ctf_field_string, parent);
- if (string->payload) {
- g_string_assign(string->payload, value);
- } else {
- string->payload = g_string_new(value);
- }
-
- string->parent.payload_set = true;
-end:
- return ret;
-}
-
-int bt_ctf_field_string_append(struct bt_ctf_field *field,
- const char *value)
-{
- int ret = 0;
- struct bt_ctf_field_string *string_field;
-
- if (!field) {
- BT_LOGW_STR("Invalid parameter: field is NULL.");
- ret = -1;
- goto end;
- }
-
- if (!value) {
- BT_LOGW_STR("Invalid parameter: value is NULL.");
- ret = -1;
- goto end;
- }
-
- if (field->frozen) {
- BT_LOGW("Invalid parameter: field is frozen: addr=%p",
- field);
- ret = -1;
- goto end;
- }
-
- if (bt_ctf_field_type_get_type_id(field->type) !=
- BT_CTF_FIELD_TYPE_ID_STRING) {
- BT_LOGW("Invalid parameter: field's type is not a string field type: "
- "field-addr=%p, ft-addr=%p, ft-id=%s", field,
- field->type,
- bt_ctf_field_type_id_string(field->type->id));
- ret = -1;
- goto end;
- }
-
- string_field = container_of(field, struct bt_ctf_field_string, parent);
-
- if (string_field->payload) {
- g_string_append(string_field->payload, value);
- } else {
- string_field->payload = g_string_new(value);
- }
-
- string_field->parent.payload_set = true;
-
-end:
- return ret;
-}
-
-int bt_ctf_field_string_append_len(struct bt_ctf_field *field,
- const char *value, unsigned int length)
-{
- int i;
- int ret = 0;
- unsigned int effective_length = length;
- struct bt_ctf_field_string *string_field;
-
- if (!field) {
- BT_LOGW_STR("Invalid parameter: field is NULL.");
- ret = -1;
- goto end;
- }
-
- if (!value) {
- BT_LOGW_STR("Invalid parameter: value is NULL.");
- ret = -1;
- goto end;
- }
-
- if (field->frozen) {
- BT_LOGW("Invalid parameter: field is frozen: addr=%p",
- field);
- ret = -1;
- goto end;
- }
-
- if (bt_ctf_field_type_get_type_id(field->type) !=
- BT_CTF_FIELD_TYPE_ID_STRING) {
- BT_LOGW("Invalid parameter: field's type is not a string field type: "
- "field-addr=%p, ft-addr=%p, ft-id=%s", field,
- field->type,
- bt_ctf_field_type_id_string(field->type->id));
- ret = -1;
- goto end;
- }
-
- string_field = container_of(field, struct bt_ctf_field_string, parent);
-
- /* make sure no null bytes are appended */
- for (i = 0; i < length; ++i) {
- if (value[i] == '\0') {
- effective_length = i;
- break;
- }
- }
-
- if (string_field->payload) {
- g_string_append_len(string_field->payload, value,
- effective_length);
- } else {
- string_field->payload = g_string_new_len(value,
- effective_length);
- }
-
- string_field->parent.payload_set = true;
-
-end:
- return ret;
-}
-
-BT_HIDDEN
-int bt_ctf_field_validate(struct bt_ctf_field *field)
-{
- int ret = 0;
- enum bt_ctf_field_type_id type_id;
-
- if (!field) {
- BT_LOGD_STR("Invalid parameter: field is NULL.");
- ret = -1;
- goto end;
- }
-
- type_id = bt_ctf_field_type_get_type_id(field->type);
- if (type_id <= BT_CTF_FIELD_TYPE_ID_UNKNOWN || type_id >= BT_CTF_NR_TYPE_IDS) {
- BT_LOGW("Invalid parameter: unknown field type ID: "
- "addr=%p, ft-addr=%p, ft-id=%d",
- field, field->type, type_id);
- ret = -1;
- goto end;
- }
-
- ret = field_validate_funcs[type_id](field);
-end:
- return ret;
-}
-
-int bt_ctf_field_reset_value(struct bt_ctf_field *field)
-{
- int ret = 0;
- enum bt_ctf_field_type_id type_id;
-
- if (!field) {
- BT_LOGD_STR("Invalid parameter: field is NULL.");
- ret = -1;
- goto end;
- }
-
- if (field->frozen) {
- BT_LOGW("Invalid parameter: field is frozen: addr=%p",
- field);
- ret = -1;
- goto end;
- }
-
- type_id = bt_ctf_field_type_get_type_id(field->type);
- if (type_id <= BT_CTF_FIELD_TYPE_ID_UNKNOWN || type_id >= BT_CTF_NR_TYPE_IDS) {
- BT_LOGW("Invalid parameter: unknown field type ID: "
- "addr=%p, ft-addr=%p, ft-id=%d",
- field, field->type, type_id);
- ret = -1;
- goto end;
- }
-
- ret = field_reset_value_funcs[type_id](field);
-end:
- return ret;
-}
-
-BT_HIDDEN
-int bt_ctf_field_serialize(struct bt_ctf_field *field,
- struct bt_ctf_stream_pos *pos,
- enum bt_ctf_byte_order native_byte_order)
-{
- int ret = 0;
- enum bt_ctf_field_type_id type_id;
-
- assert(pos);
-
- if (!field) {
- BT_LOGD_STR("Invalid parameter: field is NULL.");
- ret = -1;
- goto end;
- }
-
- type_id = bt_ctf_field_type_get_type_id(field->type);
- if (type_id <= BT_CTF_FIELD_TYPE_ID_UNKNOWN || type_id >= BT_CTF_NR_TYPE_IDS) {
- BT_LOGW("Invalid parameter: unknown field type ID: "
- "addr=%p, ft-addr=%p, ft-id=%d",
- field, field->type, type_id);
- ret = -1;
- goto end;
- }
-
- ret = field_serialize_funcs[type_id](field, pos, native_byte_order);
-end:
- return ret;
-}
-
-bt_bool bt_ctf_field_value_is_set(struct bt_ctf_field *field)
-{
- bt_bool value_is_set = BT_FALSE;
- enum bt_ctf_field_type_id type_id;
-
- if (!field) {
- goto end;
- }
-
- type_id = bt_ctf_field_type_get_type_id(field->type);
- if (type_id <= BT_CTF_FIELD_TYPE_ID_UNKNOWN || type_id >= BT_CTF_NR_TYPE_IDS) {
- BT_LOGW("Invalid parameter: unknown field type ID: "
- "field-addr=%p, ft-addr=%p, ft-id=%d",
- field, field->type, type_id);
- goto end;
- }
-
- value_is_set = field_value_is_set_funcs[type_id](field);
-end:
- return value_is_set;
-}
-
-struct bt_ctf_field *bt_ctf_field_copy(struct bt_ctf_field *field)
-{
- int ret;
- struct bt_ctf_field *copy = NULL;
- enum bt_ctf_field_type_id type_id;
-
- if (!field) {
- BT_LOGW_STR("Invalid parameter: field is NULL.");
- goto end;
- }
-
- type_id = bt_ctf_field_type_get_type_id(field->type);
- if (type_id <= BT_CTF_FIELD_TYPE_ID_UNKNOWN || type_id >= BT_CTF_NR_TYPE_IDS) {
- BT_LOGW("Invalid parameter: unknown field type ID: "
- "field-addr=%p, ft-addr=%p, ft-id=%d",
- field, field->type, type_id);
- goto end;
- }
-
- copy = bt_ctf_field_create(field->type);
- if (!copy) {
- BT_LOGW("Cannot create field: ft-addr=%p", field->type);
- goto end;
- }