lib: rename include dir to babeltrace2
[babeltrace.git] / plugins / utils / trimmer / trimmer.c
index d9407bfda205e1341f8d3ed4186eab2bf0c30d7f..1227dc50d7616384e01f5789d2bf4c311cbd8310 100644 (file)
 #define BT_LOG_TAG "PLUGIN-UTILS-TRIMMER-FLT"
 #include "logging.h"
 
-#include <babeltrace/compat/utc-internal.h>
-#include <babeltrace/compat/time-internal.h>
-#include <babeltrace/babeltrace.h>
-#include <babeltrace/common-internal.h>
+#include <babeltrace2/compat/utc-internal.h>
+#include <babeltrace2/compat/time-internal.h>
+#include <babeltrace2/babeltrace.h>
+#include <babeltrace2/common-internal.h>
 #include <plugins-common.h>
-#include <babeltrace/assert-internal.h>
+#include <babeltrace2/assert-internal.h>
 #include <stdint.h>
 #include <inttypes.h>
 #include <glib.h>
@@ -620,7 +620,6 @@ int get_msg_ns_from_origin(const bt_message *msg, int64_t *ns_from_origin,
 {
        const bt_clock_class *clock_class = NULL;
        const bt_clock_snapshot *clock_snapshot = NULL;
-       bt_clock_snapshot_state cs_state = BT_CLOCK_SNAPSHOT_STATE_KNOWN;
        bt_message_stream_activity_clock_snapshot_state sa_cs_state;
        int ret = 0;
 
@@ -637,8 +636,8 @@ int get_msg_ns_from_origin(const bt_message *msg, int64_t *ns_from_origin,
                        goto error;
                }
 
-               cs_state = bt_message_event_borrow_default_clock_snapshot_const(
-                       msg, &clock_snapshot);
+               clock_snapshot = bt_message_event_borrow_default_clock_snapshot_const(
+                       msg);
                break;
        case BT_MESSAGE_TYPE_PACKET_BEGINNING:
                clock_class =
@@ -648,8 +647,8 @@ int get_msg_ns_from_origin(const bt_message *msg, int64_t *ns_from_origin,
                        goto error;
                }
 
-               cs_state = bt_message_packet_beginning_borrow_default_clock_snapshot_const(
-                       msg, &clock_snapshot);
+               clock_snapshot = bt_message_packet_beginning_borrow_default_clock_snapshot_const(
+                       msg);
                break;
        case BT_MESSAGE_TYPE_PACKET_END:
                clock_class =
@@ -659,8 +658,8 @@ int get_msg_ns_from_origin(const bt_message *msg, int64_t *ns_from_origin,
                        goto error;
                }
 
-               cs_state = bt_message_packet_end_borrow_default_clock_snapshot_const(
-                       msg, &clock_snapshot);
+               clock_snapshot = bt_message_packet_end_borrow_default_clock_snapshot_const(
+                       msg);
                break;
        case BT_MESSAGE_TYPE_DISCARDED_EVENTS:
                clock_class =
@@ -670,8 +669,8 @@ int get_msg_ns_from_origin(const bt_message *msg, int64_t *ns_from_origin,
                        goto error;
                }
 
-               cs_state = bt_message_discarded_events_borrow_default_beginning_clock_snapshot_const(
-                       msg, &clock_snapshot);
+               clock_snapshot = bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const(
+                       msg);
                break;
        case BT_MESSAGE_TYPE_DISCARDED_PACKETS:
                clock_class =
@@ -681,8 +680,8 @@ int get_msg_ns_from_origin(const bt_message *msg, int64_t *ns_from_origin,
                        goto error;
                }
 
-               cs_state = bt_message_discarded_packets_borrow_default_beginning_clock_snapshot_const(
-                       msg, &clock_snapshot);
+               clock_snapshot = bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const(
+                       msg);
                break;
        case BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING:
                clock_class =
@@ -724,20 +723,14 @@ int get_msg_ns_from_origin(const bt_message *msg, int64_t *ns_from_origin,
 
                break;
        case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY:
-               cs_state =
+               clock_snapshot =
                        bt_message_message_iterator_inactivity_borrow_default_clock_snapshot_const(
-                               msg, &clock_snapshot);
+                               msg);
                break;
        default:
                goto no_clock_snapshot;
        }
 
-       if (unlikely(cs_state != BT_CLOCK_SNAPSHOT_STATE_KNOWN)) {
-               BT_LOGE_STR("Unsupported unknown clock snapshot.");
-               ret = -1;
-               goto end;
-       }
-
        ret = bt_clock_snapshot_get_ns_from_origin(clock_snapshot,
                ns_from_origin);
        if (unlikely(ret)) {
@@ -896,7 +889,7 @@ bt_self_message_iterator_status state_seek_initially(
                if (!bt_self_component_port_input_message_iterator_can_seek_beginning(
                                trimmer_it->upstream_iter)) {
                        BT_LOGE_STR("Cannot make upstream message iterator initially seek its beginning.");
-                       status = BT_SELF_MESSAGE_ITERATOR_STATUS_OK;
+                       status = BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR;
                        goto end;
                }
 
@@ -909,7 +902,7 @@ bt_self_message_iterator_status state_seek_initially(
                        BT_LOGE("Cannot make upstream message iterator initially seek: "
                                "seek-ns-from-origin=%" PRId64,
                                trimmer_it->begin.ns_from_origin);
-                       status = BT_SELF_MESSAGE_ITERATOR_STATUS_OK;
+                       status = BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR;
                        goto end;
                }
 
@@ -1116,15 +1109,16 @@ bt_self_message_iterator_status create_stream_beginning_activity_message(
                const bt_stream *stream,
                const bt_clock_class *clock_class, bt_message **msg)
 {
+       bt_message *local_msg;
        bt_self_message_iterator_status status =
                BT_SELF_MESSAGE_ITERATOR_STATUS_OK;
 
        BT_ASSERT(msg);
        BT_ASSERT(!trimmer_it->begin.is_infinite);
 
-       *msg = bt_message_stream_activity_beginning_create(
+       local_msg = bt_message_stream_activity_beginning_create(
                trimmer_it->self_msg_iter, stream);
-       if (!*msg) {
+       if (!local_msg) {
                status = BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM;
                goto end;
        }
@@ -1137,14 +1131,16 @@ bt_self_message_iterator_status create_stream_beginning_activity_message(
                        trimmer_it->begin.ns_from_origin, &raw_value);
                if (ret) {
                        status = BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR;
-                       bt_message_put_ref(*msg);
+                       bt_message_put_ref(local_msg);
                        goto end;
                }
 
                bt_message_stream_activity_beginning_set_default_clock_snapshot(
-                       *msg, raw_value);
+                       local_msg, raw_value);
        }
 
+       BT_MESSAGE_MOVE_REF(*msg, local_msg);
+
 end:
        return status;
 }
@@ -1428,16 +1424,16 @@ bt_self_message_iterator_status handle_message_with_stream_state(
                         * know there's a default clock and it's always
                         * known.
                         */
-                       (void) bt_message_discarded_events_borrow_default_end_clock_snapshot_const(
-                               msg, &end_cs);
+                       end_cs = bt_message_discarded_events_borrow_end_default_clock_snapshot_const(
+                               msg);
                } else {
                        /*
                         * Safe to ignore the return value because we
                         * know there's a default clock and it's always
                         * known.
                         */
-                       (void) bt_message_discarded_packets_borrow_default_end_clock_snapshot_const(
-                               msg, &end_cs);
+                       end_cs = bt_message_discarded_packets_borrow_end_default_clock_snapshot_const(
+                               msg);
                }
 
                if (bt_clock_snapshot_get_ns_from_origin(end_cs,
@@ -1479,16 +1475,16 @@ bt_self_message_iterator_status handle_message_with_stream_state(
                        }
 
                        if (msg_type == BT_MESSAGE_TYPE_DISCARDED_EVENTS) {
-                               (void) bt_message_discarded_events_borrow_default_beginning_clock_snapshot_const(
-                                       msg, &begin_cs);
+                               begin_cs = bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const(
+                                       msg);
                                new_msg = bt_message_discarded_events_create_with_default_clock_snapshots(
                                        trimmer_it->self_msg_iter,
                                        sstate->stream,
                                        bt_clock_snapshot_get_value(begin_cs),
                                        end_raw_value);
                        } else {
-                               (void) bt_message_discarded_packets_borrow_default_beginning_clock_snapshot_const(
-                                       msg, &begin_cs);
+                               begin_cs = bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const(
+                                       msg);
                                new_msg = bt_message_discarded_packets_create_with_default_clock_snapshots(
                                        trimmer_it->self_msg_iter,
                                        sstate->stream,
@@ -1737,9 +1733,56 @@ bt_self_message_iterator_status handle_message(
                                goto end;
                        }
 
-                       if (!bt_stream_class_default_clock_is_always_known(sc)) {
-                               BT_LOGE("Unsupported stream: clock does not "
-                                       "always have a known value: "
+                       /*
+                        * Temporary: make sure packet beginning, packet
+                        * end, discarded events, and discarded packets
+                        * messages have default clock snapshots until
+                        * the support for not having them is
+                        * implemented.
+                        */
+                       if (!bt_stream_class_packets_have_beginning_default_clock_snapshot(
+                                       sc)) {
+                               BT_LOGE("Unsupported stream: packets have "
+                                       "no beginning clock snapshot: "
+                                       "stream-addr=%p, "
+                                       "stream-id=%" PRIu64 ", "
+                                       "stream-name=\"%s\"",
+                                       stream, bt_stream_get_id(stream),
+                                       bt_stream_get_name(stream));
+                               status = BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR;
+                               goto end;
+                       }
+
+                       if (!bt_stream_class_packets_have_end_default_clock_snapshot(
+                                       sc)) {
+                               BT_LOGE("Unsupported stream: packets have "
+                                       "no end clock snapshot: "
+                                       "stream-addr=%p, "
+                                       "stream-id=%" PRIu64 ", "
+                                       "stream-name=\"%s\"",
+                                       stream, bt_stream_get_id(stream),
+                                       bt_stream_get_name(stream));
+                               status = BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR;
+                               goto end;
+                       }
+
+                       if (bt_stream_class_supports_discarded_events(sc) &&
+                                       !bt_stream_class_discarded_events_have_default_clock_snapshots(sc)) {
+                               BT_LOGE("Unsupported stream: discarded events "
+                                       "have no clock snapshots: "
+                                       "stream-addr=%p, "
+                                       "stream-id=%" PRIu64 ", "
+                                       "stream-name=\"%s\"",
+                                       stream, bt_stream_get_id(stream),
+                                       bt_stream_get_name(stream));
+                               status = BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR;
+                               goto end;
+                       }
+
+                       if (bt_stream_class_supports_discarded_packets(sc) &&
+                                       !bt_stream_class_discarded_packets_have_default_clock_snapshots(sc)) {
+                               BT_LOGE("Unsupported stream: discarded packets "
+                                       "have no clock snapshots: "
                                        "stream-addr=%p, "
                                        "stream-id=%" PRIu64 ", "
                                        "stream-name=\"%s\"",
This page took 0.02764 seconds and 4 git commands to generate.