blob: 2db21c9bb056d611c4aa85224dd64e963688e00c [file] [log] [blame]
Václav Kubernátc31bd602019-03-07 11:44:48 +01001#pragma once
2
Jan Kundráte0154282020-01-22 19:43:30 +01003#include <functional>
Václav Kubernátc31bd602019-03-07 11:44:48 +01004#include <libnetconf2/messages_client.h>
5#include <memory>
6#include <optional>
7#include <string>
8#include <string_view>
9#include <vector>
10
11struct nc_session;
12
13namespace libyang {
14class Data_Node;
Václav Kubernát1d50a5b2020-02-03 16:44:22 +010015class Context;
Václav Kubernátc31bd602019-03-07 11:44:48 +010016}
17
18namespace libnetconf {
19namespace client {
20
21class ReportedError : public std::runtime_error {
22public:
23 ReportedError(const std::string& what);
24 ~ReportedError() override;
25};
26
Jan Kundráte0154282020-01-22 19:43:30 +010027using KbdInteractiveCb = std::function<std::string(const std::string&, const std::string&, const std::string&, bool)>;
28
Václav Kubernátc31bd602019-03-07 11:44:48 +010029class Session {
30public:
31 Session(struct nc_session* session);
32 ~Session();
Václav Kubernátc31bd602019-03-07 11:44:48 +010033 static std::unique_ptr<Session> connectPubkey(const std::string& host, const uint16_t port, const std::string& user, const std::string& pubPath, const std::string& privPath);
Jan Kundráte0154282020-01-22 19:43:30 +010034 static std::unique_ptr<Session> connectKbdInteractive(const std::string& host, const uint16_t port, const std::string& user, const KbdInteractiveCb& callback);
Václav Kubernátc31bd602019-03-07 11:44:48 +010035 static std::unique_ptr<Session> connectSocket(const std::string& path);
36 std::vector<std::string_view> capabilities() const;
37 std::shared_ptr<libyang::Data_Node> getConfig(const NC_DATASTORE datastore,
38 const std::optional<const std::string> filter = std::nullopt); // TODO: arguments...
Jan Kundrát9138b162020-01-30 09:27:51 +010039 std::shared_ptr<libyang::Data_Node> get(const std::optional<std::string>& filter = std::nullopt);
Václav Kubernátc31bd602019-03-07 11:44:48 +010040 std::string getSchema(const std::string_view identifier, const std::optional<std::string_view> version);
41 void editConfig(const NC_DATASTORE datastore,
42 const NC_RPC_EDIT_DFLTOP defaultOperation,
43 const NC_RPC_EDIT_TESTOPT testOption,
44 const NC_RPC_EDIT_ERROPT errorOption,
45 const std::string& data);
46 void copyConfigFromString(const NC_DATASTORE target, const std::string& data);
Jan Kundrát59acc2f2020-01-23 15:12:59 +010047 std::shared_ptr<libyang::Data_Node> rpc(const std::string& xmlData);
Václav Kubernát7160a132020-04-03 02:11:01 +020048 void copyConfig(const NC_DATASTORE source, const NC_DATASTORE destination);
Václav Kubernátc31bd602019-03-07 11:44:48 +010049 void commit();
50 void discard();
Václav Kubernát1d50a5b2020-02-03 16:44:22 +010051
52 std::shared_ptr<libyang::Context> libyangContext();
Václav Kubernátc31bd602019-03-07 11:44:48 +010053 struct nc_session* session_internal(); // FIXME: remove me
54protected:
55 struct nc_session* m_session;
56};
57}
58}