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 | e2e15ee | 2020-02-05 17:38:13 +0100 | [diff] [blame] | 4 | #include <libnetconf2/log.h> |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 5 | #include <libnetconf2/messages_client.h> |
| 6 | #include <memory> |
| 7 | #include <optional> |
| 8 | #include <string> |
| 9 | #include <string_view> |
| 10 | #include <vector> |
| 11 | |
| 12 | struct nc_session; |
| 13 | |
| 14 | namespace libyang { |
| 15 | class Data_Node; |
Václav Kubernát | 1d50a5b | 2020-02-03 16:44:22 +0100 | [diff] [blame] | 16 | class Context; |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 17 | } |
| 18 | |
| 19 | namespace libnetconf { |
| 20 | namespace client { |
| 21 | |
| 22 | class ReportedError : public std::runtime_error { |
| 23 | public: |
| 24 | ReportedError(const std::string& what); |
| 25 | ~ReportedError() override; |
| 26 | }; |
| 27 | |
Jan Kundrát | e015428 | 2020-01-22 19:43:30 +0100 | [diff] [blame] | 28 | using KbdInteractiveCb = std::function<std::string(const std::string&, const std::string&, const std::string&, bool)>; |
Václav Kubernát | e2e15ee | 2020-02-05 17:38:13 +0100 | [diff] [blame] | 29 | using LogCb = std::function<void(NC_VERB_LEVEL, const char*)>; |
| 30 | |
| 31 | void setLogLevel(NC_VERB_LEVEL level); |
| 32 | void setLogCallback(const LogCb& callback); |
Jan Kundrát | e015428 | 2020-01-22 19:43:30 +0100 | [diff] [blame] | 33 | |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 34 | class Session { |
| 35 | public: |
| 36 | Session(struct nc_session* session); |
| 37 | ~Session(); |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 38 | 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] | 39 | 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] | 40 | static std::unique_ptr<Session> connectSocket(const std::string& path); |
Václav Kubernát | 7a9463f | 2020-10-30 08:57:59 +0100 | [diff] [blame] | 41 | static std::unique_ptr<Session> connectFd(const int source, const int sink); |
Václav Kubernát | 59e4ee4 | 2020-07-08 17:32:45 +0200 | [diff] [blame] | 42 | [[nodiscard]] std::vector<std::string_view> capabilities() const; |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 43 | std::shared_ptr<libyang::Data_Node> getConfig(const NC_DATASTORE datastore, |
| 44 | const std::optional<const std::string> filter = std::nullopt); // TODO: arguments... |
Jan Kundrát | 9138b16 | 2020-01-30 09:27:51 +0100 | [diff] [blame] | 45 | 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] | 46 | std::string getSchema(const std::string_view identifier, const std::optional<std::string_view> version); |
| 47 | void editConfig(const NC_DATASTORE datastore, |
| 48 | const NC_RPC_EDIT_DFLTOP defaultOperation, |
| 49 | const NC_RPC_EDIT_TESTOPT testOption, |
| 50 | const NC_RPC_EDIT_ERROPT errorOption, |
| 51 | const std::string& data); |
| 52 | void copyConfigFromString(const NC_DATASTORE target, const std::string& data); |
Václav Kubernát | a878960 | 2020-07-20 15:18:19 +0200 | [diff] [blame] | 53 | std::shared_ptr<libyang::Data_Node> rpc_or_action(const std::string& xmlData); |
Václav Kubernát | 7160a13 | 2020-04-03 02:11:01 +0200 | [diff] [blame] | 54 | void copyConfig(const NC_DATASTORE source, const NC_DATASTORE destination); |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 55 | void commit(); |
| 56 | void discard(); |
Václav Kubernát | 1d50a5b | 2020-02-03 16:44:22 +0100 | [diff] [blame] | 57 | |
| 58 | std::shared_ptr<libyang::Context> libyangContext(); |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 59 | struct nc_session* session_internal(); // FIXME: remove me |
| 60 | protected: |
| 61 | struct nc_session* m_session; |
| 62 | }; |
| 63 | } |
| 64 | } |