tests/lib/utils: add RunIn::onMsgIterNext()
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 21 Feb 2024 21:25:00 +0000 (16:25 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Tue, 26 Mar 2024 18:56:36 +0000 (14:56 -0400)
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 <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11834
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
tests/lib/utils/run-in.cpp
tests/lib/utils/run-in.hpp

index 91b23396e7fbcd6650cd1589baeab69d738ad86d..e31bbc58a26ab511e306c61b4eea9d5bd3fe9470 100644 (file)
@@ -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<RunInSourceMsgIter, RunInSource> {self, "RUN-IN-SRC-MSG-ITER"}
+        bt2::UserMessageIterator<RunInSourceMsgIter, RunInSource> {self, "RUN-IN-SRC-MSG-ITER"},
+        _mRunIn {&port.data<RunIn>()}, _mSelf {self}
     {
-        port.data<RunIn>().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 :
index f887d7a1c59b717011d4a7be5954347bda596fbf..54e8ec20c3204401990e36f8e57ffa87b89b6a3b 100644 (file)
@@ -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);
 };
 
 /*
This page took 0.025396 seconds and 4 git commands to generate.