make fillMap reusable for future RPC support
Change-Id: I4fc7abeff948c36aa5190a0188857981aa2bd61e
diff --git a/src/netconf_access.cpp b/src/netconf_access.cpp
index e648a33..1e28bd2 100644
--- a/src/netconf_access.cpp
+++ b/src/netconf_access.cpp
@@ -13,34 +13,38 @@
#include "utils.hpp"
#include "yang_schema.hpp"
+namespace {
+
+// This is very similar to the fillMap lambda in SysrepoAccess, however,
+// Sysrepo returns a weird array-like structure, while libnetconf
+// returns libyang::Data_Node
+void fillMap(DatastoreAccess::Tree& res, const std::vector<std::shared_ptr<libyang::Data_Node>> items)
+{
+ for (const auto& it : items) {
+ if (!it)
+ continue;
+ if (it->schema()->nodetype() == LYS_LIST) {
+ res.emplace(it->path(), special_{SpecialValue::List});
+ }
+ if (it->schema()->nodetype() == LYS_LEAF) {
+ libyang::Data_Node_Leaf_List leaf(it);
+ res.emplace(leaf.path(), leafValueFromValue(leaf.value(), leaf.leaf_type()->base()));
+ }
+ }
+}
+}
+
+
NetconfAccess::~NetconfAccess() = default;
DatastoreAccess::Tree NetconfAccess::getItems(const std::string& path)
{
Tree res;
-
- // This is very similar to the fillMap lambda in SysrepoAccess, however,
- // Sysrepo returns a weird array-like structure, while libnetconf
- // returns libyang::Data_Node
- auto fillMap = [&res](auto items) {
- for (const auto& it : items) {
- if (!it)
- continue;
- if (it->schema()->nodetype() == LYS_LIST) {
- res.emplace(it->path(), special_{SpecialValue::List});
- }
- if (it->schema()->nodetype() == LYS_LEAF) {
- libyang::Data_Node_Leaf_List leaf(it);
- res.emplace(leaf.path(), leafValueFromValue(leaf.value(), leaf.leaf_type()->base()));
- }
- }
- };
-
auto config = m_session->getConfig(NC_DATASTORE_RUNNING, (path != "/") ? std::optional{path} : std::nullopt);
if (config) {
for (auto it : config->tree_for()) {
- fillMap(it->tree_dfs());
+ fillMap(res, it->tree_dfs());
}
}
return res;