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(); |
| 24 | ~YangAccess() override; |
Václav Kubernát | d628291 | 2020-06-23 14:49:34 +0200 | [diff] [blame^] | 25 | Tree getItems(const std::string& path) const override; |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 26 | void setLeaf(const std::string& path, leaf_data_ value) override; |
| 27 | void createItem(const std::string& path) override; |
| 28 | void deleteItem(const std::string& path) override; |
| 29 | void moveItem(const std::string& source, std::variant<yang::move::Absolute, yang::move::Relative> move) override; |
| 30 | void commitChanges() override; |
| 31 | void discardChanges() override; |
| 32 | Tree executeRpc(const std::string& path, const Tree& input) override; |
| 33 | void copyConfig(const Datastore source, const Datastore destination) override; |
| 34 | |
| 35 | std::shared_ptr<Schema> schema() override; |
| 36 | |
| 37 | void enableFeature(const std::string& module, const std::string& feature); |
| 38 | std::string dumpXML() const; |
| 39 | std::string dumpJSON() const; |
| 40 | |
| 41 | void addSchemaFile(const std::string& path); |
| 42 | void addSchemaDir(const std::string& path); |
| 43 | |
| 44 | private: |
| 45 | std::vector<ListInstance> listInstances(const std::string& path) override; |
| 46 | |
| 47 | [[noreturn]] void getErrorsAndThrow() const; |
| 48 | void impl_newPath(const std::string& path, const std::optional<std::string>& value = std::nullopt); |
| 49 | void impl_removeNode(const std::string& path); |
| 50 | void validate(); |
| 51 | |
| 52 | std::unique_ptr<ly_ctx, void(*)(ly_ctx*)> m_ctx; |
| 53 | std::unique_ptr<lyd_node, void(*)(lyd_node*)> m_datastore; |
| 54 | std::shared_ptr<YangSchema> m_schema; |
| 55 | }; |