From e96045d4f186a5f3a7ed1f5585cf4cbfe890f579 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Tue, 15 Nov 2016 16:47:18 -0500 Subject: [PATCH] Add trace name attribute MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- formats/ctf/ir/trace.c | 36 ++++++++++++++++++++++ include/babeltrace/ctf-ir/trace-internal.h | 1 + include/babeltrace/ctf-ir/trace.h | 4 +++ 3 files changed, 41 insertions(+) diff --git a/formats/ctf/ir/trace.c b/formats/ctf/ir/trace.c index 55967275..4cf2462b 100644 --- a/formats/ctf/ir/trace.c +++ b/formats/ctf/ir/trace.c @@ -124,6 +124,38 @@ error: return trace; } +const char *bt_ctf_trace_get_name(struct bt_ctf_trace *trace) +{ + const char *name = NULL; + + if (!trace || !trace->name) { + goto end; + } + + name = trace->name->str; +end: + return name; +} + +int bt_ctf_trace_set_name(struct bt_ctf_trace *trace, const char *name) +{ + int ret = 0; + + if (!trace || !name || trace->frozen) { + ret = -1; + goto end; + } + + trace->name = trace->name ? g_string_assign(trace->name, name) : + g_string_new(name); + if (!trace->name) { + ret = -1; + goto end; + } +end: + return ret; +} + void bt_ctf_trace_destroy(struct bt_object *obj) { struct bt_ctf_trace *trace; @@ -133,6 +165,10 @@ void bt_ctf_trace_destroy(struct bt_object *obj) bt_ctf_attributes_destroy(trace->environment); } + if (trace->name) { + g_string_free(trace->name, TRUE); + } + if (trace->clocks) { g_ptr_array_free(trace->clocks, TRUE); } diff --git a/include/babeltrace/ctf-ir/trace-internal.h b/include/babeltrace/ctf-ir/trace-internal.h index db3d84f7..a782d04c 100644 --- a/include/babeltrace/ctf-ir/trace-internal.h +++ b/include/babeltrace/ctf-ir/trace-internal.h @@ -49,6 +49,7 @@ enum field_type_alias { struct bt_ctf_trace { struct bt_object base; + GString *name; int frozen; uuid_t uuid; int byte_order; /* A value defined in Babeltrace's "endian.h" */ diff --git a/include/babeltrace/ctf-ir/trace.h b/include/babeltrace/ctf-ir/trace.h index fae7832b..e935dd1f 100644 --- a/include/babeltrace/ctf-ir/trace.h +++ b/include/babeltrace/ctf-ir/trace.h @@ -71,6 +71,10 @@ typedef void (*bt_ctf_listener_cb)( */ extern struct bt_ctf_trace *bt_ctf_trace_create(void); +extern const char *bt_ctf_trace_get_name(struct bt_ctf_trace *trace); + +extern int bt_ctf_trace_set_name(struct bt_ctf_trace *trace, const char *name); + /* * bt_ctf_trace_set_environment_field: sets an environment field to the * trace. -- 2.34.1