blob: 1923e71dd390cd8ad0d91bf9078f158c44f47f88 [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;
15}
16
17namespace libnetconf {
18namespace client {
19
20class ReportedError : public std::runtime_error {
21public:
22 ReportedError(const std::string& what);
23 ~ReportedError() override;
24};
25
Jan Kundráte0154282020-01-22 19:43:30 +010026using KbdInteractiveCb = std::function<std::string(const std::string&, const std::string&, const std::string&, bool)>;
27
Václav Kubernátc31bd602019-03-07 11:44:48 +010028class Session {
29public:
30 Session(struct nc_session* session);
31 ~Session();
Václav Kubernátc31bd602019-03-07 11:44:48 +010032 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 +010033 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 +010034 static std::unique_ptr<Session> connectSocket(const std::string& path);
35 std::vector<std::string_view> capabilities() const;
36 std::shared_ptr<libyang::Data_Node> getConfig(const NC_DATASTORE datastore,
37 const std::optional<const std::string> filter = std::nullopt); // TODO: arguments...
38 std::shared_ptr<libyang::Data_Node> get(const std::string& filter);
39 std::string getSchema(const std::string_view identifier, const std::optional<std::string_view> version);
40 void editConfig(const NC_DATASTORE datastore,
41 const NC_RPC_EDIT_DFLTOP defaultOperation,
42 const NC_RPC_EDIT_TESTOPT testOption,
43 const NC_RPC_EDIT_ERROPT errorOption,
44 const std::string& data);
45 void copyConfigFromString(const NC_DATASTORE target, const std::string& data);
46 void commit();
47 void discard();
48 struct nc_session* session_internal(); // FIXME: remove me
49protected:
50 struct nc_session* m_session;
51};
52}
53}