blob: 53cd43ef45d430558463ee74d13b15e39699be3d [file] [log] [blame]
Tomáš Pecka7eb64592024-01-24 14:10:47 +01001/*
2 * Copyright (C) 2024 CESNET, https://photonics.cesnet.cz/
3 *
4 * Written by Tomáš Pecka <tomas.pecka@cesnet.cz>
5 *
6 */
7
8#include "datastore.h"
9#include "sysrepo-helpers/common.h"
10
11DatastoreWatcher::DatastoreWatcher(sysrepo::Session& session, const std::string& xpath, const std::set<std::string>& ignoredPaths)
12 : m_ignoredPaths(ignoredPaths)
13 , m_sub(session.onModuleChange(
14 moduleFromXpath(xpath),
15 [&](sysrepo::Session session, auto, auto, auto, auto, auto) {
16 ValueChanges changes;
17 for (const auto& change : session.getChanges()) {
18 if (m_ignoredPaths.contains(change.node.schema().path())) {
19 continue;
20 }
21
22 if (change.node.schema().nodeType() == libyang::NodeType::List) {
23 // any list will surely have some "nodes below", so let's not waste time printing the list entry itself
24 continue;
25 }
26 if (change.node.schema().nodeType() == libyang::NodeType::Container && !change.node.schema().asContainer().isPresence()) {
27 // non-presence containers are "always there", let's not clutter up the output
28 continue;
29 }
30
31 if (change.operation == sysrepo::ChangeOperation::Deleted) {
32 changes.emplace(change.node.path(), Deleted());
33 } else {
34 changes.emplace(change.node.path(), nodeAsString(change.node));
35 }
36 }
37
38 change(changes);
39 return sysrepo::ErrorCode::Ok;
40 },
41 xpath,
42 0,
43 sysrepo::SubscribeOptions::DoneOnly))
44{
45}