Tomáš Pecka | a18702d | 2021-01-25 18:07:23 +0100 | [diff] [blame] | 1 | /* |
Jan Kundrát | 7aa894e | 2022-03-30 19:32:40 +0200 | [diff] [blame] | 2 | * Copyright (C) 2016-2022 CESNET, https://photonics.cesnet.cz/ |
Tomáš Pecka | a18702d | 2021-01-25 18:07:23 +0100 | [diff] [blame] | 3 | * |
| 4 | * Written by Jan Kundrát <jan.kundrat@cesnet.cz> |
| 5 | * |
| 6 | */ |
| 7 | |
Tomáš Pecka | 9f7b13e | 2024-01-24 13:47:04 +0100 | [diff] [blame] | 8 | #include "notifications.h" |
Tomáš Pecka | de06290 | 2024-01-24 13:41:16 +0100 | [diff] [blame] | 9 | #include "sysrepo-helpers/common.h" |
Tomáš Pecka | a18702d | 2021-01-25 18:07:23 +0100 | [diff] [blame] | 10 | |
Jan Kundrát | 7aa894e | 2022-03-30 19:32:40 +0200 | [diff] [blame] | 11 | NotificationWatcher::NotificationWatcher(sysrepo::Session& session, const std::string& xpath) |
Jan Kundrát | c151151 | 2024-01-15 13:47:28 +0100 | [diff] [blame] | 12 | : 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áš Pecka | a18702d | 2021-01-25 18:07:23 +0100 | [diff] [blame] | 28 | { |
Tomáš Pecka | a18702d | 2021-01-25 18:07:23 +0100 | [diff] [blame] | 29 | } |