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 | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 12 | #include <set> |
| 13 | #include <stdexcept> |
| 14 | #include <unordered_map> |
| 15 | #include "ast_path.hpp" |
| 16 | #include "schema.hpp" |
| 17 | |
Jan Kundrát | 4ed0e9f | 2018-08-23 16:56:58 +0200 | [diff] [blame] | 18 | namespace libyang { |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 19 | class Context; |
| 20 | class Set; |
| 21 | class Schema_Node; |
Jan Kundrát | 4ed0e9f | 2018-08-23 16:56:58 +0200 | [diff] [blame] | 22 | } |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 23 | |
| 24 | /*! \class YangSchema |
| 25 | * \brief A schema class, which uses libyang for queries. |
| 26 | * */ |
| 27 | class YangSchema : public Schema { |
| 28 | public: |
| 29 | YangSchema(); |
| 30 | ~YangSchema() override; |
| 31 | |
| 32 | bool isContainer(const path_& location, const ModuleNodePair& node) const override; |
| 33 | bool isLeaf(const path_& location, const ModuleNodePair& node) const override; |
| 34 | bool isModule(const path_& location, const std::string& name) const override; |
| 35 | bool isList(const path_& location, const ModuleNodePair& node) const override; |
| 36 | bool isPresenceContainer(const path_& location, const ModuleNodePair& node) const override; |
| 37 | bool leafEnumHasValue(const path_& location, const ModuleNodePair& node, const std::string& value) const override; |
| 38 | bool listHasKey(const path_& location, const ModuleNodePair& node, const std::string& key) const override; |
| 39 | bool nodeExists(const std::string& location, const std::string& node) const override; |
| 40 | const std::set<std::string> listKeys(const path_& location, const ModuleNodePair& node) const override; |
| 41 | yang::LeafDataTypes leafType(const path_& location, const ModuleNodePair& node) const override; |
Václav Kubernát | e7d4aea | 2018-09-11 18:15:48 +0200 | [diff] [blame] | 42 | std::set<std::string> childNodes(const path_& path, const Recursion recursion) const override; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 43 | |
Václav Kubernát | a6c5fff | 2018-09-07 15:16:25 +0200 | [diff] [blame] | 44 | void registerModuleCallback(const std::function<std::string(const char*, const char*, const char*)>& clb); |
| 45 | |
| 46 | /** @short Loads a module called moduleName. */ |
| 47 | void loadModule(const std::string& moduleName); |
| 48 | |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 49 | /** @short Adds a new module passed as a YANG string. */ |
| 50 | void addSchemaString(const char* schema); |
| 51 | |
| 52 | /** @short Adds a new module from a file. */ |
| 53 | void addSchemaFile(const char* filename); |
| 54 | |
| 55 | /** @short Adds a new directory for schema lookup. */ |
| 56 | void addSchemaDirectory(const char* directoryName); |
| 57 | |
| 58 | private: |
| 59 | std::set<std::string> modules() const; |
| 60 | bool nodeExists(const path_& location, const ModuleNodePair& node) const; |
| 61 | |
| 62 | /** @short Returns a set of nodes, that match the location and name criteria. */ |
Jan Kundrát | 4ed0e9f | 2018-08-23 16:56:58 +0200 | [diff] [blame] | 63 | std::shared_ptr<libyang::Set> getNodeSet(const path_& location, const ModuleNodePair& node) const; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 64 | |
| 65 | /** @short Returns a single Schema_Node if the criteria matches only one, otherwise nullptr. */ |
Jan Kundrát | 4ed0e9f | 2018-08-23 16:56:58 +0200 | [diff] [blame] | 66 | std::shared_ptr<libyang::Schema_Node> getSchemaNode(const path_& location, const ModuleNodePair& node) const; |
| 67 | std::shared_ptr<libyang::Context> m_context; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 68 | }; |