From 4841ccc167f5f99267a0c129a1e79214b60f553c Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Mon, 27 Jul 2015 09:13:46 -0400 Subject: [PATCH] ir: add bt_ctf_trace_get_stream_class_by_id() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- formats/ctf/ir/trace.c | 28 ++++++++++++++++++++++++++++ include/babeltrace/ctf-ir/trace.h | 11 +++++++++++ 2 files changed, 39 insertions(+) diff --git a/formats/ctf/ir/trace.c b/formats/ctf/ir/trace.c index 8ff6371b..9c3cb507 100644 --- a/formats/ctf/ir/trace.c +++ b/formats/ctf/ir/trace.c @@ -547,6 +547,34 @@ end: return stream_class; } +struct bt_ctf_stream_class *bt_ctf_trace_get_stream_class_by_id( + struct bt_ctf_trace *trace, uint32_t id) +{ + int i; + struct bt_ctf_stream_class *stream_class = NULL; + + if (!trace) { + goto end; + } + + for (i = 0; i < trace->stream_classes->len; ++i) { + struct bt_ctf_stream_class *stream_class_candidate; + + stream_class_candidate = + g_ptr_array_index(trace->stream_classes, i); + + if (bt_ctf_stream_class_get_id(stream_class_candidate) == + (int64_t) id) { + stream_class = stream_class_candidate; + bt_ctf_get(stream_class); + goto end; + } + } + +end: + return stream_class; +} + struct bt_ctf_clock *bt_ctf_trace_get_clock_by_name( struct bt_ctf_trace *trace, const char *name) { diff --git a/include/babeltrace/ctf-ir/trace.h b/include/babeltrace/ctf-ir/trace.h index d85a4bea..29b60980 100644 --- a/include/babeltrace/ctf-ir/trace.h +++ b/include/babeltrace/ctf-ir/trace.h @@ -264,6 +264,17 @@ extern int bt_ctf_trace_get_stream_class_count(struct bt_ctf_trace *trace); extern struct bt_ctf_stream_class *bt_ctf_trace_get_stream_class( struct bt_ctf_trace *trace, int index); +/* + * bt_ctf_trace_get_stream_class_by_id: get a trace's stream class by ID. + * + * @param trace Trace instance. + * @param index ID of the stream class in the given trace. + * + * Return a stream class on success, NULL on error. + */ +extern struct bt_ctf_stream_class *bt_ctf_trace_get_stream_class_by_id( + struct bt_ctf_trace *trace, uint32_t id); + /* * bt_ctf_trace_get_clock_by_name: get a trace's clock by name * -- 2.34.1