From 884cd6c32dddeb5e9fa8d0255992956112381123 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Mon, 20 Oct 2014 13:39:46 -0400 Subject: [PATCH] Add clock accessor to CTF IR Trace 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 | 28 ++++++++++++++++++++++++++++ include/babeltrace/ctf-ir/trace.h | 21 +++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/formats/ctf/ir/trace.c b/formats/ctf/ir/trace.c index 073e4abf..1ad37bec 100644 --- a/formats/ctf/ir/trace.c +++ b/formats/ctf/ir/trace.c @@ -282,6 +282,34 @@ end: return ret; } +int bt_ctf_trace_get_clock_count(struct bt_ctf_trace *trace) +{ + int ret = -1; + + if (!trace) { + goto end; + } + + ret = trace->clocks->len; +end: + return ret; +} + +struct bt_ctf_clock *bt_ctf_trace_get_clock(struct bt_ctf_trace *trace, + int index) +{ + struct bt_ctf_clock *clock = NULL; + + if (!trace || index < 0 || index >= trace->clocks->len) { + goto end; + } + + clock = g_ptr_array_index(trace->clocks, index); + bt_ctf_clock_get(clock); +end: + return clock; +} + BT_HIDDEN const char *get_byte_order_string(int byte_order) { diff --git a/include/babeltrace/ctf-ir/trace.h b/include/babeltrace/ctf-ir/trace.h index 1be85cfd..d36da0eb 100644 --- a/include/babeltrace/ctf-ir/trace.h +++ b/include/babeltrace/ctf-ir/trace.h @@ -95,6 +95,27 @@ extern int bt_ctf_trace_add_environment_field(struct bt_ctf_trace *trace, extern int bt_ctf_trace_add_clock(struct bt_ctf_trace *trace, struct bt_ctf_clock *clock); +/* + * bt_ctf_trace_get_clock_count: get the number of clocks + * associated to the trace. + * + * @param trace Trace instance. + * + * Returns the clock count on success, a negative value on error. + */ +extern int bt_ctf_trace_get_clock_count(struct bt_ctf_trace *trace); + +/* + * bt_ctf_trace_get_clock: get a trace's clock at index. + * + * @param trace Trace instance. + * @param index Index of the clock in the given trace. + * + * Return a clock instance on success, NULL on error. + */ +extern struct bt_ctf_clock *bt_ctf_trace_get_clock( + struct bt_ctf_trace *trace, int index); + /* * bt_ctf_trace_get_metadata_string: get metadata string. * -- 2.34.1