blob: 9b8a443da5694fd991d71baff1e9472baf686f39 [file] [log] [blame]
Václav Kubernát74487df2020-06-04 01:29:28 +02001/*
2 * Copyright (C) 2020 CESNET, https://photonics.cesnet.cz/
3 *
4 * Written by Václav Kubernát <kubernat@cesnet.cz>
5 *
6*/
7
8#pragma once
9
10#include "datastore_access.hpp"
11
12/*! \class YangAccess
13 * \brief Implementation of DatastoreAccess with a local libyang data node instance
14 */
15
16class YangSchema;
17
18struct ly_ctx;
19struct lyd_node;
20
21class YangAccess : public DatastoreAccess {
22public:
23 YangAccess();
24 ~YangAccess() override;
Václav Kubernátd6282912020-06-23 14:49:34 +020025 Tree getItems(const std::string& path) const override;
Václav Kubernát74487df2020-06-04 01:29:28 +020026 void setLeaf(const std::string& path, leaf_data_ value) override;
27 void createItem(const std::string& path) override;
28 void deleteItem(const std::string& path) override;
29 void moveItem(const std::string& source, std::variant<yang::move::Absolute, yang::move::Relative> move) override;
30 void commitChanges() override;
31 void discardChanges() override;
32 Tree executeRpc(const std::string& path, const Tree& input) override;
33 void copyConfig(const Datastore source, const Datastore destination) override;
34
35 std::shared_ptr<Schema> schema() override;
36
37 void enableFeature(const std::string& module, const std::string& feature);
38 std::string dumpXML() const;
39 std::string dumpJSON() const;
40
41 void addSchemaFile(const std::string& path);
42 void addSchemaDir(const std::string& path);
43
44private:
45 std::vector<ListInstance> listInstances(const std::string& path) override;
46
47 [[noreturn]] void getErrorsAndThrow() const;
48 void impl_newPath(const std::string& path, const std::optional<std::string>& value = std::nullopt);
49 void impl_removeNode(const std::string& path);
50 void validate();
51
52 std::unique_ptr<ly_ctx, void(*)(ly_ctx*)> m_ctx;
53 std::unique_ptr<lyd_node, void(*)(lyd_node*)> m_datastore;
54 std::shared_ptr<YangSchema> m_schema;
55};