blob: 057c96ad8daa9f6ab253340b6da2a1afe56db83d [file] [log] [blame]
Václav Kubernáte7a9fa32018-08-22 13:56:35 +02001/*
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át36075ab2019-02-05 20:42:15 +010011#include <map>
Jan Kundrát9d163f12020-10-16 18:44:01 +000012#include <memory>
Václav Kubernátc58e4aa2019-04-03 18:37:32 +020013#include <optional>
Václav Kubernáte7a9fa32018-08-22 13:56:35 +020014#include <string>
15#include "ast_values.hpp"
Václav Kubernáta93f9002020-05-28 03:09:42 +020016#include "list_instance.hpp"
Václav Kubernátb4e5b182020-11-16 19:55:09 +010017#include "yang_operations.hpp"
Václav Kubernáte7a9fa32018-08-22 13:56:35 +020018
19/*! \class DatastoreAccess
20 * \brief Abstract class for accessing a datastore
21 */
22
Václav Kubernátc58e4aa2019-04-03 18:37:32 +020023struct DatastoreError {
24 std::string message;
25 std::optional<std::string> xpath;
26
Václav Kubernát74487df2020-06-04 01:29:28 +020027 DatastoreError(const std::string& message, const std::optional<std::string>& xpath = std::nullopt);
Václav Kubernátc58e4aa2019-04-03 18:37:32 +020028};
29
Václav Kubernát654303f2020-07-31 13:16:54 +020030class DatastoreException : public std::exception {
Václav Kubernátc58e4aa2019-04-03 18:37:32 +020031public:
32 DatastoreException(const std::vector<DatastoreError>& errors);
33 ~DatastoreException() override = default;
Václav Kubernát59e4ee42020-07-08 17:32:45 +020034 [[nodiscard]] const char* what() const noexcept override;
Václav Kubernátc58e4aa2019-04-03 18:37:32 +020035
36private:
37 std::string m_what;
38};
Václav Kubernáte7a9fa32018-08-22 13:56:35 +020039
Jan Kundrát77d9f612019-09-03 16:52:32 +020040class Schema;
41
Václav Kubernátbf65dd72020-05-28 02:32:31 +020042struct dataPath_;
43
Václav Kubernáte7a9fa32018-08-22 13:56:35 +020044class DatastoreAccess {
45public:
Václav Kubernátcf9224f2020-06-02 09:55:29 +020046 using Tree = std::vector<std::pair<std::string, leaf_data_>>;
Václav Kubernáte7a9fa32018-08-22 13:56:35 +020047 virtual ~DatastoreAccess() = 0;
Václav Kubernát59e4ee42020-07-08 17:32:45 +020048 [[nodiscard]] virtual Tree getItems(const std::string& path) const = 0;
Václav Kubernáte7a9fa32018-08-22 13:56:35 +020049 virtual void setLeaf(const std::string& path, leaf_data_ value) = 0;
Jan Kundrátcbf288b2020-06-18 20:44:39 +020050 virtual void createItem(const std::string& path) = 0;
51 virtual void deleteItem(const std::string& path) = 0;
Václav Kubernátbf65dd72020-05-28 02:32:31 +020052 virtual void moveItem(const std::string& path, std::variant<yang::move::Absolute, yang::move::Relative> move) = 0;
Jan Kundrát6ee84792020-01-24 01:43:36 +010053 virtual Tree executeRpc(const std::string& path, const Tree& input) = 0;
Václav Kubernáta8789602020-07-20 15:18:19 +020054 virtual Tree executeAction(const std::string& path, const Tree& input) = 0;
Václav Kubernát812ee282018-08-30 17:10:03 +020055
Jan Kundrát77d9f612019-09-03 16:52:32 +020056 virtual std::shared_ptr<Schema> schema() = 0;
57
Václav Kubernát812ee282018-08-30 17:10:03 +020058 virtual void commitChanges() = 0;
Václav Kubernát6d791432018-10-25 16:00:35 +020059 virtual void discardChanges() = 0;
Václav Kubernát7160a132020-04-03 02:11:01 +020060 virtual void copyConfig(const Datastore source, const Datastore destination) = 0;
Václav Kubernát59e4ee42020-07-08 17:32:45 +020061 [[nodiscard]] virtual std::string dump(const DataFormat format) const = 0;
Václav Kubernátab612e92019-11-26 19:51:31 +010062
63private:
64 friend class DataQuery;
65 virtual std::vector<ListInstance> listInstances(const std::string& path) = 0;
Václav Kubernáte7a9fa32018-08-22 13:56:35 +020066};