blob: 503a077ab1bd4e15ad1f3db94b9f7b074e876a16 [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();
Václav Kubernáte7248b22020-06-26 15:38:59 +020024 YangAccess(std::shared_ptr<YangSchema> schema);
Václav Kubernát74487df2020-06-04 01:29:28 +020025 ~YangAccess() override;
Václav Kubernát59e4ee42020-07-08 17:32:45 +020026 [[nodiscard]] Tree getItems(const std::string& path) const override;
Václav Kubernát74487df2020-06-04 01:29:28 +020027 void setLeaf(const std::string& path, leaf_data_ value) override;
28 void createItem(const std::string& path) override;
29 void deleteItem(const std::string& path) override;
30 void moveItem(const std::string& source, std::variant<yang::move::Absolute, yang::move::Relative> move) override;
31 void commitChanges() override;
32 void discardChanges() override;
33 Tree executeRpc(const std::string& path, const Tree& input) override;
34 void copyConfig(const Datastore source, const Datastore destination) override;
35
36 std::shared_ptr<Schema> schema() override;
37
38 void enableFeature(const std::string& module, const std::string& feature);
Václav Kubernát59e4ee42020-07-08 17:32:45 +020039 [[nodiscard]] std::string dump(const DataFormat format) const override;
Václav Kubernát74487df2020-06-04 01:29:28 +020040
Václav Kubernát619e6542020-06-29 14:13:43 +020041 void loadModule(const std::string& name);
Václav Kubernát74487df2020-06-04 01:29:28 +020042 void addSchemaFile(const std::string& path);
43 void addSchemaDir(const std::string& path);
Václav Kubernát548cb192020-06-26 14:00:42 +020044 void addDataFile(const std::string& path);
Václav Kubernát74487df2020-06-04 01:29:28 +020045
46private:
47 std::vector<ListInstance> listInstances(const std::string& path) override;
48
49 [[noreturn]] void getErrorsAndThrow() const;
50 void impl_newPath(const std::string& path, const std::optional<std::string>& value = std::nullopt);
51 void impl_removeNode(const std::string& path);
52 void validate();
53
54 std::unique_ptr<ly_ctx, void(*)(ly_ctx*)> m_ctx;
55 std::unique_ptr<lyd_node, void(*)(lyd_node*)> m_datastore;
56 std::shared_ptr<YangSchema> m_schema;
Václav Kubernáte7248b22020-06-26 15:38:59 +020057 const int m_validation_mode;
Václav Kubernát74487df2020-06-04 01:29:28 +020058};