Fix sink.ctf.fs: mark the trace as static on destroy
[babeltrace.git] / plugins / ctf / fs-sink / writer.c
index 9fca5de779230201458582da356647bb607cea11..a21413635de990c7ebe9e2fc4ef63da7309639e1 100644 (file)
@@ -38,6 +38,7 @@
 #include <babeltrace/graph/notification-iterator.h>
 #include <babeltrace/graph/notification-event.h>
 #include <babeltrace/graph/notification-packet.h>
+#include <babeltrace/graph/notification-stream.h>
 #include <plugins-common.h>
 #include <stdio.h>
 #include <stdbool.h>
 #include "writer.h"
 #include <assert.h>
 
+gboolean empty_trace_map(gpointer key, gpointer value, gpointer user_data)
+{
+       struct fs_writer *fs_writer = value;
+       struct writer_component *writer_component = user_data;
+
+       fs_writer->trace_static = 1;
+       writer_close(writer_component, fs_writer);
+
+       return TRUE;
+}
+
 static
 void destroy_writer_component_data(struct writer_component *writer_component)
 {
        bt_put(writer_component->input_iterator);
-       g_hash_table_destroy(writer_component->stream_map);
-       g_hash_table_destroy(writer_component->stream_class_map);
+
+       g_hash_table_foreach_remove(writer_component->trace_map,
+                       empty_trace_map, writer_component);
        g_hash_table_destroy(writer_component->trace_map);
+
        g_string_free(writer_component->base_path, true);
        g_string_free(writer_component->trace_name_base, true);
 }
@@ -67,21 +81,10 @@ void writer_component_finalize(struct bt_private_component *component)
 }
 
 static
-void unref_stream_class(struct bt_ctf_stream_class *writer_stream_class)
-{
-       bt_put(writer_stream_class);
-}
-
-static
-void unref_stream(struct bt_ctf_stream_class *writer_stream)
-{
-       bt_put(writer_stream);
-}
-
-static
-void unref_trace(struct bt_ctf_writer *writer)
+void free_fs_writer(struct fs_writer *fs_writer)
 {
-       bt_put(writer);
+       bt_put(fs_writer->writer);
+       g_free(fs_writer);
 }
 
 static
@@ -97,7 +100,6 @@ struct writer_component *create_writer_component(void)
        writer_component->err = stderr;
        writer_component->trace_id = 0;
        writer_component->trace_name_base = g_string_new("trace");
-       writer_component->processed_first_event = false;
        if (!writer_component->trace_name_base) {
                g_free(writer_component);
                writer_component = NULL;
@@ -108,11 +110,7 @@ struct writer_component *create_writer_component(void)
         * Reader to writer corresponding structures.
         */
        writer_component->trace_map = g_hash_table_new_full(g_direct_hash,
-                       g_direct_equal, NULL, (GDestroyNotify) unref_trace);
-       writer_component->stream_class_map = g_hash_table_new_full(g_direct_hash,
-                       g_direct_equal, NULL, (GDestroyNotify) unref_stream_class);
-       writer_component->stream_map = g_hash_table_new_full(g_direct_hash,
-                       g_direct_equal, NULL, (GDestroyNotify) unref_stream);
+                       g_direct_equal, NULL, (GDestroyNotify) free_fs_writer);
 
 end:
        return writer_component;
@@ -167,7 +165,6 @@ enum bt_component_status handle_notification(
                        ret = BT_COMPONENT_STATUS_ERROR;
                        goto end;
                }
-               ret = BT_COMPONENT_STATUS_OK;
                ret = writer_output_event(writer_component, event);
                bt_put(event);
                if (ret != BT_COMPONENT_STATUS_OK) {
@@ -175,8 +172,32 @@ 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 =
+                       bt_notification_stream_end_get_stream(notification);
+
+               if (!stream) {
+                       ret = BT_COMPONENT_STATUS_ERROR;
+                       goto end;
+               }
+               ret = writer_stream_end(writer_component, stream);
+               bt_put(stream);
                break;
+       }
        default:
                puts("Unhandled notification type");
        }
@@ -192,6 +213,14 @@ void writer_component_port_connected(
 {
        struct bt_private_connection *connection;
        struct writer_component *writer;
+       static const enum bt_notification_type notif_types[] = {
+               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,
+       };
 
        writer = bt_private_component_get_user_data(component);
        assert(writer);
@@ -200,7 +229,7 @@ void writer_component_port_connected(
        assert(connection);
        writer->input_iterator =
                bt_private_connection_create_notification_iterator(connection,
-                       NULL);
+                       notif_types);
 
        if (!writer->input_iterator) {
                writer->error = true;
This page took 0.025335 seconds and 4 git commands to generate.