blob: bcd85826931388565c3731d0f4dfd283bf67adaf [file] [log] [blame]
/*
* Copyright (C) 2016-2022 CESNET, https://photonics.cesnet.cz/
*
* Written by Jan Kundrát <jan.kundrat@cesnet.cz>
*
*/
#include "notifications.h"
#include "sysrepo-helpers/common.h"
NotificationWatcher::NotificationWatcher(sysrepo::Session& session, const std::string& xpath)
: m_sub{session.onNotification(
moduleFromXpath(xpath),
[this, xpath](sysrepo::Session, uint32_t, const sysrepo::NotificationType type, const std::optional<libyang::DataNode> tree, const sysrepo::NotificationTimeStamp) {
if (type != sysrepo::NotificationType::Realtime) {
return;
}
Values data;
for (const auto& it : tree->findPath(xpath)->childrenDfs()) {
if (!it.isTerm()) {
continue;
}
data[it.path().substr(xpath.size() + 1 /* trailing slash */)] = std::visit(libyang::ValuePrinter{}, it.asTerm().value());
}
notified(data);
},
xpath)}
{
}