Implement CTF-IR event getters
[babeltrace.git] / formats / ctf / writer / writer.c
index a3ca263adeca7a9eb934ea6dd74432262e7e02b9..57236bd94186baa0c3e562cb1a49834191b39971 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Babeltrace CTF Writer
  *
- * Copyright 2013 EfficiOS Inc.
+ * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
  * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
 
 #include <babeltrace/ctf-writer/writer.h>
 #include <babeltrace/ctf-writer/clock.h>
-#include <babeltrace/ctf-writer/clock-internal.h>
+#include <babeltrace/ctf-ir/clock-internal.h>
 #include <babeltrace/ctf-writer/writer-internal.h>
-#include <babeltrace/ctf-writer/event-types-internal.h>
-#include <babeltrace/ctf-writer/event-fields-internal.h>
+#include <babeltrace/ctf-ir/event-types-internal.h>
+#include <babeltrace/ctf-ir/event-fields-internal.h>
 #include <babeltrace/ctf-writer/functor-internal.h>
+#include <babeltrace/ctf-ir/stream-class-internal.h>
 #include <babeltrace/ctf-writer/stream-internal.h>
 #include <babeltrace/ctf-writer/stream.h>
 #include <babeltrace/compiler.h>
@@ -233,6 +234,7 @@ struct bt_ctf_stream *bt_ctf_writer_create_stream(struct bt_ctf_writer *writer,
                goto error;
        }
 
+
        for (i = 0; i < writer->stream_classes->len; i++) {
                if (writer->stream_classes->pdata[i] == stream->stream_class) {
                        stream_class_found = 1;
@@ -240,11 +242,21 @@ struct bt_ctf_stream *bt_ctf_writer_create_stream(struct bt_ctf_writer *writer,
        }
 
        if (!stream_class_found) {
-               if (bt_ctf_stream_class_set_id(stream->stream_class,
-                       writer->next_stream_id++)) {
-                       goto error;
+               int64_t stream_id = bt_ctf_stream_class_get_id(stream_class);
+               if (stream_id < 0) {
+                       if (bt_ctf_stream_class_set_id(stream->stream_class,
+                               writer->next_stream_id++)) {
+                               goto error;
+                       }
                }
 
+               for (i = 0; i < writer->stream_classes->len; i++) {
+                       if (stream_id == bt_ctf_stream_class_get_id(
+                                   writer->stream_classes->pdata[i])) {
+                               /* Duplicate stream id found */
+                               goto error;
+                       }
+               }
                bt_ctf_stream_class_get(stream->stream_class);
                g_ptr_array_add(writer->stream_classes, stream->stream_class);
        }
@@ -357,7 +369,7 @@ const char *get_byte_order_string(int byte_order)
 }
 
 static
-void append_trace_metadata(struct bt_ctf_writer *writer,
+int append_trace_metadata(struct bt_ctf_writer *writer,
                struct metadata_context *context)
 {
        unsigned char *uuid = writer->uuid;
@@ -382,10 +394,14 @@ void append_trace_metadata(struct bt_ctf_writer *writer,
        g_string_assign(context->field_name, "");
        ret = bt_ctf_field_type_serialize(writer->trace_packet_header_type,
                context);
-       assert(!ret);
+       if (ret) {
+               goto end;
+       }
        context->current_indentation_level--;
 
        g_string_append(context->string, ";\n};\n\n");
+end:
+       return ret;
 }
 
 static
@@ -429,7 +445,9 @@ char *bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer)
        context->field_name = g_string_sized_new(DEFAULT_IDENTIFIER_SIZE);
        context->string = g_string_sized_new(DEFAULT_METADATA_STRING_SIZE);
        g_string_append(context->string, "/* CTF 1.8 */\n\n");
-       append_trace_metadata(writer, context);
+       if (append_trace_metadata(writer, context)) {
+               goto error;
+       }
        append_env_metadata(writer, context);
        g_ptr_array_foreach(writer->clocks,
                (GFunc)bt_ctf_clock_serialize, context);
@@ -717,7 +735,7 @@ void stream_flush_cb(struct bt_ctf_stream *stream, struct bt_ctf_writer *writer)
 
        stream_id = bt_ctf_field_structure_get_field(
                writer->trace_packet_header, "stream_id");
-       bt_ctf_field_unsigned_integer_set_value(stream_id, stream->id);
+       bt_ctf_field_unsigned_integer_set_value(stream_id, stream->stream_class->id);
        bt_ctf_field_put(stream_id);
 
        /* Write the trace_packet_header */
This page took 0.02393 seconds and 4 git commands to generate.