tests/lib/utils: add RunIn::onMsgIterNext()
[babeltrace.git] / tests / lib / utils / run-in.hpp
index 0855e05e062ba697b3f9b4b4b51ad3a11833e634..54e8ec20c3204401990e36f8e57ffa87b89b6a3b 100644 (file)
@@ -4,45 +4,52 @@
  * Copyright (C) 2020-2023 EfficiOS, inc.
  */
 
-#ifndef TESTS_LIB_UTILS_H
-#define TESTS_LIB_UTILS_H
-
-#include <functional>
+#ifndef TESTS_LIB_UTILS_RUN_IN_HPP
+#define TESTS_LIB_UTILS_RUN_IN_HPP
 
 #include <babeltrace2/babeltrace.h>
 
-using RunInCompClsQueryFunc = std::function<void(bt_self_component_class *)>;
-using RunInCompClsInitFunc = std::function<void(bt_self_component *)>;
-using RunInMsgIterClsInitFunc = std::function<void(bt_self_message_iterator *)>;
+#include "cpp-common/bt2/self-component-class.hpp"
+#include "cpp-common/bt2/self-component-port.hpp"
+#include "cpp-common/bt2/self-message-iterator.hpp"
 
 /*
- * Runs:
- *
- * • `compClsCtxFunc` in the context of a component class method,
- *   if not `nullptr`.
- *
- * • `compCtxFunc` in the context of a component method, if not
- *   `nullptr`.
+ * Base class from which to inherit to call runIn().
  *
- * • `msgIterCtxFunc` in the context of a message iterator method, if
- *   not `nullptr`.
- */
-void runIn(RunInCompClsQueryFunc compClsCtxFunc, RunInCompClsInitFunc compCtxFunc,
-           RunInMsgIterClsInitFunc msgIterCtxFunc);
-
-/*
- * Runs `func` in the context of a component class method.
- */
-void runInCompClsQuery(RunInCompClsQueryFunc func);
-
-/*
- * Runs `func` in the context of a component method.
+ * Override any of the on*() methods to get your statements executed in
+ * a specific context.
  */
-void runInCompClsInit(RunInCompClsInitFunc func);
+class RunIn
+{
+public:
+    virtual ~RunIn() = default;
+
+    /*
+     * Called when querying the component class `self`.
+     */
+    virtual void onQuery(bt2::SelfComponentClass self);
+
+    /*
+     * Called when initializing the component `self`.
+     */
+    virtual void onCompInit(bt2::SelfComponent self);
+
+    /*
+     * 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);
+};
 
 /*
- * Runs `func` in the context of a message iterator method.
+ * Runs a simple graph (one source and one sink component), calling the
+ * `on*()` methods of `runIn` along the way.
  */
-void runInMsgIterClsInit(RunInMsgIterClsInitFunc func);
+void runIn(RunIn& runIn);
 
-#endif /* TESTS_LIB_UTILS_H */
+#endif /* TESTS_LIB_UTILS_RUN_IN_HPP */
This page took 0.023496 seconds and 4 git commands to generate.