blob: f9ea9013b6ac2e0611cac70246397e271e4a02c7 [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"
Václav Kubernáta93f9002020-05-28 03:09:42 +020015#include "list_instance.hpp"
Václav Kubernáte7a9fa32018-08-22 13:56:35 +020016
17/*! \class DatastoreAccess
18 * \brief Abstract class for accessing a datastore
19 */
20
Václav Kubernátc58e4aa2019-04-03 18:37:32 +020021struct 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
28class DatastoreException : std::exception {
29public:
30 DatastoreException(const std::vector<DatastoreError>& errors);
31 ~DatastoreException() override = default;
32 const char* what() const noexcept override;
33
34private:
35 std::string m_what;
36};
Václav Kubernáte7a9fa32018-08-22 13:56:35 +020037
Jan Kundrát77d9f612019-09-03 16:52:32 +020038class Schema;
39
Václav Kubernáte7a9fa32018-08-22 13:56:35 +020040class DatastoreAccess {
41public:
Jan Kundrátb331b552020-01-23 15:25:29 +010042 using Tree = std::map<std::string, leaf_data_>;
Václav Kubernáte7a9fa32018-08-22 13:56:35 +020043 virtual ~DatastoreAccess() = 0;
Jan Kundrátb331b552020-01-23 15:25:29 +010044 virtual Tree getItems(const std::string& path) = 0;
Václav Kubernáte7a9fa32018-08-22 13:56:35 +020045 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átf5f64f02019-03-19 17:15:47 +010048 virtual void createListInstance(const std::string& path) = 0;
49 virtual void deleteListInstance(const std::string& path) = 0;
Václav Kubernát5b8a8f32020-05-20 00:57:22 +020050 virtual void createLeafListInstance(const std::string& path) = 0;
51 virtual void deleteLeafListInstance(const std::string& path) = 0;
Jan Kundrát6ee84792020-01-24 01:43:36 +010052 virtual Tree executeRpc(const std::string& path, const Tree& input) = 0;
Václav Kubernát812ee282018-08-30 17:10:03 +020053
Jan Kundrát77d9f612019-09-03 16:52:32 +020054 virtual std::shared_ptr<Schema> schema() = 0;
55
Václav Kubernát812ee282018-08-30 17:10:03 +020056 virtual void commitChanges() = 0;
Václav Kubernát6d791432018-10-25 16:00:35 +020057 virtual void discardChanges() = 0;
Václav Kubernát7160a132020-04-03 02:11:01 +020058 virtual void copyConfig(const Datastore source, const Datastore destination) = 0;
Václav Kubernátab612e92019-11-26 19:51:31 +010059
60private:
61 friend class DataQuery;
62 virtual std::vector<ListInstance> listInstances(const std::string& path) = 0;
Václav Kubernáte7a9fa32018-08-22 13:56:35 +020063};