Tomáš Pecka | a18702d | 2021-01-25 18:07:23 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016-2018 CESNET, https://photonics.cesnet.cz/ |
| 3 | * |
| 4 | * Written by Jan Kundrát <jan.kundrat@cesnet.cz> |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #pragma once |
| 9 | |
| 10 | #include <chrono> |
| 11 | #include <mutex> |
| 12 | #include <sysrepo-cpp/Session.hpp> |
| 13 | #include "test_log_setup.h" |
| 14 | |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 15 | /** @short YANG notifications */ |
Tomáš Pecka | a18702d | 2021-01-25 18:07:23 +0100 | [diff] [blame] | 16 | class EventWatcher { |
| 17 | public: |
Tomáš Pecka | a18702d | 2021-01-25 18:07:23 +0100 | [diff] [blame] | 18 | struct Event { |
| 19 | std::string xPath; |
| 20 | std::map<std::string, std::string> data; |
| 21 | std::chrono::time_point<std::chrono::steady_clock> received; |
| 22 | }; |
| 23 | |
Tomáš Pecka | 76fa2ff | 2021-03-15 16:28:06 +0100 | [diff] [blame] | 24 | explicit EventWatcher(std::function<void(Event)> callback); |
| 25 | ~EventWatcher(); |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 26 | void operator()(sysrepo::Session session, uint32_t subscriptionId, const sysrepo::NotificationType type, const std::optional<libyang::DataNode> notificationTree, const sysrepo::NotificationTimeStamp timestamp); |
Tomáš Pecka | 76fa2ff | 2021-03-15 16:28:06 +0100 | [diff] [blame] | 27 | |
Tomáš Pecka | a18702d | 2021-01-25 18:07:23 +0100 | [diff] [blame] | 28 | Event peek(std::vector<Event>::size_type index) const; |
| 29 | std::vector<Event>::size_type count() const; |
| 30 | |
| 31 | private: |
Tomáš Pecka | 76fa2ff | 2021-03-15 16:28:06 +0100 | [diff] [blame] | 32 | std::function<void(Event)> notifRecvCb; |
Tomáš Pecka | a18702d | 2021-01-25 18:07:23 +0100 | [diff] [blame] | 33 | mutable std::shared_ptr<std::mutex> mutex = std::make_shared<std::mutex>(); |
| 34 | std::shared_ptr<std::vector<Event>> events = std::make_shared<std::vector<Event>>(); |
| 35 | }; |