blob: 6686b92adfac5dc355c3c0b9a84ff345c65d0816 [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>
14#include "ast_values.hpp"
15
16/*! \class DatastoreAccess
17 * \brief Abstract class for accessing a datastore
18 */
19
Václav Kubernátc58e4aa2019-04-03 18:37:32 +020020struct DatastoreError {
21 std::string message;
22 std::optional<std::string> xpath;
23
24 DatastoreError(const std::string& message, const std::optional<std::string>& xpath);
25};
26
27class DatastoreException : std::exception {
28public:
29 DatastoreException(const std::vector<DatastoreError>& errors);
30 ~DatastoreException() override = default;
31 const char* what() const noexcept override;
32
33private:
34 std::string m_what;
35};
Václav Kubernáte7a9fa32018-08-22 13:56:35 +020036
Jan Kundrát77d9f612019-09-03 16:52:32 +020037class Schema;
38
Václav Kubernátab612e92019-11-26 19:51:31 +010039using ListInstance = std::map<std::string, leaf_data_>;
40
Václav Kubernáte7a9fa32018-08-22 13:56:35 +020041class DatastoreAccess {
42public:
Jan Kundrátb331b552020-01-23 15:25:29 +010043 using Tree = std::map<std::string, leaf_data_>;
Václav Kubernáte7a9fa32018-08-22 13:56:35 +020044 virtual ~DatastoreAccess() = 0;
Jan Kundrátb331b552020-01-23 15:25:29 +010045 virtual Tree getItems(const std::string& path) = 0;
Václav Kubernáte7a9fa32018-08-22 13:56:35 +020046 virtual void setLeaf(const std::string& path, leaf_data_ value) = 0;
47 virtual void createPresenceContainer(const std::string& path) = 0;
48 virtual void deletePresenceContainer(const std::string& path) = 0;
Václav Kubernátf5f64f02019-03-19 17:15:47 +010049 virtual void createListInstance(const std::string& path) = 0;
50 virtual void deleteListInstance(const std::string& path) = 0;
Jan Kundrát6ee84792020-01-24 01:43:36 +010051 virtual Tree executeRpc(const std::string& path, const Tree& input) = 0;
Václav Kubernát812ee282018-08-30 17:10:03 +020052
Jan Kundrát77d9f612019-09-03 16:52:32 +020053 virtual std::shared_ptr<Schema> schema() = 0;
54
Václav Kubernát812ee282018-08-30 17:10:03 +020055 virtual void commitChanges() = 0;
Václav Kubernát6d791432018-10-25 16:00:35 +020056 virtual void discardChanges() = 0;
Václav Kubernátab612e92019-11-26 19:51:31 +010057
58private:
59 friend class DataQuery;
60 virtual std::vector<ListInstance> listInstances(const std::string& path) = 0;
Václav Kubernáte7a9fa32018-08-22 13:56:35 +020061};