lib: make packets and packet messages optional, disabled by default
[babeltrace.git] / src / plugins / ctf / fs-sink / fs-sink.c
index 7ecc7875296844e70b0e2a0d97adfde150138d1e..239e7ad10ed3ffc087ade96dd152218b35a9269e 100644 (file)
  * SOFTWARE.
  */
 
-#define BT_LOG_TAG "PLUGIN-CTF-FS-SINK"
-#include "logging.h"
+#define BT_COMP_LOG_SELF_COMP (fs_sink->self_comp)
+#define BT_LOG_OUTPUT_LEVEL (fs_sink->log_level)
+#define BT_LOG_TAG "PLUGIN/SINK.CTF.FS"
+#include "plugins/comp-logging.h"
 
 #include <babeltrace2/babeltrace.h>
 #include <stdio.h>
@@ -41,18 +43,20 @@ static
 const char * const in_port_name = "in";
 
 static
-bt_self_component_status ensure_output_dir_exists(
+bt_component_class_init_method_status ensure_output_dir_exists(
                struct fs_sink_comp *fs_sink)
 {
-       bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK;
+       bt_component_class_init_method_status status =
+               BT_COMPONENT_CLASS_INIT_METHOD_STATUS_OK;
        int ret;
 
        ret = g_mkdir_with_parents(fs_sink->output_dir_path->str, 0755);
        if (ret) {
-               BT_LOGE_ERRNO("Cannot create directories for output directory",
+               BT_COMP_LOGE_ERRNO(
+                       "Cannot create directories for output directory",
                        ": output-dir-path=\"%s\"",
                        fs_sink->output_dir_path->str);
-               status = BT_SELF_COMPONENT_STATUS_ERROR;
+               status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_ERROR;
                goto end;
        }
 
@@ -61,22 +65,24 @@ end:
 }
 
 static
-bt_self_component_status configure_component(struct fs_sink_comp *fs_sink,
+bt_component_class_init_method_status
+configure_component(struct fs_sink_comp *fs_sink,
                const bt_value *params)
 {
-       bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK;
+       bt_component_class_init_method_status status =
+               BT_COMPONENT_CLASS_INIT_METHOD_STATUS_OK;
        const bt_value *value;
 
        value = bt_value_map_borrow_entry_value_const(params, "path");
        if (!value) {
-               BT_LOGE_STR("Missing mandatory `path` parameter.");
-               status = BT_SELF_COMPONENT_STATUS_ERROR;
+               BT_COMP_LOGE_STR("Missing mandatory `path` parameter.");
+               status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_ERROR;
                goto end;
        }
 
        if (!bt_value_is_string(value)) {
-               BT_LOGE_STR("`path` parameter: expecting a string.");
-               status = BT_SELF_COMPONENT_STATUS_ERROR;
+               BT_COMP_LOGE_STR("`path` parameter: expecting a string.");
+               status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_ERROR;
                goto end;
        }
 
@@ -86,8 +92,8 @@ bt_self_component_status configure_component(struct fs_sink_comp *fs_sink,
                "assume-single-trace");
        if (value) {
                if (!bt_value_is_bool(value)) {
-                       BT_LOGE_STR("`assume-single-trace` parameter: expecting a boolean.");
-                       status = BT_SELF_COMPONENT_STATUS_ERROR;
+                       BT_COMP_LOGE_STR("`assume-single-trace` parameter: expecting a boolean.");
+                       status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_ERROR;
                        goto end;
                }
 
@@ -98,8 +104,8 @@ bt_self_component_status configure_component(struct fs_sink_comp *fs_sink,
                "ignore-discarded-events");
        if (value) {
                if (!bt_value_is_bool(value)) {
-                       BT_LOGE_STR("`ignore-discarded-events` parameter: expecting a boolean.");
-                       status = BT_SELF_COMPONENT_STATUS_ERROR;
+                       BT_COMP_LOGE_STR("`ignore-discarded-events` parameter: expecting a boolean.");
+                       status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_ERROR;
                        goto end;
                }
 
@@ -111,8 +117,8 @@ bt_self_component_status configure_component(struct fs_sink_comp *fs_sink,
                "ignore-discarded-packets");
        if (value) {
                if (!bt_value_is_bool(value)) {
-                       BT_LOGE_STR("`ignore-discarded-packets` parameter: expecting a boolean.");
-                       status = BT_SELF_COMPONENT_STATUS_ERROR;
+                       BT_COMP_LOGE_STR("`ignore-discarded-packets` parameter: expecting a boolean.");
+                       status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_ERROR;
                        goto end;
                }
 
@@ -124,8 +130,8 @@ bt_self_component_status configure_component(struct fs_sink_comp *fs_sink,
                "quiet");
        if (value) {
                if (!bt_value_is_bool(value)) {
-                       BT_LOGE_STR("`quiet` parameter: expecting a boolean.");
-                       status = BT_SELF_COMPONENT_STATUS_ERROR;
+                       BT_COMP_LOGE_STR("`quiet` parameter: expecting a boolean.");
+                       status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_ERROR;
                        goto end;
                }
 
@@ -162,24 +168,32 @@ end:
 }
 
 BT_HIDDEN
-bt_self_component_status ctf_fs_sink_init(
-               bt_self_component_sink *self_comp, const bt_value *params,
+bt_component_class_init_method_status ctf_fs_sink_init(
+               bt_self_component_sink *self_comp_sink, const bt_value *params,
                void *init_method_data)
 {
-       bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK;
+       bt_component_class_init_method_status status =
+               BT_COMPONENT_CLASS_INIT_METHOD_STATUS_OK;
+       bt_self_component_add_port_status add_port_status;
        struct fs_sink_comp *fs_sink = NULL;
+       bt_self_component *self_comp =
+               bt_self_component_sink_as_self_component(self_comp_sink);
+       bt_logging_level log_level = bt_component_get_logging_level(
+               bt_self_component_as_component(self_comp));
 
        fs_sink = g_new0(struct fs_sink_comp, 1);
        if (!fs_sink) {
-               BT_LOGE_STR("Failed to allocate one CTF FS sink structure.");
-               status = BT_SELF_COMPONENT_STATUS_NOMEM;
+               BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR, log_level, self_comp,
+                       "Failed to allocate one CTF FS sink structure.");
+               status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_MEMORY_ERROR;
                goto end;
        }
 
-       fs_sink->output_dir_path = g_string_new(NULL);
+       fs_sink->log_level = log_level;
        fs_sink->self_comp = self_comp;
+       fs_sink->output_dir_path = g_string_new(NULL);
        status = configure_component(fs_sink, params);
-       if (status != BT_SELF_COMPONENT_STATUS_OK) {
+       if (status != BT_COMPONENT_CLASS_INIT_METHOD_STATUS_OK) {
                /* configure_component() logs errors */
                goto end;
        }
@@ -187,14 +201,14 @@ bt_self_component_status ctf_fs_sink_init(
        if (fs_sink->assume_single_trace &&
                        g_file_test(fs_sink->output_dir_path->str,
                                G_FILE_TEST_EXISTS)) {
-               BT_LOGE("Single trace mode, but output path exists: "
+               BT_COMP_LOGE("Single trace mode, but output path exists: "
                        "output-path=\"%s\"", fs_sink->output_dir_path->str);
-               status = BT_SELF_COMPONENT_STATUS_ERROR;
+               status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_ERROR;
                goto end;
        }
 
        status = ensure_output_dir_exists(fs_sink);
-       if (status != BT_SELF_COMPONENT_STATUS_OK) {
+       if (status != BT_COMPONENT_CLASS_INIT_METHOD_STATUS_OK) {
                /* ensure_output_dir_exists() logs errors */
                goto end;
        }
@@ -202,22 +216,28 @@ bt_self_component_status ctf_fs_sink_init(
        fs_sink->traces = g_hash_table_new_full(g_direct_hash, g_direct_equal,
                NULL, (GDestroyNotify) fs_sink_trace_destroy);
        if (!fs_sink->traces) {
-               BT_LOGE_STR("Failed to allocate one GHashTable.");
-               status = BT_SELF_COMPONENT_STATUS_NOMEM;
+               BT_COMP_LOGE_STR("Failed to allocate one GHashTable.");
+               status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_MEMORY_ERROR;
                goto end;
        }
 
-       status = bt_self_component_sink_add_input_port(self_comp, in_port_name,
-               NULL, NULL);
-       if (status != BT_SELF_COMPONENT_STATUS_OK) {
+       add_port_status = bt_self_component_sink_add_input_port(
+               self_comp_sink, in_port_name, NULL, NULL);
+       switch (add_port_status) {
+       case BT_SELF_COMPONENT_ADD_PORT_STATUS_ERROR:
+               status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_ERROR;
                goto end;
+       case BT_SELF_COMPONENT_ADD_PORT_STATUS_MEMORY_ERROR:
+               status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_MEMORY_ERROR;
+               goto end;
+       default:
+               break;
        }
 
-       bt_self_component_set_data(
-               bt_self_component_sink_as_self_component(self_comp), fs_sink);
+       bt_self_component_set_data(self_comp, fs_sink);
 
 end:
-       if (status != BT_SELF_COMPONENT_STATUS_OK) {
+       if (status != BT_COMPONENT_CLASS_INIT_METHOD_STATUS_OK) {
                destroy_fs_sink_comp(fs_sink);
        }
 
@@ -236,7 +256,7 @@ struct fs_sink_stream *borrow_stream(struct fs_sink_comp *fs_sink,
        if (G_UNLIKELY(!trace)) {
                if (fs_sink->assume_single_trace &&
                                g_hash_table_size(fs_sink->traces) > 0) {
-                       BT_LOGE("Single trace mode, but getting more than one trace: "
+                       BT_COMP_LOGE("Single trace mode, but getting more than one trace: "
                                "stream-name=\"%s\"",
                                bt_stream_get_name(ir_stream));
                        goto end;
@@ -261,11 +281,12 @@ end:
 }
 
 static inline
-bt_self_component_status handle_event_msg(struct fs_sink_comp *fs_sink,
-               const bt_message *msg)
+bt_component_class_sink_consume_method_status handle_event_msg(
+               struct fs_sink_comp *fs_sink, const bt_message *msg)
 {
        int ret;
-       bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK;
+       bt_component_class_sink_consume_method_status status =
+               BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK;
        const bt_event *ir_event = bt_message_event_borrow_event_const(msg);
        const bt_stream *ir_stream = bt_event_borrow_stream_const(ir_event);
        struct fs_sink_stream *stream;
@@ -274,14 +295,14 @@ bt_self_component_status handle_event_msg(struct fs_sink_comp *fs_sink,
 
        stream = borrow_stream(fs_sink, ir_stream);
        if (G_UNLIKELY(!stream)) {
-               status = BT_SELF_COMPONENT_STATUS_ERROR;
+               status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR;
                goto end;
        }
 
-       ret = try_translate_event_class_trace_ir_to_ctf_ir(stream->sc,
-               bt_event_borrow_class_const(ir_event), &ec);
+       ret = try_translate_event_class_trace_ir_to_ctf_ir(fs_sink,
+               stream->sc, bt_event_borrow_class_const(ir_event), &ec);
        if (ret) {
-               status = BT_SELF_COMPONENT_STATUS_ERROR;
+               status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR;
                goto end;
        }
 
@@ -292,9 +313,45 @@ bt_self_component_status handle_event_msg(struct fs_sink_comp *fs_sink,
                        msg);
        }
 
+       /*
+        * If this event's stream does not support packets, then we
+        * lazily create artificial packets.
+        *
+        * The size of an artificial packet is arbitrarily at least
+        * 4 MiB (it usually is greater because we close it when
+        * comes the time to write a new event and the packet's content
+        * size is >= 4 MiB), except the last one which can be smaller.
+        */
+       if (G_UNLIKELY(!stream->sc->has_packets)) {
+               if (stream->packet_state.is_open &&
+                               bt_ctfser_get_offset_in_current_packet_bits(&stream->ctfser) / 8 >=
+                               4 * 1024 * 1024) {
+                       /*
+                        * Stream's current packet is larger than 4 MiB:
+                        * close it. A new packet will be opened just
+                        * below.
+                        */
+                       ret = fs_sink_stream_close_packet(stream, NULL);
+                       if (ret) {
+                               status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR;
+                               goto end;
+                       }
+               }
+
+               if (!stream->packet_state.is_open) {
+                       /* Stream's packet is not currently opened: open it */
+                       ret = fs_sink_stream_open_packet(stream, NULL, NULL);
+                       if (ret) {
+                               status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR;
+                               goto end;
+                       }
+               }
+       }
+
+       BT_ASSERT(stream->packet_state.is_open);
        ret = fs_sink_stream_write_event(stream, cs, ir_event, ec);
        if (G_UNLIKELY(ret)) {
-               status = BT_SELF_COMPONENT_STATUS_ERROR;
+               status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR;
                goto end;
        }
 
@@ -303,11 +360,12 @@ end:
 }
 
 static inline
-bt_self_component_status handle_packet_beginning_msg(
+bt_component_class_sink_consume_method_status handle_packet_beginning_msg(
                struct fs_sink_comp *fs_sink, const bt_message *msg)
 {
        int ret;
-       bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK;
+       bt_component_class_sink_consume_method_status status =
+               BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK;
        const bt_packet *ir_packet =
                bt_message_packet_beginning_borrow_packet_const(msg);
        const bt_stream *ir_stream = bt_packet_borrow_stream_const(ir_packet);
@@ -316,7 +374,7 @@ bt_self_component_status handle_packet_beginning_msg(
 
        stream = borrow_stream(fs_sink, ir_stream);
        if (G_UNLIKELY(!stream)) {
-               status = BT_SELF_COMPONENT_STATUS_ERROR;
+               status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR;
                goto end;
        }
 
@@ -367,7 +425,7 @@ bt_self_component_status handle_packet_beginning_msg(
 
                if (stream->discarded_events_state.beginning_cs !=
                                expected_cs) {
-                       BT_LOGE("Incompatible discarded events message: "
+                       BT_COMP_LOGE("Incompatible discarded events message: "
                                "unexpected beginning time: "
                                "beginning-cs-val=%" PRIu64 ", "
                                "expected-beginning-cs-val=%" PRIu64 ", "
@@ -380,7 +438,7 @@ bt_self_component_status handle_packet_beginning_msg(
                                bt_trace_get_name(
                                        bt_stream_borrow_trace_const(ir_stream)),
                                stream->trace->path->str, stream->file_name->str);
-                       status = BT_SELF_COMPONENT_STATUS_ERROR;
+                       status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR;
                        goto end;
                }
        }
@@ -417,7 +475,7 @@ bt_self_component_status handle_packet_beginning_msg(
                 * this case.
                 */
                if (stream->prev_packet_state.end_cs == UINT64_C(-1)) {
-                       BT_LOGE("Incompatible discarded packets message "
+                       BT_COMP_LOGE("Incompatible discarded packets message "
                                "occuring before the stream's first packet: "
                                "stream-id=%" PRIu64 ", stream-name=\"%s\", "
                                "trace-name=\"%s\", path=\"%s/%s\"",
@@ -426,13 +484,13 @@ bt_self_component_status handle_packet_beginning_msg(
                                bt_trace_get_name(
                                        bt_stream_borrow_trace_const(ir_stream)),
                                stream->trace->path->str, stream->file_name->str);
-                       status = BT_SELF_COMPONENT_STATUS_ERROR;
+                       status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR;
                        goto end;
                }
 
                if (stream->discarded_packets_state.beginning_cs !=
                                stream->prev_packet_state.end_cs) {
-                       BT_LOGE("Incompatible discarded packets message: "
+                       BT_COMP_LOGE("Incompatible discarded packets message: "
                                "unexpected beginning time: "
                                "beginning-cs-val=%" PRIu64 ", "
                                "expected-beginning-cs-val=%" PRIu64 ", "
@@ -445,7 +503,7 @@ bt_self_component_status handle_packet_beginning_msg(
                                bt_trace_get_name(
                                        bt_stream_borrow_trace_const(ir_stream)),
                                stream->trace->path->str, stream->file_name->str);
-                       status = BT_SELF_COMPONENT_STATUS_ERROR;
+                       status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR;
                        goto end;
                }
 
@@ -453,7 +511,7 @@ bt_self_component_status handle_packet_beginning_msg(
 
                if (stream->discarded_packets_state.end_cs !=
                                expected_end_cs) {
-                       BT_LOGE("Incompatible discarded packets message: "
+                       BT_COMP_LOGE("Incompatible discarded packets message: "
                                "unexpected end time: "
                                "end-cs-val=%" PRIu64 ", "
                                "expected-end-cs-val=%" PRIu64 ", "
@@ -466,7 +524,7 @@ bt_self_component_status handle_packet_beginning_msg(
                                bt_trace_get_name(
                                        bt_stream_borrow_trace_const(ir_stream)),
                                stream->trace->path->str, stream->file_name->str);
-                       status = BT_SELF_COMPONENT_STATUS_ERROR;
+                       status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR;
                        goto end;
                }
        }
@@ -481,7 +539,7 @@ bt_self_component_status handle_packet_beginning_msg(
 
        ret = fs_sink_stream_open_packet(stream, cs, ir_packet);
        if (ret) {
-               status = BT_SELF_COMPONENT_STATUS_ERROR;
+               status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR;
                goto end;
        }
 
@@ -490,11 +548,12 @@ end:
 }
 
 static inline
-bt_self_component_status handle_packet_end_msg(
+bt_component_class_sink_consume_method_status handle_packet_end_msg(
                struct fs_sink_comp *fs_sink, const bt_message *msg)
 {
        int ret;
-       bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK;
+       bt_component_class_sink_consume_method_status status =
+               BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK;
        const bt_packet *ir_packet =
                bt_message_packet_end_borrow_packet_const(msg);
        const bt_stream *ir_stream = bt_packet_borrow_stream_const(ir_packet);
@@ -503,7 +562,7 @@ bt_self_component_status handle_packet_end_msg(
 
        stream = borrow_stream(fs_sink, ir_stream);
        if (G_UNLIKELY(!stream)) {
-               status = BT_SELF_COMPONENT_STATUS_ERROR;
+               status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR;
                goto end;
        }
 
@@ -542,7 +601,7 @@ bt_self_component_status handle_packet_end_msg(
                expected_cs = bt_clock_snapshot_get_value(cs);
 
                if (stream->discarded_events_state.end_cs != expected_cs) {
-                       BT_LOGE("Incompatible discarded events message: "
+                       BT_COMP_LOGE("Incompatible discarded events message: "
                                "unexpected end time: "
                                "end-cs-val=%" PRIu64 ", "
                                "expected-end-cs-val=%" PRIu64 ", "
@@ -555,14 +614,14 @@ bt_self_component_status handle_packet_end_msg(
                                bt_trace_get_name(
                                        bt_stream_borrow_trace_const(ir_stream)),
                                stream->trace->path->str, stream->file_name->str);
-                       status = BT_SELF_COMPONENT_STATUS_ERROR;
+                       status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR;
                        goto end;
                }
        }
 
        ret = fs_sink_stream_close_packet(stream, cs);
        if (ret) {
-               status = BT_SELF_COMPONENT_STATUS_ERROR;
+               status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR;
                goto end;
        }
 
@@ -579,10 +638,11 @@ end:
 }
 
 static inline
-bt_self_component_status handle_stream_beginning_msg(
+bt_component_class_sink_consume_method_status handle_stream_beginning_msg(
                struct fs_sink_comp *fs_sink, const bt_message *msg)
 {
-       bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK;
+       bt_component_class_sink_consume_method_status status =
+               BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK;
        const bt_stream *ir_stream =
                bt_message_stream_beginning_borrow_stream_const(msg);
        const bt_stream_class *ir_sc =
@@ -592,6 +652,29 @@ bt_self_component_status handle_stream_beginning_msg(
                bt_stream_class_packets_have_beginning_default_clock_snapshot(ir_sc) &&
                bt_stream_class_packets_have_end_default_clock_snapshot(ir_sc);
 
+       /*
+        * Not supported: discarded events or discarded packets support
+        * without packets support. Packets are the way to know where
+        * discarded events/packets occured in CTF 1.8.
+        */
+       if (!bt_stream_class_supports_packets(ir_sc)) {
+               BT_ASSERT(!bt_stream_class_supports_discarded_packets(ir_sc));
+
+               if (!fs_sink->ignore_discarded_events &&
+                               bt_stream_class_supports_discarded_events(ir_sc)) {
+                       BT_COMP_LOGE("Unsupported stream: "
+                               "stream does not support packets, "
+                               "but supports discarded events: "
+                               "stream-addr=%p, "
+                               "stream-id=%" PRIu64 ", "
+                               "stream-name=\"%s\"",
+                               ir_stream, bt_stream_get_id(ir_stream),
+                               bt_stream_get_name(ir_stream));
+                       status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR;
+                       goto end;
+               }
+       }
+
        /*
         * Not supported: discarded events with default clock snapshots,
         * but packet beginning/end without default clock snapshot.
@@ -599,7 +682,7 @@ bt_self_component_status handle_stream_beginning_msg(
        if (!fs_sink->ignore_discarded_events &&
                        bt_stream_class_discarded_events_have_default_clock_snapshots(ir_sc) &&
                        !packets_have_beginning_end_cs) {
-               BT_LOGE("Unsupported stream: discarded events have "
+               BT_COMP_LOGE("Unsupported stream: discarded events have "
                        "default clock snapshots, but packets have no "
                        "beginning and/or end default clock snapshots: "
                        "stream-addr=%p, "
@@ -607,7 +690,7 @@ bt_self_component_status handle_stream_beginning_msg(
                        "stream-name=\"%s\"",
                        ir_stream, bt_stream_get_id(ir_stream),
                        bt_stream_get_name(ir_stream));
-               status = BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR;
+               status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR;
                goto end;
        }
 
@@ -619,7 +702,7 @@ bt_self_component_status handle_stream_beginning_msg(
        if (!fs_sink->ignore_discarded_packets &&
                        bt_stream_class_discarded_packets_have_default_clock_snapshots(ir_sc) &&
                        !packets_have_beginning_end_cs) {
-               BT_LOGE("Unsupported stream: discarded packets have "
+               BT_COMP_LOGE("Unsupported stream: discarded packets have "
                        "default clock snapshots, but packets have no "
                        "beginning and/or end default clock snapshots: "
                        "stream-addr=%p, "
@@ -627,17 +710,17 @@ bt_self_component_status handle_stream_beginning_msg(
                        "stream-name=\"%s\"",
                        ir_stream, bt_stream_get_id(ir_stream),
                        bt_stream_get_name(ir_stream));
-               status = BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR;
+               status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR;
                goto end;
        }
 
        stream = borrow_stream(fs_sink, ir_stream);
        if (!stream) {
-               status = BT_SELF_COMPONENT_STATUS_ERROR;
+               status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR;
                goto end;
        }
 
-       BT_LOGI("Created new, empty stream file: "
+       BT_COMP_LOGI("Created new, empty stream file: "
                "stream-id=%" PRIu64 ", stream-name=\"%s\", "
                "trace-name=\"%s\", path=\"%s/%s\"",
                bt_stream_get_id(ir_stream), bt_stream_get_name(ir_stream),
@@ -649,21 +732,33 @@ end:
 }
 
 static inline
-bt_self_component_status handle_stream_end_msg(struct fs_sink_comp *fs_sink,
-               const bt_message *msg)
+bt_component_class_sink_consume_method_status handle_stream_end_msg(
+               struct fs_sink_comp *fs_sink, const bt_message *msg)
 {
-       bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK;
+       bt_component_class_sink_consume_method_status status =
+               BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK;
        const bt_stream *ir_stream =
                bt_message_stream_end_borrow_stream_const(msg);
        struct fs_sink_stream *stream;
 
        stream = borrow_stream(fs_sink, ir_stream);
        if (!stream) {
-               status = BT_SELF_COMPONENT_STATUS_ERROR;
+               status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR;
                goto end;
        }
 
-       BT_LOGI("Closing stream file: "
+       if (G_UNLIKELY(!stream->sc->has_packets &&
+                       stream->packet_state.is_open)) {
+               /* Close stream's current artificial packet */
+               int ret = fs_sink_stream_close_packet(stream, NULL);
+
+               if (ret) {
+                       status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR;
+                       goto end;
+               }
+       }
+
+       BT_COMP_LOGI("Closing stream file: "
                "stream-id=%" PRIu64 ", stream-name=\"%s\", "
                "trace-name=\"%s\", path=\"%s/%s\"",
                bt_stream_get_id(ir_stream), bt_stream_get_name(ir_stream),
@@ -681,10 +776,11 @@ end:
 }
 
 static inline
-bt_self_component_status handle_discarded_events_msg(
+bt_component_class_sink_consume_method_status handle_discarded_events_msg(
                struct fs_sink_comp *fs_sink, const bt_message *msg)
 {
-       bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK;
+       bt_component_class_sink_consume_method_status status =
+               BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK;
        const bt_stream *ir_stream =
                bt_message_discarded_events_borrow_stream_const(msg);
        struct fs_sink_stream *stream;
@@ -694,12 +790,12 @@ bt_self_component_status handle_discarded_events_msg(
 
        stream = borrow_stream(fs_sink, ir_stream);
        if (!stream) {
-               status = BT_SELF_COMPONENT_STATUS_ERROR;
+               status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR;
                goto end;
        }
 
        if (fs_sink->ignore_discarded_events) {
-               BT_LOGI("Ignoring discarded events message: "
+               BT_COMP_LOGI("Ignoring discarded events message: "
                        "stream-id=%" PRIu64 ", stream-name=\"%s\", "
                        "trace-name=\"%s\", path=\"%s/%s\"",
                        bt_stream_get_id(ir_stream),
@@ -711,7 +807,7 @@ bt_self_component_status handle_discarded_events_msg(
        }
 
        if (stream->discarded_events_state.in_range) {
-               BT_LOGE("Unsupported contiguous discarded events message: "
+               BT_COMP_LOGE("Unsupported contiguous discarded events message: "
                        "stream-id=%" PRIu64 ", stream-name=\"%s\", "
                        "trace-name=\"%s\", path=\"%s/%s\"",
                        bt_stream_get_id(ir_stream),
@@ -719,7 +815,7 @@ bt_self_component_status handle_discarded_events_msg(
                        bt_trace_get_name(
                                bt_stream_borrow_trace_const(ir_stream)),
                        stream->trace->path->str, stream->file_name->str);
-               status = BT_SELF_COMPONENT_STATUS_ERROR;
+               status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR;
                goto end;
        }
 
@@ -733,7 +829,7 @@ bt_self_component_status handle_discarded_events_msg(
         */
        if (stream->packet_state.is_open &&
                        stream->sc->discarded_events_has_ts) {
-               BT_LOGE("Unsupported discarded events message with "
+               BT_COMP_LOGE("Unsupported discarded events message with "
                        "default clock snapshots occuring within a packet: "
                        "stream-id=%" PRIu64 ", stream-name=\"%s\", "
                        "trace-name=\"%s\", path=\"%s/%s\"",
@@ -742,7 +838,7 @@ bt_self_component_status handle_discarded_events_msg(
                        bt_trace_get_name(
                                bt_stream_borrow_trace_const(ir_stream)),
                        stream->trace->path->str, stream->file_name->str);
-               status = BT_SELF_COMPONENT_STATUS_ERROR;
+               status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR;
                goto end;
        }
 
@@ -788,10 +884,11 @@ end:
 }
 
 static inline
-bt_self_component_status handle_discarded_packets_msg(
+bt_component_class_sink_consume_method_status handle_discarded_packets_msg(
                struct fs_sink_comp *fs_sink, const bt_message *msg)
 {
-       bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK;
+       bt_component_class_sink_consume_method_status status =
+               BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK;
        const bt_stream *ir_stream =
                bt_message_discarded_packets_borrow_stream_const(msg);
        struct fs_sink_stream *stream;
@@ -801,12 +898,12 @@ bt_self_component_status handle_discarded_packets_msg(
 
        stream = borrow_stream(fs_sink, ir_stream);
        if (!stream) {
-               status = BT_SELF_COMPONENT_STATUS_ERROR;
+               status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR;
                goto end;
        }
 
        if (fs_sink->ignore_discarded_packets) {
-               BT_LOGI("Ignoring discarded packets message: "
+               BT_COMP_LOGI("Ignoring discarded packets message: "
                        "stream-id=%" PRIu64 ", stream-name=\"%s\", "
                        "trace-name=\"%s\", path=\"%s/%s\"",
                        bt_stream_get_id(ir_stream),
@@ -818,7 +915,7 @@ bt_self_component_status handle_discarded_packets_msg(
        }
 
        if (stream->discarded_packets_state.in_range) {
-               BT_LOGE("Unsupported contiguous discarded packets message: "
+               BT_COMP_LOGE("Unsupported contiguous discarded packets message: "
                        "stream-id=%" PRIu64 ", stream-name=\"%s\", "
                        "trace-name=\"%s\", path=\"%s/%s\"",
                        bt_stream_get_id(ir_stream),
@@ -826,7 +923,7 @@ bt_self_component_status handle_discarded_packets_msg(
                        bt_trace_get_name(
                                bt_stream_borrow_trace_const(ir_stream)),
                        stream->trace->path->str, stream->file_name->str);
-               status = BT_SELF_COMPONENT_STATUS_ERROR;
+               status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR;
                goto end;
        }
 
@@ -888,11 +985,13 @@ void put_messages(bt_message_array_const msgs, uint64_t count)
 }
 
 BT_HIDDEN
-bt_self_component_status ctf_fs_sink_consume(bt_self_component_sink *self_comp)
+bt_component_class_sink_consume_method_status ctf_fs_sink_consume(
+               bt_self_component_sink *self_comp)
 {
-       bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK;
+       bt_component_class_sink_consume_method_status status =
+               BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK;
        struct fs_sink_comp *fs_sink;
-       bt_message_iterator_status it_status;
+       bt_message_iterator_next_status next_status;
        uint64_t msg_count = 0;
        bt_message_array_const msgs;
 
@@ -902,15 +1001,15 @@ bt_self_component_status ctf_fs_sink_consume(bt_self_component_sink *self_comp)
        BT_ASSERT(fs_sink->upstream_iter);
 
        /* Consume messages */
-       it_status = bt_self_component_port_input_message_iterator_next(
+       next_status = bt_self_component_port_input_message_iterator_next(
                fs_sink->upstream_iter, &msgs, &msg_count);
-       if (it_status < 0) {
-               status = BT_SELF_COMPONENT_STATUS_ERROR;
+       if (next_status < 0) {
+               status = (int) next_status;
                goto end;
        }
 
-       switch (it_status) {
-       case BT_MESSAGE_ITERATOR_STATUS_OK:
+       switch (next_status) {
+       case BT_MESSAGE_ITERATOR_NEXT_STATUS_OK:
        {
                uint64_t i;
 
@@ -933,7 +1032,7 @@ bt_self_component_status ctf_fs_sink_consume(bt_self_component_sink *self_comp)
                                break;
                        case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY:
                                /* Ignore */
-                               BT_LOGD_STR("Ignoring message iterator inactivity message.");
+                               BT_COMP_LOGD_STR("Ignoring message iterator inactivity message.");
                                break;
                        case BT_MESSAGE_TYPE_STREAM_BEGINNING:
                                status = handle_stream_beginning_msg(
@@ -943,11 +1042,6 @@ bt_self_component_status ctf_fs_sink_consume(bt_self_component_sink *self_comp)
                                status = handle_stream_end_msg(
                                        fs_sink, msg);
                                break;
-                       case BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING:
-                       case BT_MESSAGE_TYPE_STREAM_ACTIVITY_END:
-                               /* Not supported by CTF 1.8 */
-                               BT_LOGD_STR("Ignoring stream activity message.");
-                               break;
                        case BT_MESSAGE_TYPE_DISCARDED_EVENTS:
                                status = handle_discarded_events_msg(
                                        fs_sink, msg);
@@ -962,8 +1056,8 @@ bt_self_component_status ctf_fs_sink_consume(bt_self_component_sink *self_comp)
 
                        BT_MESSAGE_PUT_REF_AND_RESET(msgs[i]);
 
-                       if (status != BT_SELF_COMPONENT_STATUS_OK) {
-                               BT_LOGE("Failed to handle message: "
+                       if (status != BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK) {
+                               BT_COMP_LOGE("Failed to handle message: "
                                        "generated CTF traces could be incomplete: "
                                        "output-dir-path=\"%s\"",
                                        fs_sink->output_dir_path->str);
@@ -973,18 +1067,18 @@ bt_self_component_status ctf_fs_sink_consume(bt_self_component_sink *self_comp)
 
                break;
        }
-       case BT_MESSAGE_ITERATOR_STATUS_AGAIN:
-               status = BT_SELF_COMPONENT_STATUS_AGAIN;
+       case BT_MESSAGE_ITERATOR_NEXT_STATUS_AGAIN:
+               status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_AGAIN;
                break;
-       case BT_MESSAGE_ITERATOR_STATUS_END:
+       case BT_MESSAGE_ITERATOR_NEXT_STATUS_END:
                /* TODO: Finalize all traces (should already be done?) */
-               status = BT_SELF_COMPONENT_STATUS_END;
+               status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_END;
                break;
-       case BT_MESSAGE_ITERATOR_STATUS_NOMEM:
-               status = BT_SELF_COMPONENT_STATUS_NOMEM;
+       case BT_MESSAGE_ITERATOR_NEXT_STATUS_MEMORY_ERROR:
+               status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_MEMORY_ERROR;
                break;
-       case BT_MESSAGE_ITERATOR_STATUS_ERROR:
-               status = BT_SELF_COMPONENT_STATUS_NOMEM;
+       case BT_MESSAGE_ITERATOR_NEXT_STATUS_ERROR:
+               status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_MEMORY_ERROR;
                break;
        default:
                break;
@@ -993,7 +1087,7 @@ bt_self_component_status ctf_fs_sink_consume(bt_self_component_sink *self_comp)
        goto end;
 
 error:
-       BT_ASSERT(status != BT_SELF_COMPONENT_STATUS_OK);
+       BT_ASSERT(status != BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK);
        put_messages(msgs, msg_count);
 
 end:
@@ -1001,10 +1095,11 @@ end:
 }
 
 BT_HIDDEN
-bt_self_component_status ctf_fs_sink_graph_is_configured(
+bt_component_class_sink_graph_is_configured_method_status ctf_fs_sink_graph_is_configured(
                bt_self_component_sink *self_comp)
 {
-       bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK;
+       bt_component_class_sink_graph_is_configured_method_status status =
+               BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_OK;
        struct fs_sink_comp *fs_sink = bt_self_component_get_data(
                        bt_self_component_sink_as_self_component(self_comp));
 
@@ -1013,7 +1108,7 @@ bt_self_component_status ctf_fs_sink_graph_is_configured(
                        bt_self_component_sink_borrow_input_port_by_name(
                                self_comp, in_port_name));
        if (!fs_sink->upstream_iter) {
-               status = BT_SELF_COMPONENT_STATUS_NOMEM;
+               status = BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_ERROR;
                goto end;
        }
 
This page took 0.038488 seconds and 4 git commands to generate.