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> |
Václav Kubernát | ed4e378 | 2022-03-02 23:57:33 +0100 | [diff] [blame] | 6 | #include <libyang-cpp/Context.hpp> |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 7 | #include <memory> |
| 8 | #include <optional> |
| 9 | #include <string> |
| 10 | #include <string_view> |
| 11 | #include <vector> |
| 12 | |
| 13 | struct nc_session; |
Václav Kubernát | ed4e378 | 2022-03-02 23:57:33 +0100 | [diff] [blame] | 14 | struct ly_ctx; |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 15 | |
| 16 | namespace libyang { |
Václav Kubernát | 1d50a5b | 2020-02-03 16:44:22 +0100 | [diff] [blame] | 17 | class Context; |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 18 | class DataNode; |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | namespace libnetconf { |
Václav Kubernát | d860d98 | 2021-01-08 13:46:02 +0100 | [diff] [blame] | 22 | enum class NmdaDatastore { |
| 23 | Startup, |
| 24 | Running, |
Václav Kubernát | 1fcfa9c | 2021-02-22 03:22:08 +0100 | [diff] [blame] | 25 | Candidate, |
Václav Kubernát | d860d98 | 2021-01-08 13:46:02 +0100 | [diff] [blame] | 26 | Operational |
| 27 | }; |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 28 | namespace client { |
| 29 | |
| 30 | class ReportedError : public std::runtime_error { |
| 31 | public: |
| 32 | ReportedError(const std::string& what); |
| 33 | ~ReportedError() override; |
| 34 | }; |
| 35 | |
Jan Kundrát | e015428 | 2020-01-22 19:43:30 +0100 | [diff] [blame] | 36 | 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] | 37 | using LogCb = std::function<void(NC_VERB_LEVEL, const char*)>; |
| 38 | |
| 39 | void setLogLevel(NC_VERB_LEVEL level); |
| 40 | void setLogCallback(const LogCb& callback); |
Jan Kundrát | e015428 | 2020-01-22 19:43:30 +0100 | [diff] [blame] | 41 | |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 42 | class Session { |
| 43 | public: |
| 44 | Session(struct nc_session* session); |
| 45 | ~Session(); |
Václav Kubernát | ed4e378 | 2022-03-02 23:57:33 +0100 | [diff] [blame] | 46 | 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, std::optional<libyang::Context> ctx = std::nullopt); |
| 47 | static std::unique_ptr<Session> connectKbdInteractive(const std::string& host, const uint16_t port, const std::string& user, const KbdInteractiveCb& callback, std::optional<libyang::Context> ctx = std::nullopt); |
| 48 | static std::unique_ptr<Session> connectSocket(const std::string& path, std::optional<libyang::Context> ctx = std::nullopt); |
| 49 | static std::unique_ptr<Session> connectFd(const int source, const int sink, std::optional<libyang::Context> ctx = std::nullopt); |
Václav Kubernát | 59e4ee4 | 2020-07-08 17:32:45 +0200 | [diff] [blame] | 50 | [[nodiscard]] std::vector<std::string_view> capabilities() const; |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 51 | std::optional<libyang::DataNode> get(const std::optional<std::string>& filter = std::nullopt); |
| 52 | std::optional<libyang::DataNode> getData(const NmdaDatastore datastore, const std::optional<std::string>& filter = std::nullopt); |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 53 | void editConfig(const NC_DATASTORE datastore, |
| 54 | const NC_RPC_EDIT_DFLTOP defaultOperation, |
| 55 | const NC_RPC_EDIT_TESTOPT testOption, |
| 56 | const NC_RPC_EDIT_ERROPT errorOption, |
| 57 | const std::string& data); |
Václav Kubernát | 1fcfa9c | 2021-02-22 03:22:08 +0100 | [diff] [blame] | 58 | void editData(const NmdaDatastore datastore, const std::string& data); |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 59 | void copyConfigFromString(const NC_DATASTORE target, const std::string& data); |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 60 | std::optional<libyang::DataNode> rpc_or_action(const std::string& xmlData); |
Václav Kubernát | 7160a13 | 2020-04-03 02:11:01 +0200 | [diff] [blame] | 61 | void copyConfig(const NC_DATASTORE source, const NC_DATASTORE destination); |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 62 | void commit(); |
| 63 | void discard(); |
Václav Kubernát | 1d50a5b | 2020-02-03 16:44:22 +0100 | [diff] [blame] | 64 | |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 65 | libyang::Context libyangContext(); |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 66 | struct nc_session* session_internal(); // FIXME: remove me |
| 67 | protected: |
| 68 | struct nc_session* m_session; |
| 69 | }; |
| 70 | } |
| 71 | } |