blob: 075ba26f3b4c9ac2c78812c8df23e242b93fa04d [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át59e4ee42020-07-08 17:32:45 +020025 [[nodiscard]] 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);
Václav Kubernát59e4ee42020-07-08 17:32:45 +020038 [[nodiscard]] std::string dump(const DataFormat format) const override;
Václav Kubernát74487df2020-06-04 01:29:28 +020039
Václav Kubernát619e6542020-06-29 14:13:43 +020040 void loadModule(const std::string& name);
Václav Kubernát74487df2020-06-04 01:29:28 +020041 void addSchemaFile(const std::string& path);
42 void addSchemaDir(const std::string& path);
Václav Kubernát548cb192020-06-26 14:00:42 +020043 void addDataFile(const std::string& path);
Václav Kubernát74487df2020-06-04 01:29:28 +020044
45private:
46 std::vector<ListInstance> listInstances(const std::string& path) override;
47
48 [[noreturn]] void getErrorsAndThrow() const;
49 void impl_newPath(const std::string& path, const std::optional<std::string>& value = std::nullopt);
50 void impl_removeNode(const std::string& path);
51 void validate();
52
53 std::unique_ptr<ly_ctx, void(*)(ly_ctx*)> m_ctx;
54 std::unique_ptr<lyd_node, void(*)(lyd_node*)> m_datastore;
55 std::shared_ptr<YangSchema> m_schema;
56};