Migrate to libyang2

Explanation of some of the changes:
1) New libyang produces different schema paths, that don't include
   choice/case nodes. This can be seen in Firewall.cpp.
2) New sysrepo does not use <map>, so it has to be included at multiple
   places.
3) getUniqueSubtree is now just one line of code. Another commit can get
   rid of it.
4) dataFromSysrepo sometimes gives less and sometimes more data. This is
   because it now uses libyang instead of sr_val_t
   - When it gives more data it's usually just lists or empty containers,
     sr_val_t didn't give those.
   - When it gives less data it's also just empty containers. This can
     be seen with "sensor-data" in hardware_ietf-hardware.cpp.

Depends-on: https://gerrit.cesnet.cz/c/CzechLight/dependencies/+/5171
Change-Id: I388536269e790b8b74ea7791c79b180adc5d80a6
Co-authored-by: Jan Kundrát <jan.kundrat@cesnet.cz>
diff --git a/src/system/LLDPCallback.cpp b/src/system/LLDPCallback.cpp
index a38705b..c25651e 100644
--- a/src/system/LLDPCallback.cpp
+++ b/src/system/LLDPCallback.cpp
@@ -14,39 +14,29 @@
 LLDPCallback::LLDPCallback(std::shared_ptr<LLDPDataProvider> lldp)
     : m_log(spdlog::get("system"))
     , m_lldp(std::move(lldp))
-    , m_lastRequestId(0)
 {
 }
 
-int LLDPCallback::operator()(std::shared_ptr<::sysrepo::Session> session, const char* module_name, const char* xpath, const char* request_xpath, uint32_t request_id, std::shared_ptr<libyang::Data_Node>& parent)
+sysrepo::ErrorCode LLDPCallback::operator()(sysrepo::Session session, uint32_t, std::string_view, std::optional<std::string_view> subXPath, std::optional<std::string_view> requestXPath, uint32_t, std::optional<libyang::DataNode>& output)
 {
-    m_log->trace("operational data callback: XPath {} req {} orig-XPath {}", xpath, request_id, request_xpath);
+    m_log->trace("operational data callback: subXPath {} request-XPath {}",
+            subXPath ? *subXPath : "(none)", requestXPath ? *requestXPath : "(none)");
 
-    // when asking for something in the subtree of THIS request
-    if (m_lastRequestId == request_id) {
-        m_log->trace(" ops data request already handled");
-        return SR_ERR_OK;
-    }
-    m_lastRequestId = request_id;
-
-    auto ctx = session->get_context();
-    auto mod = ctx->get_module(module_name);
-
-    parent = std::make_shared<libyang::Data_Node>(ctx, "/czechlight-lldp:nbr-list", nullptr, LYD_ANYDATA_CONSTSTRING, 0);
+    output = session.getContext().newPath("/czechlight-lldp:nbr-list");
 
     for (const auto& n : m_lldp->getNeighbors()) {
-        auto ifc = std::make_shared<libyang::Data_Node>(parent, mod, "neighbors");
+        auto ifc = output->newPath("neighbors");
 
-        auto ifName = std::make_shared<libyang::Data_Node>(ifc, mod, "ifName", n.m_portId.c_str());
+        auto ifName = ifc->newPath("ifName", n.m_portId.c_str());
 
         for (const auto& [key, val] : n.m_properties) { // garbage properties in, garbage out
-            auto prop = std::make_shared<libyang::Data_Node>(ifc, mod, key.c_str(), val.c_str());
+            ifc->newPath(key.c_str(), val.c_str());
         }
     }
 
-    m_log->trace("Pushing to sysrepo (JSON): {}", parent->print_mem(LYD_FORMAT::LYD_JSON, 0));
+    m_log->trace("Pushing to sysrepo (JSON): {}", *output->printStr(libyang::DataFormat::JSON, libyang::PrintFlags::WithSiblings));
 
-    return SR_ERR_OK;
+    return sysrepo::ErrorCode::Ok;
 }
 
 }