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/component-class-dev.hpp"
14 #include "cpp-common/bt2/self-message-iterator-configuration.hpp"
15 #include "cpp-common/bt2c/prio-heap.hpp"
17 #include "clock-correlation-validator/clock-correlation-validator.hpp"
18 #include "upstream-msg-iter.hpp"
24 class MsgIter final : public bt2::UserMessageIterator<MsgIter, Comp>
26 friend bt2::UserMessageIterator<MsgIter, Comp>;
29 /* Comparator for `_mHeap` with its own logger */
30 class _HeapComparator final
33 explicit _HeapComparator(const bt2c::Logger& logger);
35 bool operator()(const UpstreamMsgIter *upstreamMsgIterA,
36 const UpstreamMsgIter *upstreamMsgIterB) const noexcept;
39 bt2c::Logger _mLogger;
43 explicit MsgIter(bt2::SelfMessageIterator selfMsgIter,
44 bt2::SelfMessageIteratorConfiguration config,
45 bt2::SelfComponentOutputPort selfPort);
48 bool _canSeekBeginning();
49 void _seekBeginning();
50 void _next(bt2::ConstMessageArray& msgs);
53 * Makes sure `_mUpstreamMsgItersToReload` is empty so that `_mHeap`
54 * is ready for the next message selection.
56 * This may throw whatever UpstreamMsgIter::reload() may throw.
58 void _ensureFullHeap();
61 * Validates the clock class of the received message `msg`, setting
62 * the expectation if this is the first one.
64 * Throws `bt2::Error` on error.
66 void _validateMsgClkCls(bt2::ConstMessage msg);
69 * Container of all the upstream message iterators.
71 * The only purpose of this is to own them; where they are below
72 * indicates their state.
74 std::vector<UpstreamMsgIter::UP> _mUpstreamMsgIters;
77 * Heap of ready-to-use upstream message iterators (pointers to
78 * owned objects in `_mUpstreamMsgIters` above).
80 bt2c::PrioHeap<UpstreamMsgIter *, _HeapComparator> _mHeap;
83 * Current upstream message iterators to reload, on which we must
84 * call reload() before moving them to `_mHeap` or to
85 * `_mEndedUpstreamMsgIters`.
87 * Using `std::vector` instead of some linked list because the
88 * typical scenario is to add a single one and then remove it
91 std::vector<UpstreamMsgIter *> _mUpstreamMsgItersToReload;
93 /* Clock class correlation validator */
94 bt2ccv::ClockCorrelationValidator _mClkCorrValidator;
97 } /* namespace bt2mux */
99 #endif /* BABELTRACE_PLUGINS_UTILS_MUXER_MSG_ITER_HPP */