Václav Kubernát | e7a9fa3 | 2018-08-22 13:56:35 +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 | |
Jan Kundrát | 36075ab | 2019-02-05 20:42:15 +0100 | [diff] [blame] | 11 | #include <map> |
Václav Kubernát | c58e4aa | 2019-04-03 18:37:32 +0200 | [diff] [blame] | 12 | #include <optional> |
Václav Kubernát | e7a9fa3 | 2018-08-22 13:56:35 +0200 | [diff] [blame] | 13 | #include <string> |
Václav Kubernát | bf65dd7 | 2020-05-28 02:32:31 +0200 | [diff] [blame] | 14 | #include "yang_move.hpp" |
Václav Kubernát | e7a9fa3 | 2018-08-22 13:56:35 +0200 | [diff] [blame] | 15 | #include "ast_values.hpp" |
Václav Kubernát | a93f900 | 2020-05-28 03:09:42 +0200 | [diff] [blame] | 16 | #include "list_instance.hpp" |
Václav Kubernát | e7a9fa3 | 2018-08-22 13:56:35 +0200 | [diff] [blame] | 17 | |
| 18 | /*! \class DatastoreAccess |
| 19 | * \brief Abstract class for accessing a datastore |
| 20 | */ |
| 21 | |
Václav Kubernát | c58e4aa | 2019-04-03 18:37:32 +0200 | [diff] [blame] | 22 | struct DatastoreError { |
| 23 | std::string message; |
| 24 | std::optional<std::string> xpath; |
| 25 | |
| 26 | DatastoreError(const std::string& message, const std::optional<std::string>& xpath); |
| 27 | }; |
| 28 | |
| 29 | class DatastoreException : std::exception { |
| 30 | public: |
| 31 | DatastoreException(const std::vector<DatastoreError>& errors); |
| 32 | ~DatastoreException() override = default; |
| 33 | const char* what() const noexcept override; |
| 34 | |
| 35 | private: |
| 36 | std::string m_what; |
| 37 | }; |
Václav Kubernát | e7a9fa3 | 2018-08-22 13:56:35 +0200 | [diff] [blame] | 38 | |
Jan Kundrát | 77d9f61 | 2019-09-03 16:52:32 +0200 | [diff] [blame] | 39 | class Schema; |
| 40 | |
Václav Kubernát | bf65dd7 | 2020-05-28 02:32:31 +0200 | [diff] [blame] | 41 | struct dataPath_; |
| 42 | |
Václav Kubernát | e7a9fa3 | 2018-08-22 13:56:35 +0200 | [diff] [blame] | 43 | class DatastoreAccess { |
| 44 | public: |
Václav Kubernát | cf9224f | 2020-06-02 09:55:29 +0200 | [diff] [blame] | 45 | using Tree = std::vector<std::pair<std::string, leaf_data_>>; |
Václav Kubernát | e7a9fa3 | 2018-08-22 13:56:35 +0200 | [diff] [blame] | 46 | virtual ~DatastoreAccess() = 0; |
Jan Kundrát | b331b55 | 2020-01-23 15:25:29 +0100 | [diff] [blame] | 47 | virtual Tree getItems(const std::string& path) = 0; |
Václav Kubernát | e7a9fa3 | 2018-08-22 13:56:35 +0200 | [diff] [blame] | 48 | virtual void setLeaf(const std::string& path, leaf_data_ value) = 0; |
Jan Kundrát | cbf288b | 2020-06-18 20:44:39 +0200 | [diff] [blame] | 49 | virtual void createItem(const std::string& path) = 0; |
| 50 | virtual void deleteItem(const std::string& path) = 0; |
Václav Kubernát | bf65dd7 | 2020-05-28 02:32:31 +0200 | [diff] [blame] | 51 | virtual void moveItem(const std::string& path, std::variant<yang::move::Absolute, yang::move::Relative> move) = 0; |
Jan Kundrát | 6ee8479 | 2020-01-24 01:43:36 +0100 | [diff] [blame] | 52 | virtual Tree executeRpc(const std::string& path, const Tree& input) = 0; |
Václav Kubernát | 812ee28 | 2018-08-30 17:10:03 +0200 | [diff] [blame] | 53 | |
Jan Kundrát | 77d9f61 | 2019-09-03 16:52:32 +0200 | [diff] [blame] | 54 | virtual std::shared_ptr<Schema> schema() = 0; |
| 55 | |
Václav Kubernát | 812ee28 | 2018-08-30 17:10:03 +0200 | [diff] [blame] | 56 | virtual void commitChanges() = 0; |
Václav Kubernát | 6d79143 | 2018-10-25 16:00:35 +0200 | [diff] [blame] | 57 | virtual void discardChanges() = 0; |
Václav Kubernát | 7160a13 | 2020-04-03 02:11:01 +0200 | [diff] [blame] | 58 | virtual void copyConfig(const Datastore source, const Datastore destination) = 0; |
Václav Kubernát | ab612e9 | 2019-11-26 19:51:31 +0100 | [diff] [blame] | 59 | |
| 60 | private: |
| 61 | friend class DataQuery; |
| 62 | virtual std::vector<ListInstance> listInstances(const std::string& path) = 0; |
Václav Kubernát | e7a9fa3 | 2018-08-22 13:56:35 +0200 | [diff] [blame] | 63 | }; |