blob: a4c0b90e638294399815f52158529377de3c9e06 [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át3a99f002020-03-31 02:27:41 +020020class Schema_Node_Leaf;
Václav Kubernátc31bd602019-03-07 11:44:48 +010021class Data_Node;
22class Module;
Jan Kundrát4ed0e9f2018-08-23 16:56:58 +020023}
Václav Kubernát0d4db442018-07-18 17:18:43 +020024
25/*! \class YangSchema
26 * \brief A schema class, which uses libyang for queries.
27 * */
28class YangSchema : public Schema {
29public:
30 YangSchema();
Václav Kubernát1d50a5b2020-02-03 16:44:22 +010031 YangSchema(std::shared_ptr<libyang::Context> lyCtx);
Václav Kubernát0d4db442018-07-18 17:18:43 +020032 ~YangSchema() override;
33
Václav Kubernát34ee85a2020-02-18 17:12:12 +010034 yang::NodeTypes nodeType(const std::string& path) const override;
35 yang::NodeTypes nodeType(const schemaPath_& location, const ModuleNodePair& node) const override;
Václav Kubernát75877de2019-11-20 17:43:02 +010036 bool isModule(const std::string& name) const override;
Václav Kubernát2eaceb82018-10-08 19:56:30 +020037 bool listHasKey(const schemaPath_& location, const ModuleNodePair& node, const std::string& key) const override;
Václav Kubernátc3866792020-02-20 14:12:56 +010038 bool leafIsKey(const std::string& leafPath) const override;
Václav Kubernát0599e9f2020-04-21 09:51:33 +020039 bool isConfig(const std::string& path) const override;
Václav Kubernátb1a75c62020-04-21 15:20:16 +020040 std::optional<std::string> defaultValue(const std::string& leafPath) const override;
Václav Kubernát2eaceb82018-10-08 19:56:30 +020041 const std::set<std::string> listKeys(const schemaPath_& location, const ModuleNodePair& node) const override;
Václav Kubernát13b23d72020-04-16 21:49:51 +020042 yang::TypeInfo leafType(const schemaPath_& location, const ModuleNodePair& node) const override;
43 yang::TypeInfo leafType(const std::string& path) const override;
Václav Kubernát76ba4ec2020-05-18 13:26:56 +020044 /** @brief If the leaf type is a typedef, returns the typedef name. */
Václav Kubernát6fcd0282020-02-21 16:33:08 +010045 std::optional<std::string> leafTypeName(const std::string& path) const override;
Václav Kubernátbd5e3c22020-02-19 15:22:00 +010046 std::string leafrefPath(const std::string& leafrefPath) const override;
Václav Kubernát95b08872020-04-28 01:04:17 +020047 std::set<ModuleNodePair> availableNodes(const boost::variant<dataPath_, schemaPath_, module_>& path, const Recursion recursion) const override;
Václav Kubernát1e09bd62020-02-17 15:13:38 +010048 std::optional<std::string> description(const std::string& path) const override;
Václav Kubernáta1c4c9e2020-04-22 00:37:52 +020049 yang::Status status(const std::string& location) const override;
Václav Kubernát0d4db442018-07-18 17:18:43 +020050
Václav Kubernátb52dc252019-12-04 13:03:39 +010051 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 +020052
53 /** @short Loads a module called moduleName. */
54 void loadModule(const std::string& moduleName);
55
Václav Kubernátbf9c6112019-11-04 16:03:35 +010056 /** @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át0d4db442018-07-18 17:18:43 +020059 /** @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átc31bd602019-03-07 11:44:48 +010068 /** @short Creates a new data node from a path (to be used with NETCONF edit-config) */
69 std::shared_ptr<libyang::Data_Node> dataNodeFromPath(const std::string& path, const std::optional<const std::string> value = std::nullopt) const;
70 std::shared_ptr<libyang::Module> getYangModule(const std::string& name);
71
Václav Kubernát0d4db442018-07-18 17:18:43 +020072private:
Václav Kubernát13b23d72020-04-16 21:49:51 +020073 yang::TypeInfo impl_leafType(const std::shared_ptr<libyang::Schema_Node>& node) const;
Václav Kubernát0d4db442018-07-18 17:18:43 +020074 std::set<std::string> modules() const;
Václav Kubernát0d4db442018-07-18 17:18:43 +020075
76 /** @short Returns a set of nodes, that match the location and name criteria. */
Václav Kubernát0d4db442018-07-18 17:18:43 +020077
78 /** @short Returns a single Schema_Node if the criteria matches only one, otherwise nullptr. */
Václav Kubernát47a3f672019-11-08 15:42:43 +010079 std::shared_ptr<libyang::Schema_Node> getSchemaNode(const std::string& node) const;
80
81 /** @short Returns a single Schema_Node if the criteria matches only one, otherwise nullptr. */
Václav Kubernát2eaceb82018-10-08 19:56:30 +020082 std::shared_ptr<libyang::Schema_Node> getSchemaNode(const schemaPath_& location, const ModuleNodePair& node) const;
Jan Kundrát4ed0e9f2018-08-23 16:56:58 +020083 std::shared_ptr<libyang::Context> m_context;
Václav Kubernát47a3f672019-11-08 15:42:43 +010084
85 std::shared_ptr<libyang::Schema_Node> impl_getSchemaNode(const std::string& node) const;
Václav Kubernát0d4db442018-07-18 17:18:43 +020086};