X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=formats%2Fctf%2Fwriter%2Fwriter.c;h=fe6f52cbf918372094a18d95c00e65702c150a01;hb=319fd969d5f098775f83f9a4c5c394d4a96db999;hp=babe033b03931e6e9219cd54c2ee02ff0cf231ae;hpb=b25d20adeabe34126cacaf6b7f93883c1c98ad90;p=babeltrace.git diff --git a/formats/ctf/writer/writer.c b/formats/ctf/writer/writer.c index babe033b..fe6f52cb 100644 --- a/formats/ctf/writer/writer.c +++ b/formats/ctf/writer/writer.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -46,10 +47,6 @@ static void bt_ctf_writer_destroy(struct bt_object *obj); -static -int create_stream_file(struct bt_ctf_writer *writer, - struct bt_ctf_stream *stream); - struct bt_ctf_writer *bt_ctf_writer_create(const char *path) { struct bt_ctf_writer *writer = NULL; @@ -74,6 +71,7 @@ struct bt_ctf_writer *bt_ctf_writer_create(const char *path) goto error_destroy; } + writer->trace->is_created_by_writer = 1; bt_object_set_parent(writer->trace, writer); bt_put(writer->trace); /* Create trace directory if necessary and open a metadata file */ @@ -144,24 +142,50 @@ end: struct bt_ctf_stream *bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, struct bt_ctf_stream_class *stream_class) { - int stream_fd; struct bt_ctf_stream *stream = NULL; + int stream_class_count; + bool stream_class_found = false; + int i; if (!writer || !stream_class) { goto error; } - stream = bt_ctf_trace_create_stream(writer->trace, stream_class); - if (!stream) { + /* Make sure the stream class is part of the writer's trace */ + stream_class_count = bt_ctf_trace_get_stream_class_count(writer->trace); + if (stream_class_count < 0) { goto error; } - stream_fd = create_stream_file(writer, stream); - if (stream_fd < 0 || bt_ctf_stream_set_fd(stream, stream_fd)) { + for (i = 0; i < stream_class_count; i++) { + struct bt_ctf_stream_class *existing_stream_class = + bt_ctf_trace_get_stream_class(writer->trace, i); + + if (existing_stream_class == stream_class) { + stream_class_found = true; + } + + BT_PUT(existing_stream_class); + + if (stream_class_found) { + break; + } + } + + if (!stream_class_found) { + int ret = bt_ctf_trace_add_stream_class(writer->trace, + stream_class); + + if (ret) { + goto error; + } + } + + stream = bt_ctf_stream_create(stream_class); + if (!stream) { goto error; } - writer->frozen = 1; return stream; error: @@ -274,30 +298,8 @@ void bt_ctf_writer_put(struct bt_ctf_writer *writer) bt_put(writer); } -static -int create_stream_file(struct bt_ctf_writer *writer, - struct bt_ctf_stream *stream) +BT_HIDDEN +void bt_ctf_writer_freeze(struct bt_ctf_writer *writer) { - int fd; - GString *filename = g_string_new(stream->stream_class->name->str); - - if (stream->stream_class->name->len == 0) { - int64_t ret; - - ret = bt_ctf_stream_class_get_id(stream->stream_class); - if (ret < 0) { - fd = -1; - goto error; - } - - g_string_printf(filename, "stream_%" PRId64, ret); - } - - g_string_append_printf(filename, "_%" PRIu32, stream->id); - fd = openat(writer->trace_dir_fd, filename->str, - O_RDWR | O_CREAT | O_TRUNC, - S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); -error: - g_string_free(filename, TRUE); - return fd; + writer->frozen = 1; }