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; |
| 33 | Tree executeRpc(const std::string& path, const Tree& input) override; |
Václav Kubernát | a878960 | 2020-07-20 15:18:19 +0200 | [diff] [blame^] | 34 | Tree executeAction(const std::string& path, const Tree& input) override; |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 35 | void copyConfig(const Datastore source, const Datastore destination) override; |
| 36 | |
| 37 | std::shared_ptr<Schema> schema() override; |
| 38 | |
| 39 | void enableFeature(const std::string& module, const std::string& feature); |
Václav Kubernát | 59e4ee4 | 2020-07-08 17:32:45 +0200 | [diff] [blame] | 40 | [[nodiscard]] std::string dump(const DataFormat format) const override; |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 41 | |
Václav Kubernát | 619e654 | 2020-06-29 14:13:43 +0200 | [diff] [blame] | 42 | void loadModule(const std::string& name); |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 43 | void addSchemaFile(const std::string& path); |
| 44 | void addSchemaDir(const std::string& path); |
Václav Kubernát | 548cb19 | 2020-06-26 14:00:42 +0200 | [diff] [blame] | 45 | void addDataFile(const std::string& path); |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 46 | |
| 47 | private: |
| 48 | std::vector<ListInstance> listInstances(const std::string& path) override; |
Václav Kubernát | a878960 | 2020-07-20 15:18:19 +0200 | [diff] [blame^] | 49 | [[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] | 50 | |
| 51 | [[noreturn]] void getErrorsAndThrow() const; |
| 52 | void impl_newPath(const std::string& path, const std::optional<std::string>& value = std::nullopt); |
| 53 | void impl_removeNode(const std::string& path); |
| 54 | void validate(); |
| 55 | |
| 56 | std::unique_ptr<ly_ctx, void(*)(ly_ctx*)> m_ctx; |
| 57 | std::unique_ptr<lyd_node, void(*)(lyd_node*)> m_datastore; |
| 58 | std::shared_ptr<YangSchema> m_schema; |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 59 | const int m_validation_mode; |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 60 | }; |