blob: 39d9c064c30951d3f99627d977b79b8e7c6fe6a8 [file] [log] [blame]
/*
* Copyright (C) 2020 CESNET, https://photonics.cesnet.cz/
*
* Written by Tomáš Pecka <tomas.pecka@fit.cvut.cz>
*
*/
#pragma once
#include <sysrepo-cpp/Session.hpp>
#include <map>
#include <string>
namespace velia::utils {
struct YANGPair {
std::string m_xpath;
std::string m_value;
YANGPair(std::string xpath, std::string value);
};
void valuesToYang(const std::vector<YANGPair>& values, const std::vector<std::string>& removePaths, const std::vector<std::string>& discardPaths, ::sysrepo::Session session, std::optional<libyang::DataNode>& parent);
void valuesToYang(const std::map<std::string, std::string>& values, const std::vector<std::string>& removePaths, const std::vector<std::string>& discardPaths, ::sysrepo::Session session, std::optional<libyang::DataNode>& parent);
void valuesPush(const std::map<std::string, std::string>& values, const std::vector<std::string>& removePaths, const std::vector<std::string>& discardPaths, ::sysrepo::Session session);
void valuesPush(const std::vector<YANGPair>& values, const std::vector<std::string>& removePaths, const std::vector<std::string>& discardPaths, ::sysrepo::Session session);
void valuesPush(const std::map<std::string, std::string>& values, const std::vector<std::string>& removePaths, const std::vector<std::string>& discardPaths, ::sysrepo::Session session, sysrepo::Datastore datastore);
void valuesPush(const std::vector<YANGPair>& values, const std::vector<std::string>& removePaths, const std::vector<std::string>& discardPaths, ::sysrepo::Session session, sysrepo::Datastore datastore);
void initLogsSysrepo();
void ensureModuleImplemented(::sysrepo::Session session, const std::string& module, const std::string& revision);
void setErrors(::sysrepo::Session session, const std::string& msg);
/** @brief Ensures that session switches to provided datastore and when the object gets destroyed the session switches back to the original datastore. */
class ScopedDatastoreSwitch {
sysrepo::Session m_session;
sysrepo::Datastore m_oldDatastore;
public:
ScopedDatastoreSwitch(sysrepo::Session session, sysrepo::Datastore ds);
~ScopedDatastoreSwitch();
ScopedDatastoreSwitch(const ScopedDatastoreSwitch&) = delete;
ScopedDatastoreSwitch(ScopedDatastoreSwitch&&) = delete;
ScopedDatastoreSwitch& operator=(const ScopedDatastoreSwitch&) = delete;
ScopedDatastoreSwitch& operator=(ScopedDatastoreSwitch&&) = delete;
};
}