blob: a718f14f270a26e402ba38f2ec075ebb4d26e21a [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
Václav Kubernátf5d75152020-12-03 03:52:34 +010040enum class DatastoreTarget {
41 Startup,
42 Running,
43 Operational
44};
45
Jan Kundrát77d9f612019-09-03 16:52:32 +020046class Schema;
47
Václav Kubernátbf65dd72020-05-28 02:32:31 +020048struct dataPath_;
49
Václav Kubernáte7a9fa32018-08-22 13:56:35 +020050class DatastoreAccess {
51public:
Václav Kubernátcf9224f2020-06-02 09:55:29 +020052 using Tree = std::vector<std::pair<std::string, leaf_data_>>;
Václav Kubernáte7a9fa32018-08-22 13:56:35 +020053 virtual ~DatastoreAccess() = 0;
Václav Kubernát59e4ee42020-07-08 17:32:45 +020054 [[nodiscard]] virtual Tree getItems(const std::string& path) const = 0;
Václav Kubernáte7a9fa32018-08-22 13:56:35 +020055 virtual void setLeaf(const std::string& path, leaf_data_ value) = 0;
Jan Kundrátcbf288b2020-06-18 20:44:39 +020056 virtual void createItem(const std::string& path) = 0;
57 virtual void deleteItem(const std::string& path) = 0;
Václav Kubernátbf65dd72020-05-28 02:32:31 +020058 virtual void moveItem(const std::string& path, std::variant<yang::move::Absolute, yang::move::Relative> move) = 0;
Václav Kubernátb3960f82020-12-01 03:21:48 +010059 virtual Tree execute(const std::string& path, const Tree& input) = 0;
Václav Kubernáte066fe22022-04-06 00:32:26 +020060 DatastoreTarget target() const;
Václav Kubernátf5d75152020-12-03 03:52:34 +010061 void setTarget(const DatastoreTarget target);
Václav Kubernát812ee282018-08-30 17:10:03 +020062
Jan Kundrát77d9f612019-09-03 16:52:32 +020063 virtual std::shared_ptr<Schema> schema() = 0;
64
Václav Kubernát812ee282018-08-30 17:10:03 +020065 virtual void commitChanges() = 0;
Václav Kubernát6d791432018-10-25 16:00:35 +020066 virtual void discardChanges() = 0;
Václav Kubernát7160a132020-04-03 02:11:01 +020067 virtual void copyConfig(const Datastore source, const Datastore destination) = 0;
Václav Kubernát59e4ee42020-07-08 17:32:45 +020068 [[nodiscard]] virtual std::string dump(const DataFormat format) const = 0;
Václav Kubernátab612e92019-11-26 19:51:31 +010069
Václav Kubernátf5d75152020-12-03 03:52:34 +010070protected:
71 DatastoreTarget m_target = DatastoreTarget::Operational;
72
Václav Kubernátab612e92019-11-26 19:51:31 +010073private:
74 friend class DataQuery;
75 virtual std::vector<ListInstance> listInstances(const std::string& path) = 0;
Václav Kubernáte7a9fa32018-08-22 13:56:35 +020076};