blob: bcd85826931388565c3731d0f4dfd283bf67adaf [file] [log] [blame]
Tomáš Peckaa18702d2021-01-25 18:07:23 +01001/*
Jan Kundrát7aa894e2022-03-30 19:32:40 +02002 * Copyright (C) 2016-2022 CESNET, https://photonics.cesnet.cz/
Tomáš Peckaa18702d2021-01-25 18:07:23 +01003 *
4 * Written by Jan Kundrát <jan.kundrat@cesnet.cz>
5 *
6*/
7
Tomáš Pecka9f7b13e2024-01-24 13:47:04 +01008#include "notifications.h"
Tomáš Peckade062902024-01-24 13:41:16 +01009#include "sysrepo-helpers/common.h"
Tomáš Peckaa18702d2021-01-25 18:07:23 +010010
Jan Kundrát7aa894e2022-03-30 19:32:40 +020011NotificationWatcher::NotificationWatcher(sysrepo::Session& session, const std::string& xpath)
Jan Kundrátc1511512024-01-15 13:47:28 +010012 : m_sub{session.onNotification(
13 moduleFromXpath(xpath),
14 [this, xpath](sysrepo::Session, uint32_t, const sysrepo::NotificationType type, const std::optional<libyang::DataNode> tree, const sysrepo::NotificationTimeStamp) {
15 if (type != sysrepo::NotificationType::Realtime) {
16 return;
17 }
18 Values data;
19 for (const auto& it : tree->findPath(xpath)->childrenDfs()) {
20 if (!it.isTerm()) {
21 continue;
22 }
23 data[it.path().substr(xpath.size() + 1 /* trailing slash */)] = std::visit(libyang::ValuePrinter{}, it.asTerm().value());
24 }
25 notified(data);
26 },
27 xpath)}
Tomáš Peckaa18702d2021-01-25 18:07:23 +010028{
Tomáš Peckaa18702d2021-01-25 18:07:23 +010029}