From a72c7ff699753ebaf571b69389354c40967731e7 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Wed, 21 Feb 2024 16:25:00 -0500 Subject: [PATCH] tests/lib/utils: add RunIn::onMsgIterNext() Add a virtual method on `RunIn` to execute some code in the context of a message iterator's `next` method. Change-Id: I6f8ca7a9596fd998f07c401c1859177c728a0b53 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/11834 Reviewed-by: Philippe Proulx --- tests/lib/utils/run-in.cpp | 16 +++++++++++++--- tests/lib/utils/run-in.hpp | 6 ++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/tests/lib/utils/run-in.cpp b/tests/lib/utils/run-in.cpp index 91b23396..e31bbc58 100644 --- a/tests/lib/utils/run-in.cpp +++ b/tests/lib/utils/run-in.cpp @@ -27,6 +27,10 @@ void RunIn::onMsgIterInit(bt2::SelfMessageIterator) { } +void RunIn::onMsgIterNext(bt2::SelfMessageIterator, bt2::ConstMessageArray&) +{ +} + namespace { class RunInSource; @@ -37,14 +41,20 @@ public: explicit RunInSourceMsgIter(const bt2::SelfMessageIterator self, bt2::SelfMessageIteratorConfiguration, const bt2::SelfComponentOutputPort port) : - bt2::UserMessageIterator {self, "RUN-IN-SRC-MSG-ITER"} + bt2::UserMessageIterator {self, "RUN-IN-SRC-MSG-ITER"}, + _mRunIn {&port.data()}, _mSelf {self} { - port.data().onMsgIterInit(self); + _mRunIn->onMsgIterInit(self); } - void _next(bt2::ConstMessageArray&) + void _next(bt2::ConstMessageArray& msgs) { + _mRunIn->onMsgIterNext(_mSelf, msgs); } + +private: + RunIn *_mRunIn; + bt2::SelfMessageIterator _mSelf; }; class RunInSource final : diff --git a/tests/lib/utils/run-in.hpp b/tests/lib/utils/run-in.hpp index f887d7a1..54e8ec20 100644 --- a/tests/lib/utils/run-in.hpp +++ b/tests/lib/utils/run-in.hpp @@ -38,6 +38,12 @@ public: * Called when initializing the message iterator `self`. */ virtual void onMsgIterInit(bt2::SelfMessageIterator self); + + /* + * Called within the "next" method of `self` to return the messages + * `msgs`. + */ + virtual void onMsgIterNext(bt2::SelfMessageIterator self, bt2::ConstMessageArray& msgs); }; /* -- 2.34.1