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> |
| 14 | #include "ast_values.hpp" |
Václav Kubernát | a93f900 | 2020-05-28 03:09:42 +0200 | [diff] [blame^] | 15 | #include "list_instance.hpp" |
Václav Kubernát | e7a9fa3 | 2018-08-22 13:56:35 +0200 | [diff] [blame] | 16 | |
| 17 | /*! \class DatastoreAccess |
| 18 | * \brief Abstract class for accessing a datastore |
| 19 | */ |
| 20 | |
Václav Kubernát | c58e4aa | 2019-04-03 18:37:32 +0200 | [diff] [blame] | 21 | struct DatastoreError { |
| 22 | std::string message; |
| 23 | std::optional<std::string> xpath; |
| 24 | |
| 25 | DatastoreError(const std::string& message, const std::optional<std::string>& xpath); |
| 26 | }; |
| 27 | |
| 28 | class DatastoreException : std::exception { |
| 29 | public: |
| 30 | DatastoreException(const std::vector<DatastoreError>& errors); |
| 31 | ~DatastoreException() override = default; |
| 32 | const char* what() const noexcept override; |
| 33 | |
| 34 | private: |
| 35 | std::string m_what; |
| 36 | }; |
Václav Kubernát | e7a9fa3 | 2018-08-22 13:56:35 +0200 | [diff] [blame] | 37 | |
Jan Kundrát | 77d9f61 | 2019-09-03 16:52:32 +0200 | [diff] [blame] | 38 | class Schema; |
| 39 | |
Václav Kubernát | e7a9fa3 | 2018-08-22 13:56:35 +0200 | [diff] [blame] | 40 | class DatastoreAccess { |
| 41 | public: |
Jan Kundrát | b331b55 | 2020-01-23 15:25:29 +0100 | [diff] [blame] | 42 | using Tree = std::map<std::string, leaf_data_>; |
Václav Kubernát | e7a9fa3 | 2018-08-22 13:56:35 +0200 | [diff] [blame] | 43 | virtual ~DatastoreAccess() = 0; |
Jan Kundrát | b331b55 | 2020-01-23 15:25:29 +0100 | [diff] [blame] | 44 | virtual Tree getItems(const std::string& path) = 0; |
Václav Kubernát | e7a9fa3 | 2018-08-22 13:56:35 +0200 | [diff] [blame] | 45 | virtual void setLeaf(const std::string& path, leaf_data_ value) = 0; |
| 46 | virtual void createPresenceContainer(const std::string& path) = 0; |
| 47 | virtual void deletePresenceContainer(const std::string& path) = 0; |
Václav Kubernát | f5f64f0 | 2019-03-19 17:15:47 +0100 | [diff] [blame] | 48 | virtual void createListInstance(const std::string& path) = 0; |
| 49 | virtual void deleteListInstance(const std::string& path) = 0; |
Václav Kubernát | 5b8a8f3 | 2020-05-20 00:57:22 +0200 | [diff] [blame] | 50 | virtual void createLeafListInstance(const std::string& path) = 0; |
| 51 | virtual void deleteLeafListInstance(const std::string& path) = 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 | }; |