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