blob: 63df0bba56e273383269513c81bd2da42d9f1b11 [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>
Václav Kubernátc58e4aa2019-04-03 18:37:32 +020012#include <optional>
Václav Kubernáte7a9fa32018-08-22 13:56:35 +020013#include <string>
Václav Kubernát6a7dd4d2020-06-23 22:44:13 +020014#include "yang_operations.hpp"
Václav Kubernáte7a9fa32018-08-22 13:56:35 +020015#include "ast_values.hpp"
Václav Kubernáta93f9002020-05-28 03:09:42 +020016#include "list_instance.hpp"
Václav Kubernáte7a9fa32018-08-22 13:56:35 +020017
18/*! \class DatastoreAccess
19 * \brief Abstract class for accessing a datastore
20 */
21
Václav Kubernátc58e4aa2019-04-03 18:37:32 +020022struct DatastoreError {
23 std::string message;
24 std::optional<std::string> xpath;
25
Václav Kubernát74487df2020-06-04 01:29:28 +020026 DatastoreError(const std::string& message, const std::optional<std::string>& xpath = std::nullopt);
Václav Kubernátc58e4aa2019-04-03 18:37:32 +020027};
28
29class DatastoreException : std::exception {
30public:
31 DatastoreException(const std::vector<DatastoreError>& errors);
32 ~DatastoreException() override = default;
Václav Kubernát59e4ee42020-07-08 17:32:45 +020033 [[nodiscard]] const char* what() const noexcept override;
Václav Kubernátc58e4aa2019-04-03 18:37:32 +020034
35private:
36 std::string m_what;
37};
Václav Kubernáte7a9fa32018-08-22 13:56:35 +020038
Jan Kundrát77d9f612019-09-03 16:52:32 +020039class Schema;
40
Václav Kubernátbf65dd72020-05-28 02:32:31 +020041struct dataPath_;
42
Václav Kubernáte7a9fa32018-08-22 13:56:35 +020043class DatastoreAccess {
44public:
Václav Kubernátcf9224f2020-06-02 09:55:29 +020045 using Tree = std::vector<std::pair<std::string, leaf_data_>>;
Václav Kubernáte7a9fa32018-08-22 13:56:35 +020046 virtual ~DatastoreAccess() = 0;
Václav Kubernát59e4ee42020-07-08 17:32:45 +020047 [[nodiscard]] virtual Tree getItems(const std::string& path) const = 0;
Václav Kubernáte7a9fa32018-08-22 13:56:35 +020048 virtual void setLeaf(const std::string& path, leaf_data_ value) = 0;
Jan Kundrátcbf288b2020-06-18 20:44:39 +020049 virtual void createItem(const std::string& path) = 0;
50 virtual void deleteItem(const std::string& path) = 0;
Václav Kubernátbf65dd72020-05-28 02:32:31 +020051 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 +010052 virtual Tree executeRpc(const std::string& path, const Tree& input) = 0;
Václav Kubernáta8789602020-07-20 15:18:19 +020053 virtual Tree executeAction(const std::string& path, const Tree& input) = 0;
Václav Kubernát812ee282018-08-30 17:10:03 +020054
Jan Kundrát77d9f612019-09-03 16:52:32 +020055 virtual std::shared_ptr<Schema> schema() = 0;
56
Václav Kubernát812ee282018-08-30 17:10:03 +020057 virtual void commitChanges() = 0;
Václav Kubernát6d791432018-10-25 16:00:35 +020058 virtual void discardChanges() = 0;
Václav Kubernát7160a132020-04-03 02:11:01 +020059 virtual void copyConfig(const Datastore source, const Datastore destination) = 0;
Václav Kubernát59e4ee42020-07-08 17:32:45 +020060 [[nodiscard]] virtual std::string dump(const DataFormat format) const = 0;
Václav Kubernátab612e92019-11-26 19:51:31 +010061
62private:
63 friend class DataQuery;
64 virtual std::vector<ListInstance> listInstances(const std::string& path) = 0;
Václav Kubernáte7a9fa32018-08-22 13:56:35 +020065};