blob: f084a2d2d3ee0526150be66b5c8308e2cba89b37 [file] [log] [blame]
Václav Kubernát48e9dfa2020-07-08 10:55:12 +02001/*
2 * Copyright (C) 2020 CESNET, https://photonics.cesnet.cz/
3 *
4 * Written by Václav Kubernát <kubernat@cesnet.cz>
5 *
6*/
7
8#pragma once
9#include "datastore_access.hpp"
Václav Kubernáte7248b22020-06-26 15:38:59 +020010#include "yang_access.hpp"
Václav Kubernát48e9dfa2020-07-08 10:55:12 +020011
12/*! \class ProxyDatastore
13 * \brief DatastoreAccess wrapper that handles RPC input
14 */
15class ProxyDatastore {
16public:
Václav Kubernáte7248b22020-06-26 15:38:59 +020017 /**
18 * The createTemporaryDatastore function should create a temporary datastore that's going to be used for RPC input.
19 * This temporary datastore and the main datastore are supposed share the same schemas.
20 * */
21 ProxyDatastore(const std::shared_ptr<DatastoreAccess>& datastore, std::function<std::shared_ptr<DatastoreAccess>(const std::shared_ptr<DatastoreAccess>&)> createTemporaryDatastore);
Václav Kubernát48e9dfa2020-07-08 10:55:12 +020022 [[nodiscard]] DatastoreAccess::Tree getItems(const std::string& path) const;
23 void setLeaf(const std::string& path, leaf_data_ value);
24 void createItem(const std::string& path);
25 void deleteItem(const std::string& path);
26 void moveItem(const std::string& source, std::variant<yang::move::Absolute, yang::move::Relative> move);
27 void commitChanges();
28 void discardChanges();
29 void copyConfig(const Datastore source, const Datastore destination);
30 [[nodiscard]] std::string dump(const DataFormat format) const;
31
Václav Kubernátb3960f82020-12-01 03:21:48 +010032 void initiate(const std::string& path);
Václav Kubernátaa4250a2020-07-22 00:02:23 +020033 [[nodiscard]] DatastoreAccess::Tree execute();
34 void cancel();
Václav Kubernáte7248b22020-06-26 15:38:59 +020035
Václav Kubernát2bed9522020-12-01 03:37:41 +010036 std::optional<std::string> inputDatastorePath();
37
Václav Kubernát48e9dfa2020-07-08 10:55:12 +020038 [[nodiscard]] std::shared_ptr<Schema> schema() const;
Václav Kubernátb4e5b182020-11-16 19:55:09 +010039
Václav Kubernát48e9dfa2020-07-08 10:55:12 +020040private:
Václav Kubernáte7248b22020-06-26 15:38:59 +020041 /** @brief Picks a datastore based on the requested path.
42 *
43 * If the path starts with a currently processed RPC, m_inputDatastore is picked.
44 * Otherwise m_datastore is picked.
45 */
46 [[nodiscard]] std::shared_ptr<DatastoreAccess> pickDatastore(const std::string& path) const;
47
Václav Kubernát48e9dfa2020-07-08 10:55:12 +020048 std::shared_ptr<DatastoreAccess> m_datastore;
Václav Kubernáte7248b22020-06-26 15:38:59 +020049 std::function<std::shared_ptr<DatastoreAccess>(const std::shared_ptr<DatastoreAccess>&)> m_createTemporaryDatastore;
50 std::shared_ptr<DatastoreAccess> m_inputDatastore;
Václav Kubernátaa4250a2020-07-22 00:02:23 +020051
Václav Kubernát2bed9522020-12-01 03:37:41 +010052 std::optional<std::string> m_inputPath;
Václav Kubernát48e9dfa2020-07-08 10:55:12 +020053};