fs-sink: explicitely handle stream_begin notif
authorJulien Desfossez <jdesfossez@efficios.com>
Wed, 31 May 2017 18:35:54 +0000 (14:35 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 9 Jun 2017 20:58:16 +0000 (16:58 -0400)
Instead of creating the new streams lazily when packets begin, this
allows to handle empty streams.

Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
plugins/ctf/fs-sink/write.c
plugins/ctf/fs-sink/writer.c
plugins/ctf/fs-sink/writer.h

index 2285e92a2e4dc27e7eb39cead4bed82d49281265..9f4fe61d5dcdb0c9d13e3e517aa580aae5420664 100644 (file)
@@ -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,
index 56bab6e8f454670e8612127a5433466743bb9f71..e233a87da5ffa4d89da912a567fa57081b3dcea4 100644 (file)
@@ -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,
        };
index d34b77f9d64c874183c9aa5195740559827fbf91..da2eb1e842802ab105d458f4780a50f86f89c193 100644 (file)
@@ -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);
 
This page took 0.026963 seconds and 4 git commands to generate.