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 | |
Václav Kubernát | f5d7515 | 2020-12-03 03:52:34 +0100 | [diff] [blame] | 40 | enum class DatastoreTarget { |
| 41 | Startup, |
| 42 | Running, |
| 43 | Operational |
| 44 | }; |
| 45 | |
Jan Kundrát | 77d9f61 | 2019-09-03 16:52:32 +0200 | [diff] [blame] | 46 | class Schema; |
| 47 | |
Václav Kubernát | bf65dd7 | 2020-05-28 02:32:31 +0200 | [diff] [blame] | 48 | struct dataPath_; |
| 49 | |
Václav Kubernát | e7a9fa3 | 2018-08-22 13:56:35 +0200 | [diff] [blame] | 50 | class DatastoreAccess { |
| 51 | public: |
Václav Kubernát | cf9224f | 2020-06-02 09:55:29 +0200 | [diff] [blame] | 52 | using Tree = std::vector<std::pair<std::string, leaf_data_>>; |
Václav Kubernát | e7a9fa3 | 2018-08-22 13:56:35 +0200 | [diff] [blame] | 53 | virtual ~DatastoreAccess() = 0; |
Václav Kubernát | 59e4ee4 | 2020-07-08 17:32:45 +0200 | [diff] [blame] | 54 | [[nodiscard]] virtual Tree getItems(const std::string& path) const = 0; |
Václav Kubernát | e7a9fa3 | 2018-08-22 13:56:35 +0200 | [diff] [blame] | 55 | virtual void setLeaf(const std::string& path, leaf_data_ value) = 0; |
Jan Kundrát | cbf288b | 2020-06-18 20:44:39 +0200 | [diff] [blame] | 56 | virtual void createItem(const std::string& path) = 0; |
| 57 | virtual void deleteItem(const std::string& path) = 0; |
Václav Kubernát | bf65dd7 | 2020-05-28 02:32:31 +0200 | [diff] [blame] | 58 | virtual void moveItem(const std::string& path, std::variant<yang::move::Absolute, yang::move::Relative> move) = 0; |
Václav Kubernát | b3960f8 | 2020-12-01 03:21:48 +0100 | [diff] [blame] | 59 | virtual Tree execute(const std::string& path, const Tree& input) = 0; |
Václav Kubernát | e066fe2 | 2022-04-06 00:32:26 +0200 | [diff] [blame^] | 60 | DatastoreTarget target() const; |
Václav Kubernát | f5d7515 | 2020-12-03 03:52:34 +0100 | [diff] [blame] | 61 | void setTarget(const DatastoreTarget target); |
Václav Kubernát | 812ee28 | 2018-08-30 17:10:03 +0200 | [diff] [blame] | 62 | |
Jan Kundrát | 77d9f61 | 2019-09-03 16:52:32 +0200 | [diff] [blame] | 63 | virtual std::shared_ptr<Schema> schema() = 0; |
| 64 | |
Václav Kubernát | 812ee28 | 2018-08-30 17:10:03 +0200 | [diff] [blame] | 65 | virtual void commitChanges() = 0; |
Václav Kubernát | 6d79143 | 2018-10-25 16:00:35 +0200 | [diff] [blame] | 66 | virtual void discardChanges() = 0; |
Václav Kubernát | 7160a13 | 2020-04-03 02:11:01 +0200 | [diff] [blame] | 67 | virtual void copyConfig(const Datastore source, const Datastore destination) = 0; |
Václav Kubernát | 59e4ee4 | 2020-07-08 17:32:45 +0200 | [diff] [blame] | 68 | [[nodiscard]] virtual std::string dump(const DataFormat format) const = 0; |
Václav Kubernát | ab612e9 | 2019-11-26 19:51:31 +0100 | [diff] [blame] | 69 | |
Václav Kubernát | f5d7515 | 2020-12-03 03:52:34 +0100 | [diff] [blame] | 70 | protected: |
| 71 | DatastoreTarget m_target = DatastoreTarget::Operational; |
| 72 | |
Václav Kubernát | ab612e9 | 2019-11-26 19:51:31 +0100 | [diff] [blame] | 73 | private: |
| 74 | friend class DataQuery; |
| 75 | virtual std::vector<ListInstance> listInstances(const std::string& path) = 0; |
Václav Kubernát | e7a9fa3 | 2018-08-22 13:56:35 +0200 | [diff] [blame] | 76 | }; |