From e6fa216001c0b8a91868c1982bae990c1304965c Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Sun, 1 Mar 2015 21:03:10 -0500 Subject: [PATCH] Add trace environment field getters 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 | 91 ++++++++++++++++++++++++++++++- include/babeltrace/ctf-ir/trace.h | 72 ++++++++++++++++++++++++ 2 files changed, 162 insertions(+), 1 deletion(-) diff --git a/formats/ctf/ir/trace.c b/formats/ctf/ir/trace.c index 8d5f7270..5787f9f5 100644 --- a/formats/ctf/ir/trace.c +++ b/formats/ctf/ir/trace.c @@ -259,7 +259,7 @@ error: int bt_ctf_trace_add_environment_field_integer(struct bt_ctf_trace *trace, const char *name, - int64_t value) + int64_t value) { struct environment_variable *var = NULL; int ret = 0; @@ -295,6 +295,95 @@ error: return ret; } +int bt_ctf_trace_get_environment_field_count(struct bt_ctf_trace *trace) +{ + int ret = 0; + + if (!trace) { + ret = -1; + goto end; + } + + ret = trace->environment->len; +end: + return ret; +} + +enum bt_environment_field_type +bt_ctf_trace_get_environment_field_type(struct bt_ctf_trace *trace, int index) +{ + struct environment_variable *var; + enum bt_environment_field_type type = BT_ENVIRONMENT_FIELD_TYPE_UNKNOWN; + + if (!trace || index < 0 || index >= trace->environment->len) { + goto end; + } + + var = g_ptr_array_index(trace->environment, index); + type = var->type; +end: + return type; +} + +const char * +bt_ctf_trace_get_environment_field_name(struct bt_ctf_trace *trace, + int index) +{ + struct environment_variable *var; + const char *ret = NULL; + + if (!trace || index < 0 || index >= trace->environment->len) { + goto end; + } + + var = g_ptr_array_index(trace->environment, index); + ret = var->name->str; +end: + return ret; +} + +const char * +bt_ctf_trace_get_environment_field_value_string(struct bt_ctf_trace *trace, + int index) +{ + struct environment_variable *var; + const char *ret = NULL; + + if (!trace || index < 0 || index >= trace->environment->len) { + goto end; + } + + var = g_ptr_array_index(trace->environment, index); + if (var->type != BT_ENVIRONMENT_FIELD_TYPE_STRING) { + goto end; + } + ret = var->value.string->str; +end: + return ret; +} + +int +bt_ctf_trace_get_environment_field_value_integer(struct bt_ctf_trace *trace, + int index, int64_t *value) +{ + struct environment_variable *var; + int ret = 0; + + if (!trace || !value || index < 0 || index >= trace->environment->len) { + ret = -1; + goto end; + } + + var = g_ptr_array_index(trace->environment, index); + if (var->type != BT_ENVIRONMENT_FIELD_TYPE_INTEGER) { + ret = -1; + goto end; + } + *value = var->value.integer; +end: + return ret; +} + int bt_ctf_trace_add_clock(struct bt_ctf_trace *trace, struct bt_ctf_clock *clock) { diff --git a/include/babeltrace/ctf-ir/trace.h b/include/babeltrace/ctf-ir/trace.h index f5f3415c..cf14dcff 100644 --- a/include/babeltrace/ctf-ir/trace.h +++ b/include/babeltrace/ctf-ir/trace.h @@ -111,6 +111,78 @@ extern int bt_ctf_trace_add_environment_field_integer( struct bt_ctf_trace *trace, const char *name, int64_t value); +/* + * bt_ctf_trace_get_environment_field_count: get environment field count. + * + * Get the trace's environment field count. + * + * @param trace Trace instance. + * + * Returns the environment field count, a negative value on error. + */ +extern int bt_ctf_trace_get_environment_field_count( + struct bt_ctf_trace *trace); + +/* + * bt_ctf_trace_get_environment_field_type: get environment field type. + * + * Get an environment field's type. + * + * @param trace Trace instance. + * @param index Index of the environment field. + * + * Returns the environment field count, a negative value on error. + */ +extern enum bt_environment_field_type +bt_ctf_trace_get_environment_field_type(struct bt_ctf_trace *trace, + int index); + +/* + * bt_ctf_trace_get_environment_field_name: get environment field name. + * + * Get an environment field's name. The string's ownership is not + * transferred to the caller. + * + * @param trace Trace instance. + * @param index Index of the environment field. + * + * Returns the environment field's name, NULL on error. + */ +extern const char * +bt_ctf_trace_get_environment_field_name(struct bt_ctf_trace *trace, + int index); + +/* + * bt_ctf_trace_get_environment_field_value_string: get environment field + * string value. + * + * Get an environment field's string value. The string's ownership is not + * transferred to the caller. + * + * @param trace Trace instance. + * @param index Index of the environment field. + * + * Returns the environment field's string value, NULL on error. + */ +extern const char * +bt_ctf_trace_get_environment_field_value_string(struct bt_ctf_trace *trace, + int index); + +/* + * bt_ctf_trace_get_environment_field_value_integer: get environment field + * integer value. + * + * Get an environment field's integer value. + * + * @param trace Trace instance. + * @param index Index of the environment field. + * + * Returns the environment field's integer value, a negative value on error. + */ +extern int +bt_ctf_trace_get_environment_field_value_integer(struct bt_ctf_trace *trace, + int index, int64_t *value); + /* * bt_ctf_trace_add_clock: add a clock to the trace. * -- 2.34.1