blob: baeb46635a28612b4c85ff6071ccb8d3dffe47c6 [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át0d4db442018-07-18 17:18:43 +020012#include <set>
13#include <stdexcept>
14#include <unordered_map>
15#include "ast_path.hpp"
16#include "schema.hpp"
17
Jan Kundrát4ed0e9f2018-08-23 16:56:58 +020018namespace libyang {
Václav Kubernát0d4db442018-07-18 17:18:43 +020019class Context;
20class Set;
21class Schema_Node;
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();
30 ~YangSchema() override;
31
Václav Kubernát2eaceb82018-10-08 19:56:30 +020032 bool isContainer(const schemaPath_& location, const ModuleNodePair& node) const override;
33 bool isLeaf(const schemaPath_& location, const ModuleNodePair& node) const override;
34 bool isModule(const schemaPath_& location, const std::string& name) const override;
35 bool isList(const schemaPath_& location, const ModuleNodePair& node) const override;
36 bool isPresenceContainer(const schemaPath_& location, const ModuleNodePair& node) const override;
37 bool leafEnumHasValue(const schemaPath_& location, const ModuleNodePair& node, const std::string& value) const override;
Václav Kubernáteeb38842019-03-20 19:46:05 +010038 bool leafIdentityIsValid(const schemaPath_& location, const ModuleNodePair& node, const ModuleValuePair& value) const override;
Václav Kubernát2eaceb82018-10-08 19:56:30 +020039 bool listHasKey(const schemaPath_& location, const ModuleNodePair& node, const std::string& key) const override;
Václav Kubernát2eaceb82018-10-08 19:56:30 +020040 const std::set<std::string> listKeys(const schemaPath_& location, const ModuleNodePair& node) const override;
41 yang::LeafDataTypes leafType(const schemaPath_& location, const ModuleNodePair& node) const override;
Václav Kubernáteeb38842019-03-20 19:46:05 +010042 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 +010043 const std::set<std::string> enumValues(const schemaPath_& location, const ModuleNodePair& node) const override;
Václav Kubernát2eaceb82018-10-08 19:56:30 +020044 std::set<std::string> childNodes(const schemaPath_& path, const Recursion recursion) const override;
Václav Kubernát0d4db442018-07-18 17:18:43 +020045
Václav Kubernáta6c5fff2018-09-07 15:16:25 +020046 void registerModuleCallback(const std::function<std::string(const char*, const char*, const char*)>& clb);
47
48 /** @short Loads a module called moduleName. */
49 void loadModule(const std::string& moduleName);
50
Václav Kubernát0d4db442018-07-18 17:18:43 +020051 /** @short Adds a new module passed as a YANG string. */
52 void addSchemaString(const char* schema);
53
54 /** @short Adds a new module from a file. */
55 void addSchemaFile(const char* filename);
56
57 /** @short Adds a new directory for schema lookup. */
58 void addSchemaDirectory(const char* directoryName);
59
60private:
61 std::set<std::string> modules() const;
Václav Kubernát0d4db442018-07-18 17:18:43 +020062
63 /** @short Returns a set of nodes, that match the location and name criteria. */
Václav Kubernát2eaceb82018-10-08 19:56:30 +020064 std::shared_ptr<libyang::Set> getNodeSet(const schemaPath_& location, const ModuleNodePair& node) const;
Václav Kubernát0d4db442018-07-18 17:18:43 +020065
66 /** @short Returns a single Schema_Node if the criteria matches only one, otherwise nullptr. */
Václav Kubernát2eaceb82018-10-08 19:56:30 +020067 std::shared_ptr<libyang::Schema_Node> getSchemaNode(const schemaPath_& location, const ModuleNodePair& node) const;
Jan Kundrát4ed0e9f2018-08-23 16:56:58 +020068 std::shared_ptr<libyang::Context> m_context;
Václav Kubernát0d4db442018-07-18 17:18:43 +020069};