Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/ |
| 3 | * Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/ |
| 4 | * |
| 5 | * Written by Václav Kubernát <kubervac@fit.cvut.cz> |
| 6 | * |
| 7 | */ |
| 8 | |
| 9 | #pragma once |
| 10 | |
Václav Kubernát | a6c5fff | 2018-09-07 15:16:25 +0200 | [diff] [blame] | 11 | #include <functional> |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 12 | #include <libyang-cpp/Context.hpp> |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 13 | #include <optional> |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 14 | #include <set> |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 15 | #include "ast_path.hpp" |
| 16 | #include "schema.hpp" |
| 17 | |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 18 | /*! \class YangSchema |
| 19 | * \brief A schema class, which uses libyang for queries. |
| 20 | * */ |
| 21 | class YangSchema : public Schema { |
| 22 | public: |
| 23 | YangSchema(); |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 24 | YangSchema(libyang::Context lyCtx); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 25 | ~YangSchema() override; |
| 26 | |
Václav Kubernát | 59e4ee4 | 2020-07-08 17:32:45 +0200 | [diff] [blame] | 27 | [[nodiscard]] yang::NodeTypes nodeType(const std::string& path) const override; |
| 28 | [[nodiscard]] yang::NodeTypes nodeType(const schemaPath_& location, const ModuleNodePair& node) const override; |
| 29 | [[nodiscard]] bool isModule(const std::string& name) const override; |
| 30 | [[nodiscard]] bool listHasKey(const schemaPath_& listPath, const std::string& key) const override; |
| 31 | [[nodiscard]] bool leafIsKey(const std::string& leafPath) const override; |
| 32 | [[nodiscard]] bool isConfig(const std::string& path) const override; |
| 33 | [[nodiscard]] std::optional<std::string> defaultValue(const std::string& leafPath) const override; |
| 34 | [[nodiscard]] const std::set<std::string> listKeys(const schemaPath_& listPath) const override; |
| 35 | [[nodiscard]] yang::TypeInfo leafType(const schemaPath_& location, const ModuleNodePair& node) const override; |
| 36 | [[nodiscard]] yang::TypeInfo leafType(const std::string& path) const override; |
Václav Kubernát | 76ba4ec | 2020-05-18 13:26:56 +0200 | [diff] [blame] | 37 | /** @brief If the leaf type is a typedef, returns the typedef name. */ |
Václav Kubernát | 59e4ee4 | 2020-07-08 17:32:45 +0200 | [diff] [blame] | 38 | [[nodiscard]] std::optional<std::string> leafTypeName(const std::string& path) const override; |
| 39 | [[nodiscard]] std::string leafrefPath(const std::string& leafrefPath) const override; |
| 40 | [[nodiscard]] std::set<ModuleNodePair> availableNodes(const boost::variant<dataPath_, schemaPath_, module_>& path, const Recursion recursion) const override; |
| 41 | [[nodiscard]] std::optional<std::string> description(const std::string& path) const override; |
| 42 | [[nodiscard]] yang::Status status(const std::string& location) const override; |
Václav Kubernát | d8408e0 | 2020-12-02 05:13:27 +0100 | [diff] [blame] | 43 | [[nodiscard]] bool hasInputNodes(const std::string& path) const override; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 44 | |
Jan Kundrát | f59b83c | 2022-03-18 18:12:08 +0100 | [diff] [blame] | 45 | void registerModuleCallback(const std::function<std::string(const std::string_view, const std::optional<std::string_view>, const std::optional<std::string_view>, const std::optional<std::string_view>)>& clb); |
Václav Kubernát | a6c5fff | 2018-09-07 15:16:25 +0200 | [diff] [blame] | 46 | |
| 47 | /** @short Loads a module called moduleName. */ |
| 48 | void loadModule(const std::string& moduleName); |
| 49 | |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 50 | /** @short Sets enabled features. */ |
| 51 | void setEnabledFeatures(const std::string& moduleName, const std::vector<std::string>& features); |
Václav Kubernát | bf9c611 | 2019-11-04 16:03:35 +0100 | [diff] [blame] | 52 | |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 53 | /** @short Adds a new module passed as a YANG string. */ |
| 54 | void addSchemaString(const char* schema); |
| 55 | |
| 56 | /** @short Adds a new module from a file. */ |
| 57 | void addSchemaFile(const char* filename); |
| 58 | |
| 59 | /** @short Adds a new directory for schema lookup. */ |
| 60 | void addSchemaDirectory(const char* directoryName); |
| 61 | |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 62 | /** @short Creates a new data node from a path (to be used with NETCONF edit-config) */ |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 63 | [[nodiscard]] libyang::CreatedNodes dataNodeFromPath(const std::string& path, const std::optional<const std::string> value = std::nullopt) const; |
| 64 | std::optional<libyang::Module> getYangModule(const std::string& name); |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 65 | |
Václav Kubernát | a878960 | 2020-07-20 15:18:19 +0200 | [diff] [blame] | 66 | [[nodiscard]] std::string dataPathToSchemaPath(const std::string& path); |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 67 | |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 68 | private: |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 69 | friend class YangAccess; |
Václav Kubernát | 5b8a8f3 | 2020-05-20 00:57:22 +0200 | [diff] [blame] | 70 | template <typename NodeType> |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 71 | [[nodiscard]] yang::TypeInfo impl_leafType(const NodeType& node) const; |
Václav Kubernát | 59e4ee4 | 2020-07-08 17:32:45 +0200 | [diff] [blame] | 72 | [[nodiscard]] std::set<std::string> modules() const; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 73 | |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 74 | |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 75 | /** @short Returns a single SchemaNode if the criteria matches only one, otherwise nullopt. */ |
| 76 | [[nodiscard]] std::optional<libyang::SchemaNode> getSchemaNode(const std::string& node) const; |
| 77 | /** @short Returns a single Schema_Node if the criteria matches only one, otherwise nullopt. */ |
| 78 | [[nodiscard]] std::optional<libyang::SchemaNode> getSchemaNode(const schemaPath_& listPath) const; |
Václav Kubernát | 47a3f67 | 2019-11-08 15:42:43 +0100 | [diff] [blame] | 79 | |
| 80 | /** @short Returns a single Schema_Node if the criteria matches only one, otherwise nullptr. */ |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 81 | [[nodiscard]] std::optional<libyang::SchemaNode> getSchemaNode(const schemaPath_& location, const ModuleNodePair& node) const; |
| 82 | libyang::Context m_context; |
Václav Kubernát | 47a3f67 | 2019-11-08 15:42:43 +0100 | [diff] [blame] | 83 | |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 84 | [[nodiscard]] std::optional<libyang::SchemaNode> impl_getSchemaNode(const std::string& node) const; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 85 | }; |