From d9b1ab6dad281d8ba70f6c8dd372ab489ea465c0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Mon, 9 Mar 2015 14:28:08 -0400 Subject: [PATCH] Implement bt_ctf_field_type_variant_set_tag_name() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- formats/ctf/ir/event-types.c | 19 +++++++++++++++++++ include/babeltrace/ctf-ir/event-types.h | 11 +++++++++++ 2 files changed, 30 insertions(+) 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. * -- 2.34.1