tests: encapsulate RPC watcher into a class
Change-Id: I62e09cd4333717ce8941a2bcbe17298cc007f315
diff --git a/tests/sysrepo-helpers/rpc.cpp b/tests/sysrepo-helpers/rpc.cpp
new file mode 100644
index 0000000..eb32038
--- /dev/null
+++ b/tests/sysrepo-helpers/rpc.cpp
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2024 CESNET, https://photonics.cesnet.cz/
+ *
+ * Written by Tomáš Pecka <tomas.pecka@cesnet.cz>
+ *
+ */
+
+#include "rpc.h"
+#include "sysrepo-helpers/common.h"
+
+RPCWatcher::RPCWatcher(sysrepo::Session& session, const std::string& xpath)
+ : m_sub(session.onRPCAction(xpath, [&](auto, auto, auto, const libyang::DataNode input, auto, auto, auto) {
+ std::map<std::string, std::string> in;
+
+ for (auto n : input.childrenDfs()) {
+ in.emplace(n.path(), nodeAsString(n));
+ }
+
+ rpc(in);
+ return sysrepo::ErrorCode::Ok;
+ }))
+{
+}