blob: aab5d8195b6113a2947e927f9abf7cc7100b11e9 [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
Václav Kubernátcfdb9222021-07-07 22:36:24 +020010#include <libyang-cpp/Context.hpp>
Václav Kubernát74487df2020-06-04 01:29:28 +020011#include "datastore_access.hpp"
12
13/*! \class YangAccess
14 * \brief Implementation of DatastoreAccess with a local libyang data node instance
15 */
16
Václav Kubernát0c90dd42022-01-18 00:07:29 +010017enum class StrictDataParsing {
18 Yes,
19 No
20};
21
Václav Kubernát74487df2020-06-04 01:29:28 +020022class YangSchema;
23
24struct ly_ctx;
25struct lyd_node;
26
27class YangAccess : public DatastoreAccess {
28public:
29 YangAccess();
Václav Kubernáte7248b22020-06-26 15:38:59 +020030 YangAccess(std::shared_ptr<YangSchema> schema);
Václav Kubernát74487df2020-06-04 01:29:28 +020031 ~YangAccess() override;
Václav Kubernát59e4ee42020-07-08 17:32:45 +020032 [[nodiscard]] Tree getItems(const std::string& path) const override;
Václav Kubernát74487df2020-06-04 01:29:28 +020033 void setLeaf(const std::string& path, leaf_data_ value) override;
34 void createItem(const std::string& path) override;
35 void deleteItem(const std::string& path) override;
36 void moveItem(const std::string& source, std::variant<yang::move::Absolute, yang::move::Relative> move) override;
37 void commitChanges() override;
38 void discardChanges() override;
Václav Kubernátb3960f82020-12-01 03:21:48 +010039 [[noreturn]] Tree execute(const std::string& path, const Tree& input) override;
Václav Kubernát74487df2020-06-04 01:29:28 +020040 void copyConfig(const Datastore source, const Datastore destination) override;
41
42 std::shared_ptr<Schema> schema() override;
43
Václav Kubernátcfdb9222021-07-07 22:36:24 +020044 void setEnabledFeatures(const std::string& module, const std::vector<std::string>& features);
Václav Kubernát59e4ee42020-07-08 17:32:45 +020045 [[nodiscard]] std::string dump(const DataFormat format) const override;
Václav Kubernát74487df2020-06-04 01:29:28 +020046
Václav Kubernát619e6542020-06-29 14:13:43 +020047 void loadModule(const std::string& name);
Václav Kubernát74487df2020-06-04 01:29:28 +020048 void addSchemaFile(const std::string& path);
49 void addSchemaDir(const std::string& path);
Václav Kubernát0c90dd42022-01-18 00:07:29 +010050 void addDataFile(const std::string& path, const StrictDataParsing strict);
Václav Kubernát74487df2020-06-04 01:29:28 +020051
52private:
53 std::vector<ListInstance> listInstances(const std::string& path) override;
Václav Kubernáta8789602020-07-20 15:18:19 +020054 [[noreturn]] void impl_execute(const std::string& type, const std::string& path, const Tree& input);
Václav Kubernát74487df2020-06-04 01:29:28 +020055
56 [[noreturn]] void getErrorsAndThrow() const;
57 void impl_newPath(const std::string& path, const std::optional<std::string>& value = std::nullopt);
58 void impl_removeNode(const std::string& path);
59 void validate();
60
Václav Kubernátcfdb9222021-07-07 22:36:24 +020061 libyang::Context m_ctx;
62 std::optional<libyang::DataNode> m_datastore;
Václav Kubernát74487df2020-06-04 01:29:28 +020063 std::shared_ptr<YangSchema> m_schema;
Václav Kubernát74487df2020-06-04 01:29:28 +020064};