blob: f7799b0e5505a51bae29712df89e24a2e5e053c7 [file] [log] [blame]
Václav Kubernát80aacc02018-08-22 17:41:54 +02001/*
2 * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/
3 * Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/
4 *
5 * Written by Václav Kubernát <kubervac@fit.cvut.cz>
6 *
7*/
8
9#include <sysrepo-cpp/Session.h>
10#include "sysrepo_access.hpp"
11
12
13struct valFromValue : boost::static_visitor<S_Val> {
14 S_Val operator()(const enum_& value) const
15 {
16 return std::make_shared<Val>(value.m_value.c_str(), SR_ENUM_T);
17 }
18
19 S_Val operator()(const std::string& value) const
20 {
21 return std::make_shared<Val>(value.c_str());
22 }
23
24 S_Val operator()(const uint32_t& value) const
25 {
26 return std::make_shared<Val>(value, SR_UINT32_T);
27 }
28
29 S_Val operator()(const int32_t& value) const
30 {
31 return std::make_shared<Val>(value, SR_INT32_T);
32 }
33
34 S_Val operator()(const bool& value) const
35 {
36 return std::make_shared<Val>(value, SR_BOOL_T);
37 }
38
39 S_Val operator()(const double& value) const
40 {
41 return std::make_shared<Val>(value);
42 }
43};
44
45SysrepoAccess::~SysrepoAccess()
46{
47 m_session->commit();
48}
49
50SysrepoAccess::SysrepoAccess(const std::string& appname)
51 : m_connection(new Connection(appname.c_str()))
52{
53 m_session = std::make_shared<Session>(m_connection);
54}
55
56std::map<std::string, leaf_data_> SysrepoAccess::getItems(const std::string& path)
57{
58 std::map<std::string, leaf_data_> res;
59 auto iterator = m_session->get_items_iter(path.c_str());
60
61 // TODO: implement this (and make use of it somehow)
62
63 return res;
64}
65
66void SysrepoAccess::setLeaf(const std::string& path, leaf_data_ value)
67{
68 m_session->set_item(path.c_str(), boost::apply_visitor(valFromValue(), value));
69}
70
71void SysrepoAccess::createPresenceContainer(const std::string& path)
72{
73 m_session->set_item(path.c_str());
74}
75
76void SysrepoAccess::deletePresenceContainer(const std::string& path)
77{
78 m_session->delete_item(path.c_str());
79}