Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Jan Kundrát | e015428 | 2020-01-22 19:43:30 +0100 | [diff] [blame] | 3 | #include <functional> |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 4 | #include <libnetconf2/messages_client.h> |
| 5 | #include <memory> |
| 6 | #include <optional> |
| 7 | #include <string> |
| 8 | #include <string_view> |
| 9 | #include <vector> |
| 10 | |
| 11 | struct nc_session; |
| 12 | |
| 13 | namespace libyang { |
| 14 | class Data_Node; |
Václav Kubernát | 1d50a5b | 2020-02-03 16:44:22 +0100 | [diff] [blame] | 15 | class Context; |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 16 | } |
| 17 | |
| 18 | namespace libnetconf { |
| 19 | namespace client { |
| 20 | |
| 21 | class ReportedError : public std::runtime_error { |
| 22 | public: |
| 23 | ReportedError(const std::string& what); |
| 24 | ~ReportedError() override; |
| 25 | }; |
| 26 | |
Jan Kundrát | e015428 | 2020-01-22 19:43:30 +0100 | [diff] [blame] | 27 | using KbdInteractiveCb = std::function<std::string(const std::string&, const std::string&, const std::string&, bool)>; |
| 28 | |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 29 | class Session { |
| 30 | public: |
| 31 | Session(struct nc_session* session); |
| 32 | ~Session(); |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 33 | 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át | e015428 | 2020-01-22 19:43:30 +0100 | [diff] [blame] | 34 | static std::unique_ptr<Session> connectKbdInteractive(const std::string& host, const uint16_t port, const std::string& user, const KbdInteractiveCb& callback); |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 35 | 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át | 9138b16 | 2020-01-30 09:27:51 +0100 | [diff] [blame] | 39 | std::shared_ptr<libyang::Data_Node> get(const std::optional<std::string>& filter = std::nullopt); |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 40 | 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át | 59acc2f | 2020-01-23 15:12:59 +0100 | [diff] [blame] | 47 | std::shared_ptr<libyang::Data_Node> rpc(const std::string& xmlData); |
Václav Kubernát | 7160a13 | 2020-04-03 02:11:01 +0200 | [diff] [blame] | 48 | void copyConfig(const NC_DATASTORE source, const NC_DATASTORE destination); |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 49 | void commit(); |
| 50 | void discard(); |
Václav Kubernát | 1d50a5b | 2020-02-03 16:44:22 +0100 | [diff] [blame] | 51 | |
| 52 | std::shared_ptr<libyang::Context> libyangContext(); |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 53 | struct nc_session* session_internal(); // FIXME: remove me |
| 54 | protected: |
| 55 | struct nc_session* m_session; |
| 56 | }; |
| 57 | } |
| 58 | } |