lib: make packet beginning/end default CS optional
[babeltrace.git] / plugins / ctf / fs-sink / fs-sink.c
index bc8d3fa1338c8a297b46af17c17ebe5e59500345..da3307feac63dc59225ab7ffee4c6065aafc2312 100644 (file)
@@ -288,8 +288,8 @@ bt_self_component_status handle_event_msg(struct fs_sink_comp *fs_sink,
        BT_ASSERT(ec);
 
        if (stream->sc->default_clock_class) {
-               (void) bt_message_event_borrow_default_clock_snapshot_const(
-                       msg, &cs);
+               cs = bt_message_event_borrow_default_clock_snapshot_const(
+                       msg);
        }
 
        ret = fs_sink_stream_write_event(stream, cs, ir_event, ec);
@@ -321,8 +321,8 @@ bt_self_component_status handle_packet_beginning_msg(
        }
 
        if (stream->sc->default_clock_class) {
-               (void) bt_message_packet_beginning_borrow_default_clock_snapshot_const(
-                       msg, &cs);
+               cs = bt_message_packet_beginning_borrow_default_clock_snapshot_const(
+                       msg);
                BT_ASSERT(cs);
        }
 
@@ -457,14 +457,14 @@ bt_self_component_status handle_packet_end_msg(
        }
 
        if (stream->sc->default_clock_class) {
-               (void) bt_message_packet_end_borrow_default_clock_snapshot_const(
-                       msg, &cs);
+               cs = bt_message_packet_end_borrow_default_clock_snapshot_const(
+                       msg);
                BT_ASSERT(cs);
        }
 
        if (stream->sc->default_clock_class) {
-               (void) bt_message_packet_end_borrow_default_clock_snapshot_const(
-                       msg, &cs);
+               cs = bt_message_packet_end_borrow_default_clock_snapshot_const(
+                       msg);
                BT_ASSERT(cs);
        }
 
@@ -516,8 +516,44 @@ bt_self_component_status handle_stream_beginning_msg(
        bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK;
        const bt_stream *ir_stream =
                bt_message_stream_beginning_borrow_stream_const(msg);
+       const bt_stream_class *ir_sc =
+               bt_stream_borrow_class_const(ir_stream);
        struct fs_sink_stream *stream;
 
+       /*
+        * Temporary: if the stream's class has a default clock class,
+        * make sure packet beginning and end messages have default
+        * clock snapshots until the support for not having them is
+        * implemented.
+        */
+       if (bt_stream_class_borrow_default_clock_class_const(ir_sc)) {
+               if (!bt_stream_class_packets_have_default_beginning_clock_snapshot(
+                               ir_sc)) {
+                       BT_LOGE("Unsupported stream: packets have "
+                               "no beginning clock snapshot: "
+                               "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_SELF_MESSAGE_ITERATOR_STATUS_ERROR;
+                       goto end;
+               }
+
+               if (!bt_stream_class_packets_have_default_end_clock_snapshot(
+                               ir_sc)) {
+                       BT_LOGE("Unsupported stream: packets have "
+                               "no end clock snapshot: "
+                               "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_SELF_MESSAGE_ITERATOR_STATUS_ERROR;
+                       goto end;
+               }
+       }
+
        stream = borrow_stream(fs_sink, ir_stream);
        if (!stream) {
                status = BT_SELF_COMPONENT_STATUS_ERROR;
@@ -631,14 +667,13 @@ bt_self_component_status handle_discarded_events_msg(
                 * The clock snapshot values will be validated when
                 * handling the next "packet beginning" message.
                 */
-               (void) bt_message_discarded_events_borrow_default_beginning_clock_snapshot_const(
-                       msg, &cs);
+               cs = bt_message_discarded_events_borrow_default_beginning_clock_snapshot_const(
+                       msg);
                BT_ASSERT(cs);
                stream->discarded_events_state.beginning_cs =
                        bt_clock_snapshot_get_value(cs);
-               cs = NULL;
-               (void) bt_message_discarded_events_borrow_default_end_clock_snapshot_const(
-                       msg, &cs);
+               cs = bt_message_discarded_events_borrow_default_end_clock_snapshot_const(
+                       msg);
                BT_ASSERT(cs);
                stream->discarded_events_state.end_cs =
                        bt_clock_snapshot_get_value(cs);
@@ -722,14 +757,13 @@ bt_self_component_status handle_discarded_packets_msg(
                 * The clock snapshot values will be validated when
                 * handling the next "packet beginning" message.
                 */
-               (void) bt_message_discarded_packets_borrow_default_beginning_clock_snapshot_const(
-                       msg, &cs);
+               cs = bt_message_discarded_packets_borrow_default_beginning_clock_snapshot_const(
+                       msg);
                BT_ASSERT(cs);
                stream->discarded_packets_state.beginning_cs =
                        bt_clock_snapshot_get_value(cs);
-               cs = NULL;
-               (void) bt_message_discarded_packets_borrow_default_end_clock_snapshot_const(
-                       msg, &cs);
+               cs = bt_message_discarded_packets_borrow_default_end_clock_snapshot_const(
+                       msg);
                BT_ASSERT(cs);
                stream->discarded_packets_state.end_cs =
                        bt_clock_snapshot_get_value(cs);
This page took 0.024685 seconds and 4 git commands to generate.