Add bt_ctf_trace_get_stream_count() and bt_ctf_trace_get_stream()
[babeltrace.git] / lib / ctf-ir / trace.c
index 90432dbac36273de8e896f428aa5e614f79bb6a7..b850b4ffe6e35495fcc07bad3eea2c2105a41a75 100644 (file)
 #include <babeltrace/ctf-ir/validation-internal.h>
 #include <babeltrace/ctf-ir/visitor-internal.h>
 #include <babeltrace/ctf-ir/utils.h>
-#include <babeltrace/graph/notification-schema.h>
-#include <babeltrace/compiler.h>
+#include <babeltrace/compiler-internal.h>
 #include <babeltrace/values.h>
 #include <babeltrace/ref.h>
-#include <babeltrace/endian.h>
+#include <babeltrace/endian-internal.h>
 #include <inttypes.h>
 
 #define DEFAULT_IDENTIFIER_SIZE 128
@@ -89,7 +88,7 @@ struct bt_ctf_trace *bt_ctf_trace_create(void)
                goto error;
        }
 
-       bt_ctf_trace_set_byte_order(trace, BT_CTF_BYTE_ORDER_NATIVE);
+       trace->native_byte_order = BT_CTF_BYTE_ORDER_NATIVE;
        bt_object_init(trace, bt_ctf_trace_destroy);
        trace->clocks = g_ptr_array_new_with_free_func(
                (GDestroyNotify) bt_put);
@@ -389,7 +388,6 @@ int bt_ctf_trace_add_clock_class(struct bt_ctf_trace *trace,
                struct bt_ctf_clock_class *clock_class)
 {
        int ret = 0;
-       struct search_query query = { .value = clock_class, .found = 0 };
 
        if (!trace || !bt_ctf_clock_class_is_valid(clock_class)) {
                ret = -1;
@@ -397,8 +395,7 @@ int bt_ctf_trace_add_clock_class(struct bt_ctf_trace *trace,
        }
 
        /* Check for duplicate clock classes */
-       g_ptr_array_foreach(trace->clocks, value_exists, &query);
-       if (query.found) {
+       if (bt_ctf_trace_has_clock_class(trace, clock_class)) {
                ret = -1;
                goto end;
        }
@@ -465,6 +462,15 @@ int bt_ctf_trace_add_stream_class(struct bt_ctf_trace *trace,
                goto end;
        }
 
+       /*
+        * At the end of this function we freeze the trace, so its
+        * native byte order must NOT be BT_CTF_BYTE_ORDER_NATIVE.
+        */
+       if (trace->native_byte_order == BT_CTF_BYTE_ORDER_NATIVE) {
+               ret = -1;
+               goto end;
+       }
+
        current_parent_trace = bt_ctf_stream_class_get_trace(stream_class);
        if (current_parent_trace) {
                /* Stream class is already associated to a trace, abort. */
@@ -709,6 +715,36 @@ end:
        return ret;
 }
 
+int bt_ctf_trace_get_stream_count(struct bt_ctf_trace *trace)
+{
+       int ret;
+
+       if (!trace) {
+               ret = -1;
+               goto end;
+       }
+
+       ret = trace->streams->len;
+
+end:
+       return ret;
+}
+
+struct bt_ctf_stream *bt_ctf_trace_get_stream(struct bt_ctf_trace *trace,
+               int index)
+{
+       struct bt_ctf_stream *stream = NULL;
+
+       if (!trace || index >= trace->streams->len) {
+               goto end;
+       }
+
+       stream = bt_get(g_ptr_array_index(trace->streams, index));
+
+end:
+       return stream;
+}
+
 int bt_ctf_trace_get_stream_class_count(struct bt_ctf_trace *trace)
 {
        int ret;
@@ -796,6 +832,19 @@ end:
        return clock_class;
 }
 
+BT_HIDDEN
+bool bt_ctf_trace_has_clock_class(struct bt_ctf_trace *trace,
+               struct bt_ctf_clock_class *clock_class)
+{
+       struct search_query query = { .value = clock_class, .found = 0 };
+
+       assert(trace);
+       assert(clock_class);
+
+       g_ptr_array_foreach(trace->clocks, value_exists, &query);
+       return query.found;
+}
+
 BT_HIDDEN
 const char *get_byte_order_string(enum bt_ctf_byte_order byte_order)
 {
@@ -995,7 +1044,7 @@ end:
        return ret;
 }
 
-int bt_ctf_trace_set_byte_order(struct bt_ctf_trace *trace,
+int bt_ctf_trace_set_native_byte_order(struct bt_ctf_trace *trace,
                enum bt_ctf_byte_order byte_order)
 {
        int ret = 0;
This page took 0.026559 seconds and 4 git commands to generate.