flt.utils.muxer: use clock correlation validator
[babeltrace.git] / src / plugins / utils / muxer / msg-iter.hpp
CommitLineData
fca1d0f5
PP
1/*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 * Copyright 2017-2023 Philippe Proulx <pproulx@efficios.com>
6 */
7
8#ifndef BABELTRACE_PLUGINS_UTILS_MUXER_MSG_ITER_HPP
9#define BABELTRACE_PLUGINS_UTILS_MUXER_MSG_ITER_HPP
10
11#include <vector>
12
212313d9 13#include "cpp-common/bt2/component-class-dev.hpp"
22309699 14#include "cpp-common/bt2/self-message-iterator-configuration.hpp"
fca1d0f5 15#include "cpp-common/bt2c/prio-heap.hpp"
fca1d0f5 16
df8863ad 17#include "clock-correlation-validator/clock-correlation-validator.hpp"
fca1d0f5
PP
18#include "upstream-msg-iter.hpp"
19
20namespace bt2mux {
21
22class Comp;
23
24class MsgIter final : public bt2::UserMessageIterator<MsgIter, Comp>
25{
26 friend bt2::UserMessageIterator<MsgIter, Comp>;
27
28private:
fca1d0f5
PP
29 /* Comparator for `_mHeap` with its own logger */
30 class _HeapComparator final
31 {
32 public:
33 explicit _HeapComparator(const bt2c::Logger& logger);
34
35 bool operator()(const UpstreamMsgIter *upstreamMsgIterA,
36 const UpstreamMsgIter *upstreamMsgIterB) const noexcept;
37
38 private:
39 bt2c::Logger _mLogger;
40 };
41
42public:
43 explicit MsgIter(bt2::SelfMessageIterator selfMsgIter,
44 bt2::SelfMessageIteratorConfiguration config,
45 bt2::SelfComponentOutputPort selfPort);
46
47private:
48 bool _canSeekBeginning();
49 void _seekBeginning();
50 void _next(bt2::ConstMessageArray& msgs);
51
52 /*
53 * Makes sure `_mUpstreamMsgItersToReload` is empty so that `_mHeap`
54 * is ready for the next message selection.
55 *
56 * This may throw whatever UpstreamMsgIter::reload() may throw.
57 */
58 void _ensureFullHeap();
59
60 /*
61 * Validates the clock class of the received message `msg`, setting
62 * the expectation if this is the first one.
63 *
64 * Throws `bt2::Error` on error.
65 */
66 void _validateMsgClkCls(bt2::ConstMessage msg);
67
fca1d0f5
PP
68 /*
69 * Container of all the upstream message iterators.
70 *
71 * The only purpose of this is to own them; where they are below
72 * indicates their state.
73 */
74 std::vector<UpstreamMsgIter::UP> _mUpstreamMsgIters;
75
76 /*
77 * Heap of ready-to-use upstream message iterators (pointers to
78 * owned objects in `_mUpstreamMsgIters` above).
79 */
80 bt2c::PrioHeap<UpstreamMsgIter *, _HeapComparator> _mHeap;
81
82 /*
83 * Current upstream message iterators to reload, on which we must
84 * call reload() before moving them to `_mHeap` or to
85 * `_mEndedUpstreamMsgIters`.
86 *
87 * Using `std::vector` instead of some linked list because the
88 * typical scenario is to add a single one and then remove it
89 * shortly after.
90 */
91 std::vector<UpstreamMsgIter *> _mUpstreamMsgItersToReload;
92
df8863ad
SM
93 /* Clock class correlation validator */
94 bt2ccv::ClockCorrelationValidator _mClkCorrValidator;
fca1d0f5
PP
95};
96
97} /* namespace bt2mux */
98
99#endif /* BABELTRACE_PLUGINS_UTILS_MUXER_MSG_ITER_HPP */
This page took 0.029266 seconds and 4 git commands to generate.