blob: ab948cff2c5be4aea747296a85ffe15167201ed8 [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;
Václav Kubernáta8789602020-07-20 15:18:19 +020034 Tree executeAction(const std::string& path, const Tree& input) override;
Václav Kubernát74487df2020-06-04 01:29:28 +020035 void copyConfig(const Datastore source, const Datastore destination) override;
36
37 std::shared_ptr<Schema> schema() override;
38
39 void enableFeature(const std::string& module, const std::string& feature);
Václav Kubernát59e4ee42020-07-08 17:32:45 +020040 [[nodiscard]] std::string dump(const DataFormat format) const override;
Václav Kubernát74487df2020-06-04 01:29:28 +020041
Václav Kubernát619e6542020-06-29 14:13:43 +020042 void loadModule(const std::string& name);
Václav Kubernát74487df2020-06-04 01:29:28 +020043 void addSchemaFile(const std::string& path);
44 void addSchemaDir(const std::string& path);
Václav Kubernát548cb192020-06-26 14:00:42 +020045 void addDataFile(const std::string& path);
Václav Kubernát74487df2020-06-04 01:29:28 +020046
47private:
48 std::vector<ListInstance> listInstances(const std::string& path) override;
Václav Kubernáta8789602020-07-20 15:18:19 +020049 [[noreturn]] void impl_execute(const std::string& type, const std::string& path, const Tree& input);
Václav Kubernát74487df2020-06-04 01:29:28 +020050
51 [[noreturn]] void getErrorsAndThrow() const;
52 void impl_newPath(const std::string& path, const std::optional<std::string>& value = std::nullopt);
53 void impl_removeNode(const std::string& path);
54 void validate();
55
56 std::unique_ptr<ly_ctx, void(*)(ly_ctx*)> m_ctx;
57 std::unique_ptr<lyd_node, void(*)(lyd_node*)> m_datastore;
58 std::shared_ptr<YangSchema> m_schema;
Václav Kubernáte7248b22020-06-26 15:38:59 +020059 const int m_validation_mode;
Václav Kubernát74487df2020-06-04 01:29:28 +020060};