Václav Kubernát | 48e9dfa | 2020-07-08 10:55:12 +0200 | [diff] [blame] | 1 | /* |
| 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át | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 10 | #include "yang_access.hpp" |
Václav Kubernát | 48e9dfa | 2020-07-08 10:55:12 +0200 | [diff] [blame] | 11 | |
| 12 | /*! \class ProxyDatastore |
| 13 | * \brief DatastoreAccess wrapper that handles RPC input |
| 14 | */ |
| 15 | class ProxyDatastore { |
| 16 | public: |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 17 | /** |
| 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át | 48e9dfa | 2020-07-08 10:55:12 +0200 | [diff] [blame] | 22 | [[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; |
Václav Kubernát | e066fe2 | 2022-04-06 00:32:26 +0200 | [diff] [blame] | 31 | DatastoreTarget target() const; |
Václav Kubernát | 162165e | 2021-02-22 09:46:53 +0100 | [diff] [blame] | 32 | void setTarget(const DatastoreTarget target); |
Václav Kubernát | 48e9dfa | 2020-07-08 10:55:12 +0200 | [diff] [blame] | 33 | |
Václav Kubernát | b3960f8 | 2020-12-01 03:21:48 +0100 | [diff] [blame] | 34 | void initiate(const std::string& path); |
Václav Kubernát | aa4250a | 2020-07-22 00:02:23 +0200 | [diff] [blame] | 35 | [[nodiscard]] DatastoreAccess::Tree execute(); |
| 36 | void cancel(); |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 37 | |
aleskucera@cesnet.cz | 8f4fe8f | 2023-10-27 13:09:29 +0200 | [diff] [blame] | 38 | std::optional<std::string> inputDatastorePath() const; |
Václav Kubernát | 2bed952 | 2020-12-01 03:37:41 +0100 | [diff] [blame] | 39 | |
Václav Kubernát | 48e9dfa | 2020-07-08 10:55:12 +0200 | [diff] [blame] | 40 | [[nodiscard]] std::shared_ptr<Schema> schema() const; |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 41 | |
Václav Kubernát | 48e9dfa | 2020-07-08 10:55:12 +0200 | [diff] [blame] | 42 | private: |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 43 | /** @brief Picks a datastore based on the requested path. |
| 44 | * |
| 45 | * If the path starts with a currently processed RPC, m_inputDatastore is picked. |
| 46 | * Otherwise m_datastore is picked. |
| 47 | */ |
| 48 | [[nodiscard]] std::shared_ptr<DatastoreAccess> pickDatastore(const std::string& path) const; |
| 49 | |
Václav Kubernát | 48e9dfa | 2020-07-08 10:55:12 +0200 | [diff] [blame] | 50 | std::shared_ptr<DatastoreAccess> m_datastore; |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 51 | std::function<std::shared_ptr<DatastoreAccess>(const std::shared_ptr<DatastoreAccess>&)> m_createTemporaryDatastore; |
| 52 | std::shared_ptr<DatastoreAccess> m_inputDatastore; |
Václav Kubernát | aa4250a | 2020-07-22 00:02:23 +0200 | [diff] [blame] | 53 | |
Václav Kubernát | 2bed952 | 2020-12-01 03:37:41 +0100 | [diff] [blame] | 54 | std::optional<std::string> m_inputPath; |
Václav Kubernát | 48e9dfa | 2020-07-08 10:55:12 +0200 | [diff] [blame] | 55 | }; |