From: Jérémie Galarneau Date: Mon, 9 Mar 2015 18:28:08 +0000 (-0400) Subject: Implement bt_ctf_field_type_variant_set_tag_name() X-Git-Tag: v2.0.0-pre1~1320 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=d9b1ab6dad281d8ba70f6c8dd372ab489ea465c0 Implement bt_ctf_field_type_variant_set_tag_name() Signed-off-by: Jérémie Galarneau --- diff --git a/formats/ctf/ir/event-types.c b/formats/ctf/ir/event-types.c index a4dca127..11ca0e9e 100644 --- a/formats/ctf/ir/event-types.c +++ b/formats/ctf/ir/event-types.c @@ -1334,6 +1334,25 @@ end: return tag_name; } +int bt_ctf_field_type_variant_set_tag_name( + struct bt_ctf_field_type *type, const char *name) +{ + int ret = 0; + struct bt_ctf_field_type_variant *variant; + + if (!type || type->frozen || + (type->declaration->id != CTF_TYPE_VARIANT) || + bt_ctf_validate_identifier(name)) { + ret = -1; + goto end; + } + + variant = container_of(type, struct bt_ctf_field_type_variant, parent); + g_string_assign(variant->tag_name, name); +end: + return ret; +} + int bt_ctf_field_type_variant_add_field(struct bt_ctf_field_type *type, struct bt_ctf_field_type *field_type, const char *field_name) diff --git a/include/babeltrace/ctf-ir/event-types.h b/include/babeltrace/ctf-ir/event-types.h index 19dd6a33..20069435 100644 --- a/include/babeltrace/ctf-ir/event-types.h +++ b/include/babeltrace/ctf-ir/event-types.h @@ -501,6 +501,17 @@ extern struct bt_ctf_field_type *bt_ctf_field_type_variant_get_tag_type( extern const char *bt_ctf_field_type_variant_get_tag_name( struct bt_ctf_field_type *variant); +/* + * bt_ctf_field_type_variant_set_tag_name: set a variant's tag name. + * + * @param variant Variant type. + * @param name Tag field name. + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_field_type_variant_set_tag_name( + struct bt_ctf_field_type *variant, const char *name); + /* * bt_ctf_field_type_variant_add_field: add a field to a variant. *