From: Jérémie Galarneau Date: Thu, 12 Jun 2014 19:00:39 +0000 (-0400) Subject: Implement CTF-IR stream class getters X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=69dc4535c16c08b0db87a9d6efe4a494005e0c95;p=deliverable%2Fbabeltrace.git Implement CTF-IR stream class getters Signed-off-by: Jérémie Galarneau --- diff --git a/formats/ctf/ir/stream-class.c b/formats/ctf/ir/stream-class.c index 7957a4961..670159783 100644 --- a/formats/ctf/ir/stream-class.c +++ b/formats/ctf/ir/stream-class.c @@ -77,6 +77,20 @@ error: return stream_class; } +const char *bt_ctf_stream_class_get_name( + struct bt_ctf_stream_class *stream_class) +{ + const char *name = NULL; + + if (!stream_class) { + goto end; + } + + name = stream_class->name->str; +end: + return name; +} + struct bt_ctf_clock *bt_ctf_stream_class_get_clock( struct bt_ctf_stream_class *stream_class) { @@ -183,6 +197,66 @@ end: return ret; } +int64_t bt_ctf_stream_class_get_event_class_count( + struct bt_ctf_stream_class *stream_class) +{ + int64_t ret; + + if (!stream_class) { + ret = -1; + goto end; + } + + ret = (int64_t) stream_class->event_classes->len; +end: + return ret; +} + +struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class( + struct bt_ctf_stream_class *stream_class, size_t index) +{ + struct bt_ctf_event_class *event_class = NULL; + + if (!stream_class || index >= stream_class->event_classes->len) { + goto end; + } + + event_class = g_ptr_array_index(stream_class->event_classes, index); + bt_ctf_event_class_get(event_class); +end: + return event_class; +} + +struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class_by_name( + struct bt_ctf_stream_class *stream_class, const char *name) +{ + size_t i; + GQuark name_quark; + struct bt_ctf_event_class *event_class = NULL; + + if (!stream_class || !name) { + goto end; + } + + name_quark = g_quark_try_string(name); + if (!name_quark) { + goto end; + } + + for (i = 0; i < stream_class->event_classes->len; i++) { + struct bt_ctf_event_class *current_event_class = + g_ptr_array_index(stream_class->event_classes, i); + + if (name_quark == current_event_class->name) { + event_class = current_event_class; + bt_ctf_event_class_get(event_class); + goto end; + } + } +end: + return event_class; +} + void bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class) { if (!stream_class) { diff --git a/include/babeltrace/ctf-ir/stream-class.h b/include/babeltrace/ctf-ir/stream-class.h index d26bc2ca8..ef6bc778d 100644 --- a/include/babeltrace/ctf-ir/stream-class.h +++ b/include/babeltrace/ctf-ir/stream-class.h @@ -50,6 +50,16 @@ struct bt_ctf_clock; */ extern struct bt_ctf_stream_class *bt_ctf_stream_class_create(const char *name); +/* + * bt_ctf_stream_class_get_name: Get a stream class' name. + * + * @param stream_class Stream class. + * + * Returns the stream class' name, NULL on error. + */ +extern const char *bt_ctf_stream_class_get_name( + struct bt_ctf_stream_class *stream_class); + /* * bt_ctf_stream_class_get_clock: get the clock associated with a stream class. * @@ -118,6 +128,40 @@ extern int bt_ctf_stream_class_add_event_class( struct bt_ctf_stream_class *stream_class, struct bt_ctf_event_class *event_class); +/* + * bt_ctf_stream_class_get_event_class_count: Get a stream class' event class + * count. + * + * @param stream_class Stream class. + * + * Returns the stream class' event count, a negative value on error. + */ +extern int64_t bt_ctf_stream_class_get_event_class_count( + struct bt_ctf_stream_class *stream_class); + +/* + * bt_ctf_stream_class_get_event_class: Get stream class event class by index. + * + * @param stream_class Stream class. + * @param index Index of field. + * + * Returns event class, NULL on error. + */ +extern struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class( + struct bt_ctf_stream_class *stream_class, size_t index); + +/* + * bt_ctf_stream_class_get_event_class_by_name: Get stream class event class by + * name. + * + * @param stream_class Stream class. + * @param name Event name. + * + * Returns event class, NULL on error. + */ +extern struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class_by_name( + struct bt_ctf_stream_class *stream_class, const char *name); + /* * bt_ctf_stream_class_get and bt_ctf_stream_class_put: increment and * decrement the stream class' reference count.