blob: 64538f0427ea1de999576002f9343e96bb014c75 [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
Václav Kubernát0c90dd42022-01-18 00:07:29 +010016enum class StrictDataParsing {
17 Yes,
18 No
19};
20
Václav Kubernát74487df2020-06-04 01:29:28 +020021class YangSchema;
22
23struct ly_ctx;
24struct lyd_node;
25
26class YangAccess : public DatastoreAccess {
27public:
28 YangAccess();
Václav Kubernáte7248b22020-06-26 15:38:59 +020029 YangAccess(std::shared_ptr<YangSchema> schema);
Václav Kubernát74487df2020-06-04 01:29:28 +020030 ~YangAccess() override;
Václav Kubernát59e4ee42020-07-08 17:32:45 +020031 [[nodiscard]] Tree getItems(const std::string& path) const override;
Václav Kubernát74487df2020-06-04 01:29:28 +020032 void setLeaf(const std::string& path, leaf_data_ value) override;
33 void createItem(const std::string& path) override;
34 void deleteItem(const std::string& path) override;
35 void moveItem(const std::string& source, std::variant<yang::move::Absolute, yang::move::Relative> move) override;
36 void commitChanges() override;
37 void discardChanges() override;
Václav Kubernátb3960f82020-12-01 03:21:48 +010038 [[noreturn]] Tree execute(const std::string& path, const Tree& input) override;
Václav Kubernát74487df2020-06-04 01:29:28 +020039 void copyConfig(const Datastore source, const Datastore destination) override;
40
41 std::shared_ptr<Schema> schema() override;
42
43 void enableFeature(const std::string& module, const std::string& feature);
Václav Kubernát59e4ee42020-07-08 17:32:45 +020044 [[nodiscard]] std::string dump(const DataFormat format) const override;
Václav Kubernát74487df2020-06-04 01:29:28 +020045
Václav Kubernát619e6542020-06-29 14:13:43 +020046 void loadModule(const std::string& name);
Václav Kubernát74487df2020-06-04 01:29:28 +020047 void addSchemaFile(const std::string& path);
48 void addSchemaDir(const std::string& path);
Václav Kubernát0c90dd42022-01-18 00:07:29 +010049 void addDataFile(const std::string& path, const StrictDataParsing strict);
Václav Kubernát74487df2020-06-04 01:29:28 +020050
51private:
52 std::vector<ListInstance> listInstances(const std::string& path) override;
Václav Kubernáta8789602020-07-20 15:18:19 +020053 [[noreturn]] void impl_execute(const std::string& type, const std::string& path, const Tree& input);
Václav Kubernát74487df2020-06-04 01:29:28 +020054
55 [[noreturn]] void getErrorsAndThrow() const;
56 void impl_newPath(const std::string& path, const std::optional<std::string>& value = std::nullopt);
57 void impl_removeNode(const std::string& path);
58 void validate();
59
Václav Kubernátb4e5b182020-11-16 19:55:09 +010060 std::unique_ptr<ly_ctx, void (*)(ly_ctx*)> m_ctx;
61 std::unique_ptr<lyd_node, void (*)(lyd_node*)> m_datastore;
Václav Kubernát74487df2020-06-04 01:29:28 +020062 std::shared_ptr<YangSchema> m_schema;
Václav Kubernáte7248b22020-06-26 15:38:59 +020063 const int m_validation_mode;
Václav Kubernát74487df2020-06-04 01:29:28 +020064};