Václav Kubernát | 7310938 | 2018-09-14 19:52:03 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/ |
| 3 | * Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/ |
| 4 | * |
| 5 | * Written by Václav Kubernát <kubervac@fit.cvut.cz> |
| 6 | * |
| 7 | */ |
| 8 | |
| 9 | #pragma once |
| 10 | |
| 11 | #include <memory> |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 12 | #include <optional> |
Václav Kubernát | eaf5668 | 2021-02-22 17:15:41 +0100 | [diff] [blame] | 13 | #include <sysrepo-cpp/Session.hpp> |
Jan Kundrát | bb525b4 | 2020-02-04 11:56:59 +0100 | [diff] [blame] | 14 | #include "datastore_access.hpp" |
Václav Kubernát | 7310938 | 2018-09-14 19:52:03 +0200 | [diff] [blame] | 15 | |
| 16 | namespace sysrepo { |
| 17 | class Callback; |
| 18 | class Connection; |
| 19 | class Session; |
| 20 | class Subscribe; |
| 21 | } |
| 22 | class YangSchema; |
| 23 | |
| 24 | class Recorder { |
| 25 | public: |
| 26 | virtual ~Recorder(); |
Václav Kubernát | 69aabe9 | 2020-01-24 16:53:12 +0100 | [diff] [blame] | 27 | virtual void write(const std::string& xpath, const std::optional<std::string>& oldValue, const std::optional<std::string>& newValue) = 0; |
Václav Kubernát | 7310938 | 2018-09-14 19:52:03 +0200 | [diff] [blame] | 28 | }; |
| 29 | |
Jan Kundrát | bb525b4 | 2020-02-04 11:56:59 +0100 | [diff] [blame] | 30 | class DataSupplier { |
| 31 | public: |
| 32 | virtual ~DataSupplier(); |
Václav Kubernát | 59e4ee4 | 2020-07-08 17:32:45 +0200 | [diff] [blame] | 33 | [[nodiscard]] virtual DatastoreAccess::Tree get_data(const std::string& xpath) const = 0; |
Jan Kundrát | bb525b4 | 2020-02-04 11:56:59 +0100 | [diff] [blame] | 34 | }; |
| 35 | |
| 36 | |
Václav Kubernát | 7310938 | 2018-09-14 19:52:03 +0200 | [diff] [blame] | 37 | class SysrepoSubscription { |
| 38 | public: |
Václav Kubernát | eaf5668 | 2021-02-22 17:15:41 +0100 | [diff] [blame] | 39 | SysrepoSubscription(const std::string& moduleName, Recorder* rec = nullptr, sr_datastore_t ds = SR_DS_RUNNING); |
Václav Kubernát | 7310938 | 2018-09-14 19:52:03 +0200 | [diff] [blame] | 40 | |
| 41 | private: |
| 42 | std::shared_ptr<sysrepo::Connection> m_connection; |
| 43 | std::shared_ptr<sysrepo::Session> m_session; |
| 44 | std::shared_ptr<YangSchema> m_schema; |
Václav Kubernát | 7310938 | 2018-09-14 19:52:03 +0200 | [diff] [blame] | 45 | std::shared_ptr<sysrepo::Subscribe> m_subscription; |
| 46 | }; |
Jan Kundrát | bb525b4 | 2020-02-04 11:56:59 +0100 | [diff] [blame] | 47 | |
| 48 | class OperationalDataSubscription { |
| 49 | public: |
Václav Kubernát | 654303f | 2020-07-31 13:16:54 +0200 | [diff] [blame] | 50 | OperationalDataSubscription(const std::string& moduleName, const std::string& path, const DataSupplier& dataSupplier); |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 51 | |
Jan Kundrát | bb525b4 | 2020-02-04 11:56:59 +0100 | [diff] [blame] | 52 | private: |
| 53 | std::shared_ptr<sysrepo::Connection> m_connection; |
| 54 | std::shared_ptr<sysrepo::Session> m_session; |
| 55 | std::shared_ptr<YangSchema> m_schema; |
| 56 | std::shared_ptr<sysrepo::Subscribe> m_subscription; |
Jan Kundrát | bb525b4 | 2020-02-04 11:56:59 +0100 | [diff] [blame] | 57 | }; |