tests/lib: C++ify run-in and condition trigger code
[babeltrace.git] / tests / lib / utils / run-in.hpp
index 01774f9053f5e424dcea154d84b31d73f3f955c2..d08e931a125cb8e67719ec8765c389b49f405a99 100644 (file)
@@ -7,46 +7,43 @@
 #ifndef TESTS_LIB_UTILS_H
 #define TESTS_LIB_UTILS_H
 
-#include <functional>
-
 #include <babeltrace2/babeltrace.h>
 
 #include "cpp-common/bt2/self-component-class.hpp"
 #include "cpp-common/bt2/self-component-port.hpp"
 #include "cpp-common/bt2/self-message-iterator.hpp"
 
-using RunInCompClsQueryFunc = std::function<void(bt2::SelfComponentClass)>;
-using RunInCompClsInitFunc = std::function<void(bt2::SelfComponent)>;
-using RunInMsgIterClsInitFunc = std::function<void(bt2::SelfMessageIterator)>;
-
 /*
- * Runs:
- *
- * • `compClsCtxFunc` in the context of a component class method,
- *   if not `nullptr`.
+ * Base class from which to inherit to call runIn().
  *
- * • `compCtxFunc` in the context of a component method, if not
- *   `nullptr`.
- *
- * • `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);
+};
 
 /*
- * 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 */
This page took 0.023288 seconds and 4 git commands to generate.