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 | 34ee85a | 2020-02-18 17:12:12 +0100 | [diff] [blame] | 34 | yang::NodeTypes nodeType(const std::string& path) const override; |
| 35 | yang::NodeTypes nodeType(const schemaPath_& location, const ModuleNodePair& node) const override; |
Václav Kubernát | 75877de | 2019-11-20 17:43:02 +0100 | [diff] [blame] | 36 | bool isModule(const std::string& name) const override; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 37 | bool listHasKey(const schemaPath_& location, const ModuleNodePair& node, const std::string& key) const override; |
Václav Kubernát | c386679 | 2020-02-20 14:12:56 +0100 | [diff] [blame] | 38 | bool leafIsKey(const std::string& leafPath) const override; |
Václav Kubernát | 0599e9f | 2020-04-21 09:51:33 +0200 | [diff] [blame^] | 39 | bool isConfig(const std::string& path) const override; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 40 | const std::set<std::string> listKeys(const schemaPath_& location, const ModuleNodePair& node) const override; |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 41 | yang::TypeInfo leafType(const schemaPath_& location, const ModuleNodePair& node) const override; |
| 42 | yang::TypeInfo leafType(const std::string& path) const override; |
Václav Kubernát | 6fcd028 | 2020-02-21 16:33:08 +0100 | [diff] [blame] | 43 | std::optional<std::string> leafTypeName(const std::string& path) const override; |
Václav Kubernát | bd5e3c2 | 2020-02-19 15:22:00 +0100 | [diff] [blame] | 44 | std::string leafrefPath(const std::string& leafrefPath) const override; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 45 | std::set<std::string> childNodes(const schemaPath_& path, const Recursion recursion) const override; |
Václav Kubernát | 9456b5c | 2019-10-02 21:14:52 +0200 | [diff] [blame] | 46 | std::set<std::string> moduleNodes(const module_& module, const Recursion recursion) const override; |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 47 | std::optional<std::string> description(const std::string& path) const override; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 48 | |
Václav Kubernát | b52dc25 | 2019-12-04 13:03:39 +0100 | [diff] [blame] | 49 | 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] | 50 | |
| 51 | /** @short Loads a module called moduleName. */ |
| 52 | void loadModule(const std::string& moduleName); |
| 53 | |
Václav Kubernát | bf9c611 | 2019-11-04 16:03:35 +0100 | [diff] [blame] | 54 | /** @short Enables a feature called featureName on a module called moduleName. */ |
| 55 | void enableFeature(const std::string& moduleName, const std::string& featureName); |
| 56 | |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 57 | /** @short Adds a new module passed as a YANG string. */ |
| 58 | void addSchemaString(const char* schema); |
| 59 | |
| 60 | /** @short Adds a new module from a file. */ |
| 61 | void addSchemaFile(const char* filename); |
| 62 | |
| 63 | /** @short Adds a new directory for schema lookup. */ |
| 64 | void addSchemaDirectory(const char* directoryName); |
| 65 | |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 66 | /** @short Creates a new data node from a path (to be used with NETCONF edit-config) */ |
| 67 | std::shared_ptr<libyang::Data_Node> dataNodeFromPath(const std::string& path, const std::optional<const std::string> value = std::nullopt) const; |
| 68 | std::shared_ptr<libyang::Module> getYangModule(const std::string& name); |
| 69 | |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 70 | private: |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 71 | yang::TypeInfo impl_leafType(const std::shared_ptr<libyang::Schema_Node>& node) const; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 72 | std::set<std::string> modules() const; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 73 | |
| 74 | /** @short Returns a set of nodes, that match the location and name criteria. */ |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 75 | |
| 76 | /** @short Returns a single Schema_Node if the criteria matches only one, otherwise nullptr. */ |
Václav Kubernát | 47a3f67 | 2019-11-08 15:42:43 +0100 | [diff] [blame] | 77 | std::shared_ptr<libyang::Schema_Node> getSchemaNode(const std::string& node) const; |
| 78 | |
| 79 | /** @short Returns a single Schema_Node if the criteria matches only one, otherwise nullptr. */ |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 80 | 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] | 81 | std::shared_ptr<libyang::Context> m_context; |
Václav Kubernát | 47a3f67 | 2019-11-08 15:42:43 +0100 | [diff] [blame] | 82 | |
| 83 | 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] | 84 | }; |