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