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; |
| 19 | class Set; |
| 20 | class Schema_Node; |
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(); |
| 31 | ~YangSchema() override; |
| 32 | |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 33 | bool isContainer(const schemaPath_& location, const ModuleNodePair& node) const override; |
| 34 | bool isLeaf(const schemaPath_& location, const ModuleNodePair& node) const override; |
| 35 | bool isModule(const schemaPath_& location, const std::string& name) const override; |
| 36 | bool isList(const schemaPath_& location, const ModuleNodePair& node) const override; |
| 37 | bool isPresenceContainer(const schemaPath_& location, const ModuleNodePair& node) const override; |
| 38 | bool leafEnumHasValue(const schemaPath_& location, const ModuleNodePair& node, const std::string& value) const override; |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 39 | bool leafIdentityIsValid(const schemaPath_& location, const ModuleNodePair& node, const ModuleValuePair& value) const override; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 40 | bool listHasKey(const schemaPath_& location, const ModuleNodePair& node, const std::string& key) const override; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 41 | const std::set<std::string> listKeys(const schemaPath_& location, const ModuleNodePair& node) const override; |
| 42 | yang::LeafDataTypes leafType(const schemaPath_& location, const ModuleNodePair& node) const override; |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 43 | const std::set<std::string> validIdentities(const schemaPath_& location, const ModuleNodePair& node, const Prefixes prefixes) const override; |
Václav Kubernát | 989b5de | 2019-02-20 16:28:35 +0100 | [diff] [blame] | 44 | const std::set<std::string> enumValues(const schemaPath_& location, const ModuleNodePair& node) 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 | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 46 | |
Václav Kubernát | a6c5fff | 2018-09-07 15:16:25 +0200 | [diff] [blame] | 47 | void registerModuleCallback(const std::function<std::string(const char*, const char*, const char*)>& clb); |
| 48 | |
| 49 | /** @short Loads a module called moduleName. */ |
| 50 | void loadModule(const std::string& moduleName); |
| 51 | |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 52 | /** @short Adds a new module passed as a YANG string. */ |
| 53 | void addSchemaString(const char* schema); |
| 54 | |
| 55 | /** @short Adds a new module from a file. */ |
| 56 | void addSchemaFile(const char* filename); |
| 57 | |
| 58 | /** @short Adds a new directory for schema lookup. */ |
| 59 | void addSchemaDirectory(const char* directoryName); |
| 60 | |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 61 | /** @short Creates a new data node from a path (to be used with NETCONF edit-config) */ |
| 62 | std::shared_ptr<libyang::Data_Node> dataNodeFromPath(const std::string& path, const std::optional<const std::string> value = std::nullopt) const; |
| 63 | std::shared_ptr<libyang::Module> getYangModule(const std::string& name); |
| 64 | |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 65 | private: |
| 66 | std::set<std::string> modules() const; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 67 | |
| 68 | /** @short Returns a set of nodes, that match the location and name criteria. */ |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 69 | std::shared_ptr<libyang::Set> getNodeSet(const schemaPath_& location, const ModuleNodePair& node) const; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 70 | |
| 71 | /** @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] | 72 | 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] | 73 | std::shared_ptr<libyang::Context> m_context; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 74 | }; |