Václav Kubernát | 74487df | 2020-06-04 01:29:28 +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 | |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 10 | #include <libyang-cpp/Context.hpp> |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 11 | #include "datastore_access.hpp" |
| 12 | |
| 13 | /*! \class YangAccess |
| 14 | * \brief Implementation of DatastoreAccess with a local libyang data node instance |
| 15 | */ |
| 16 | |
Václav Kubernát | 0c90dd4 | 2022-01-18 00:07:29 +0100 | [diff] [blame] | 17 | enum class StrictDataParsing { |
| 18 | Yes, |
| 19 | No |
| 20 | }; |
| 21 | |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 22 | class YangSchema; |
| 23 | |
| 24 | struct ly_ctx; |
| 25 | struct lyd_node; |
| 26 | |
| 27 | class YangAccess : public DatastoreAccess { |
| 28 | public: |
| 29 | YangAccess(); |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 30 | YangAccess(std::shared_ptr<YangSchema> schema); |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 31 | ~YangAccess() override; |
Václav Kubernát | 59e4ee4 | 2020-07-08 17:32:45 +0200 | [diff] [blame] | 32 | [[nodiscard]] Tree getItems(const std::string& path) const override; |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 33 | void setLeaf(const std::string& path, leaf_data_ value) override; |
| 34 | void createItem(const std::string& path) override; |
| 35 | void deleteItem(const std::string& path) override; |
| 36 | void moveItem(const std::string& source, std::variant<yang::move::Absolute, yang::move::Relative> move) override; |
| 37 | void commitChanges() override; |
| 38 | void discardChanges() override; |
Václav Kubernát | b3960f8 | 2020-12-01 03:21:48 +0100 | [diff] [blame] | 39 | [[noreturn]] Tree execute(const std::string& path, const Tree& input) override; |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 40 | void copyConfig(const Datastore source, const Datastore destination) override; |
| 41 | |
| 42 | std::shared_ptr<Schema> schema() override; |
| 43 | |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 44 | void setEnabledFeatures(const std::string& module, const std::vector<std::string>& features); |
Václav Kubernát | 59e4ee4 | 2020-07-08 17:32:45 +0200 | [diff] [blame] | 45 | [[nodiscard]] std::string dump(const DataFormat format) const override; |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 46 | |
Václav Kubernát | 619e654 | 2020-06-29 14:13:43 +0200 | [diff] [blame] | 47 | void loadModule(const std::string& name); |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 48 | void addSchemaFile(const std::string& path); |
| 49 | void addSchemaDir(const std::string& path); |
Václav Kubernát | 0c90dd4 | 2022-01-18 00:07:29 +0100 | [diff] [blame] | 50 | void addDataFile(const std::string& path, const StrictDataParsing strict); |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 51 | |
| 52 | private: |
| 53 | std::vector<ListInstance> listInstances(const std::string& path) override; |
Václav Kubernát | a878960 | 2020-07-20 15:18:19 +0200 | [diff] [blame] | 54 | [[noreturn]] void impl_execute(const std::string& type, const std::string& path, const Tree& input); |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 55 | |
| 56 | [[noreturn]] void getErrorsAndThrow() const; |
| 57 | void impl_newPath(const std::string& path, const std::optional<std::string>& value = std::nullopt); |
| 58 | void impl_removeNode(const std::string& path); |
| 59 | void validate(); |
| 60 | |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 61 | libyang::Context m_ctx; |
| 62 | std::optional<libyang::DataNode> m_datastore; |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 63 | std::shared_ptr<YangSchema> m_schema; |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 64 | }; |