2 * SPDX-License-Identifier: MIT
4 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 * Copyright 2017-2023 Philippe Proulx <pproulx@efficios.com>
8 #ifndef BABELTRACE_PLUGINS_UTILS_MUXER_MSG_ITER_HPP
9 #define BABELTRACE_PLUGINS_UTILS_MUXER_MSG_ITER_HPP
13 #include "cpp-common/bt2/optional-borrowed-object.hpp"
14 #include "cpp-common/bt2/plugin-dev.hpp"
15 #include "cpp-common/bt2c/prio-heap.hpp"
16 #include "cpp-common/bt2c/uuid.hpp"
17 #include "cpp-common/bt2s/optional.hpp"
19 #include "upstream-msg-iter.hpp"
25 class MsgIter final : public bt2::UserMessageIterator<MsgIter, Comp>
27 friend bt2::UserMessageIterator<MsgIter, Comp>;
30 /* Clock class nature expectation */
31 enum class _ClkClsExpectation
36 ORIG_ISNT_UNIX_EPOCH_AND_SPEC_UUID,
37 ORIG_ISNT_UNIX_EPOCH_AND_NO_UUID,
40 /* Comparator for `_mHeap` with its own logger */
41 class _HeapComparator final
44 explicit _HeapComparator(const bt2c::Logger& logger);
46 bool operator()(const UpstreamMsgIter *upstreamMsgIterA,
47 const UpstreamMsgIter *upstreamMsgIterB) const noexcept;
50 bt2c::Logger _mLogger;
54 explicit MsgIter(bt2::SelfMessageIterator selfMsgIter,
55 bt2::SelfMessageIteratorConfiguration config,
56 bt2::SelfComponentOutputPort selfPort);
59 bool _canSeekBeginning();
60 void _seekBeginning();
61 void _next(bt2::ConstMessageArray& msgs);
64 * Makes sure `_mUpstreamMsgItersToReload` is empty so that `_mHeap`
65 * is ready for the next message selection.
67 * This may throw whatever UpstreamMsgIter::reload() may throw.
69 void _ensureFullHeap();
72 * Validates the clock class of the received message `msg`, setting
73 * the expectation if this is the first one.
75 * Throws `bt2::Error` on error.
77 void _validateMsgClkCls(bt2::ConstMessage msg);
80 * Sets the clock class expectation (`_mClkClsExpectation` and
81 * `_mExpectedClkClsUuid`) according to `clkCls`.
83 void _setClkClsExpectation(bt2::OptionalBorrowedObject<bt2::ConstClockClass> clkCls) noexcept;
86 * Checks that `clkCls` meets the current clock class expectation,
87 * throwing if it doesn't.
89 void _makeSureClkClsIsExpected(bt2::ConstMessage msg,
90 bt2::OptionalBorrowedObject<bt2::ConstClockClass> clkCls) const;
93 * Container of all the upstream message iterators.
95 * The only purpose of this is to own them; where they are below
96 * indicates their state.
98 std::vector<UpstreamMsgIter::UP> _mUpstreamMsgIters;
101 * Heap of ready-to-use upstream message iterators (pointers to
102 * owned objects in `_mUpstreamMsgIters` above).
104 bt2c::PrioHeap<UpstreamMsgIter *, _HeapComparator> _mHeap;
107 * Current upstream message iterators to reload, on which we must
108 * call reload() before moving them to `_mHeap` or to
109 * `_mEndedUpstreamMsgIters`.
111 * Using `std::vector` instead of some linked list because the
112 * typical scenario is to add a single one and then remove it
115 std::vector<UpstreamMsgIter *> _mUpstreamMsgItersToReload;
118 * Which kind of clock class to expect from any incoming message.
120 * The very first received message determines this for all the
123 * For `ORIG_ISNT_UNIX_EPOCH_AND_SPEC_UUID`, `*_mExpectedClkClsUuid`
124 * is the expected specific UUID.
126 _ClkClsExpectation _mClkClsExpectation = _ClkClsExpectation::ANY;
127 bt2s::optional<bt2c::Uuid> _mExpectedClkClsUuid;
130 } /* namespace bt2mux */
132 #endif /* BABELTRACE_PLUGINS_UTILS_MUXER_MSG_ITER_HPP */