From f384901f99784474c5c013dd16b4333d9125dfd5 Mon Sep 17 00:00:00 2001 From: Julien Desfossez Date: Wed, 31 May 2017 14:35:54 -0400 Subject: [PATCH] fs-sink: explicitely handle stream_begin notif MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Instead of creating the new streams lazily when packets begin, this allows to handle empty streams. Signed-off-by: Julien Desfossez Signed-off-by: Jérémie Galarneau --- plugins/ctf/fs-sink/write.c | 73 +++++++++++++++++++++++------------- plugins/ctf/fs-sink/writer.c | 14 +++++++ plugins/ctf/fs-sink/writer.h | 3 ++ 3 files changed, 63 insertions(+), 27 deletions(-) diff --git a/plugins/ctf/fs-sink/write.c b/plugins/ctf/fs-sink/write.c index 2285e92a..9f4fe61d 100644 --- a/plugins/ctf/fs-sink/write.c +++ b/plugins/ctf/fs-sink/write.c @@ -279,37 +279,14 @@ struct bt_ctf_stream *get_writer_stream( struct writer_component *writer_component, struct bt_ctf_packet *packet, struct bt_ctf_stream *stream) { - struct bt_ctf_stream_class *stream_class = NULL; - struct bt_ctf_writer *ctf_writer = NULL; struct bt_ctf_stream *writer_stream = NULL; - stream_class = bt_ctf_stream_get_class(stream); - if (!stream_class) { + writer_stream = lookup_stream(writer_component, stream); + if (!writer_stream) { fprintf(writer_component->err, "[error] %s in %s:%d\n", __func__, __FILE__, __LINE__); goto error; } - - writer_stream = lookup_stream(writer_component, stream); - if (!writer_stream) { - struct fs_writer *fs_writer; - - fs_writer = get_fs_writer(writer_component, stream_class); - if (!fs_writer) { - fprintf(writer_component->err, "[error] %s in %s:%d\n", - __func__, __FILE__, __LINE__); - goto error; - } - ctf_writer = bt_get(fs_writer->writer); - writer_stream = insert_new_stream(writer_component, ctf_writer, - stream_class, stream); - if (!writer_stream) { - fprintf(writer_component->err, "[error] %s in %s:%d\n", - __func__, __FILE__, __LINE__); - goto error; - } - fs_writer->active_streams++; - } bt_get(writer_stream); goto end; @@ -317,8 +294,6 @@ struct bt_ctf_stream *get_writer_stream( error: BT_PUT(writer_stream); end: - bt_put(ctf_writer); - bt_put(stream_class); return writer_stream; } @@ -338,6 +313,50 @@ enum bt_component_status writer_close( return ret; } +BT_HIDDEN +enum bt_component_status writer_stream_begin( + struct writer_component *writer_component, + struct bt_ctf_stream *stream) +{ + struct bt_ctf_stream_class *stream_class = NULL; + struct fs_writer *fs_writer; + struct bt_ctf_writer *ctf_writer = NULL; + struct bt_ctf_stream *writer_stream = NULL; + enum bt_component_status ret = BT_COMPONENT_STATUS_OK; + + stream_class = bt_ctf_stream_get_class(stream); + if (!stream_class) { + fprintf(writer_component->err, "[error] %s in %s:%d\n", + __func__, __FILE__, __LINE__); + goto error; + } + + fs_writer = get_fs_writer(writer_component, stream_class); + if (!fs_writer) { + fprintf(writer_component->err, "[error] %s in %s:%d\n", + __func__, __FILE__, __LINE__); + goto error; + } + ctf_writer = bt_get(fs_writer->writer); + writer_stream = insert_new_stream(writer_component, ctf_writer, + stream_class, stream); + if (!writer_stream) { + fprintf(writer_component->err, "[error] %s in %s:%d\n", + __func__, __FILE__, __LINE__); + goto error; + } + fs_writer->active_streams++; + + goto end; + +error: + ret = BT_COMPONENT_STATUS_ERROR; +end: + bt_put(ctf_writer); + bt_put(stream_class); + return ret; +} + BT_HIDDEN enum bt_component_status writer_stream_end( struct writer_component *writer_component, diff --git a/plugins/ctf/fs-sink/writer.c b/plugins/ctf/fs-sink/writer.c index 56bab6e8..e233a87d 100644 --- a/plugins/ctf/fs-sink/writer.c +++ b/plugins/ctf/fs-sink/writer.c @@ -191,6 +191,19 @@ enum bt_component_status handle_notification( } break; } + case BT_NOTIFICATION_TYPE_STREAM_BEGIN: + { + struct bt_ctf_stream *stream = + bt_notification_stream_begin_get_stream(notification); + + if (!stream) { + ret = BT_COMPONENT_STATUS_ERROR; + goto end; + } + ret = writer_stream_begin(writer_component, stream); + bt_put(stream); + break; + } case BT_NOTIFICATION_TYPE_STREAM_END: { struct bt_ctf_stream *stream = @@ -223,6 +236,7 @@ void writer_component_port_connected( BT_NOTIFICATION_TYPE_EVENT, BT_NOTIFICATION_TYPE_PACKET_BEGIN, BT_NOTIFICATION_TYPE_PACKET_END, + BT_NOTIFICATION_TYPE_STREAM_BEGIN, BT_NOTIFICATION_TYPE_STREAM_END, BT_NOTIFICATION_TYPE_SENTINEL, }; diff --git a/plugins/ctf/fs-sink/writer.h b/plugins/ctf/fs-sink/writer.h index d34b77f9..da2eb1e8 100644 --- a/plugins/ctf/fs-sink/writer.h +++ b/plugins/ctf/fs-sink/writer.h @@ -67,6 +67,9 @@ BT_HIDDEN enum bt_component_status writer_close_packet(struct writer_component *writer, struct bt_ctf_packet *packet); BT_HIDDEN +enum bt_component_status writer_stream_begin(struct writer_component *writer, + struct bt_ctf_stream *stream); +BT_HIDDEN enum bt_component_status writer_stream_end(struct writer_component *writer, struct bt_ctf_stream *stream); -- 2.34.1