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