blob: 8a8826c73a507e482ff70a71f4aa40c153623b9b [file] [log] [blame]
Václav Kubernát0d4db442018-07-18 17:18:43 +02001/*
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áta6c5fff2018-09-07 15:16:25 +020011#include <functional>
Václav Kubernátc31bd602019-03-07 11:44:48 +010012#include <optional>
Václav Kubernát0d4db442018-07-18 17:18:43 +020013#include <set>
Václav Kubernát0d4db442018-07-18 17:18:43 +020014#include "ast_path.hpp"
15#include "schema.hpp"
16
Jan Kundrát4ed0e9f2018-08-23 16:56:58 +020017namespace libyang {
Václav Kubernát0d4db442018-07-18 17:18:43 +020018class Context;
Václav Kubernát0d4db442018-07-18 17:18:43 +020019class Schema_Node;
Václav Kubernátc31bd602019-03-07 11:44:48 +010020class Data_Node;
21class Module;
Jan Kundrát4ed0e9f2018-08-23 16:56:58 +020022}
Václav Kubernát0d4db442018-07-18 17:18:43 +020023
24/*! \class YangSchema
25 * \brief A schema class, which uses libyang for queries.
26 * */
27class YangSchema : public Schema {
28public:
29 YangSchema();
Václav Kubernát1d50a5b2020-02-03 16:44:22 +010030 YangSchema(std::shared_ptr<libyang::Context> lyCtx);
Václav Kubernát0d4db442018-07-18 17:18:43 +020031 ~YangSchema() override;
32
Václav Kubernát34ee85a2020-02-18 17:12:12 +010033 yang::NodeTypes nodeType(const std::string& path) const override;
34 yang::NodeTypes nodeType(const schemaPath_& location, const ModuleNodePair& node) const override;
Václav Kubernát75877de2019-11-20 17:43:02 +010035 bool isModule(const std::string& name) const override;
Václav Kubernát2eaceb82018-10-08 19:56:30 +020036 bool leafEnumHasValue(const schemaPath_& location, const ModuleNodePair& node, const std::string& value) const override;
Václav Kubernáteeb38842019-03-20 19:46:05 +010037 bool leafIdentityIsValid(const schemaPath_& location, const ModuleNodePair& node, const ModuleValuePair& value) const override;
Václav Kubernát2eaceb82018-10-08 19:56:30 +020038 bool listHasKey(const schemaPath_& location, const ModuleNodePair& node, const std::string& key) const override;
Václav Kubernát2eaceb82018-10-08 19:56:30 +020039 const std::set<std::string> listKeys(const schemaPath_& location, const ModuleNodePair& node) const override;
40 yang::LeafDataTypes leafType(const schemaPath_& location, const ModuleNodePair& node) const override;
Václav Kubernát9bf36852020-02-18 17:47:56 +010041 yang::LeafDataTypes leafType(const std::string& path) const override;
Václav Kubernát6a8d1d92019-04-24 20:30:36 +020042 yang::LeafDataTypes leafrefBase(const schemaPath_& location, const ModuleNodePair& node) const override;
Václav Kubernáteeb38842019-03-20 19:46:05 +010043 const std::set<std::string> validIdentities(const schemaPath_& location, const ModuleNodePair& node, const Prefixes prefixes) const override;
Václav Kubernát989b5de2019-02-20 16:28:35 +010044 const std::set<std::string> enumValues(const schemaPath_& location, const ModuleNodePair& node) const override;
Václav Kubernát2eaceb82018-10-08 19:56:30 +020045 std::set<std::string> childNodes(const schemaPath_& path, const Recursion recursion) const override;
Václav Kubernát9456b5c2019-10-02 21:14:52 +020046 std::set<std::string> moduleNodes(const module_& module, const Recursion recursion) const override;
Václav Kubernát1e09bd62020-02-17 15:13:38 +010047 std::optional<std::string> description(const std::string& path) const override;
48 std::optional<std::string> units(const std::string& path) const override;
Václav Kubernát0d4db442018-07-18 17:18:43 +020049
Václav Kubernátb52dc252019-12-04 13:03:39 +010050 void registerModuleCallback(const std::function<std::string(const char*, const char*, const char*, const char*)>& clb);
Václav Kubernáta6c5fff2018-09-07 15:16:25 +020051
52 /** @short Loads a module called moduleName. */
53 void loadModule(const std::string& moduleName);
54
Václav Kubernátbf9c6112019-11-04 16:03:35 +010055 /** @short Enables a feature called featureName on a module called moduleName. */
56 void enableFeature(const std::string& moduleName, const std::string& featureName);
57
Václav Kubernát0d4db442018-07-18 17:18:43 +020058 /** @short Adds a new module passed as a YANG string. */
59 void addSchemaString(const char* schema);
60
61 /** @short Adds a new module from a file. */
62 void addSchemaFile(const char* filename);
63
64 /** @short Adds a new directory for schema lookup. */
65 void addSchemaDirectory(const char* directoryName);
66
Václav Kubernátc31bd602019-03-07 11:44:48 +010067 /** @short Creates a new data node from a path (to be used with NETCONF edit-config) */
68 std::shared_ptr<libyang::Data_Node> dataNodeFromPath(const std::string& path, const std::optional<const std::string> value = std::nullopt) const;
69 std::shared_ptr<libyang::Module> getYangModule(const std::string& name);
70
Václav Kubernát0d4db442018-07-18 17:18:43 +020071private:
72 std::set<std::string> modules() const;
Václav Kubernát0d4db442018-07-18 17:18:43 +020073
74 /** @short Returns a set of nodes, that match the location and name criteria. */
Václav Kubernát0d4db442018-07-18 17:18:43 +020075
76 /** @short Returns a single Schema_Node if the criteria matches only one, otherwise nullptr. */
Václav Kubernát47a3f672019-11-08 15:42:43 +010077 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át2eaceb82018-10-08 19:56:30 +020080 std::shared_ptr<libyang::Schema_Node> getSchemaNode(const schemaPath_& location, const ModuleNodePair& node) const;
Jan Kundrát4ed0e9f2018-08-23 16:56:58 +020081 std::shared_ptr<libyang::Context> m_context;
Václav Kubernát47a3f672019-11-08 15:42:43 +010082
83 std::shared_ptr<libyang::Schema_Node> impl_getSchemaNode(const std::string& node) const;
Václav Kubernát0d4db442018-07-18 17:18:43 +020084};