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