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 { |
Václav Kubernát | d860d98 | 2021-01-08 13:46:02 +0100 | [diff] [blame] | 20 | enum class NmdaDatastore { |
| 21 | Startup, |
| 22 | Running, |
Václav Kubernát | 1fcfa9c | 2021-02-22 03:22:08 +0100 | [diff] [blame] | 23 | Candidate, |
Václav Kubernát | d860d98 | 2021-01-08 13:46:02 +0100 | [diff] [blame] | 24 | Operational |
| 25 | }; |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 26 | namespace client { |
| 27 | |
| 28 | class ReportedError : public std::runtime_error { |
| 29 | public: |
| 30 | ReportedError(const std::string& what); |
| 31 | ~ReportedError() override; |
| 32 | }; |
| 33 | |
Jan Kundrát | e015428 | 2020-01-22 19:43:30 +0100 | [diff] [blame] | 34 | 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] | 35 | using LogCb = std::function<void(NC_VERB_LEVEL, const char*)>; |
| 36 | |
| 37 | void setLogLevel(NC_VERB_LEVEL level); |
| 38 | void setLogCallback(const LogCb& callback); |
Jan Kundrát | e015428 | 2020-01-22 19:43:30 +0100 | [diff] [blame] | 39 | |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 40 | class Session { |
| 41 | public: |
| 42 | Session(struct nc_session* session); |
| 43 | ~Session(); |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 44 | 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] | 45 | 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] | 46 | static std::unique_ptr<Session> connectSocket(const std::string& path); |
Václav Kubernát | 7a9463f | 2020-10-30 08:57:59 +0100 | [diff] [blame] | 47 | 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] | 48 | [[nodiscard]] std::vector<std::string_view> capabilities() const; |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 49 | std::shared_ptr<libyang::Data_Node> getConfig(const NC_DATASTORE datastore, |
| 50 | const std::optional<const std::string> filter = std::nullopt); // TODO: arguments... |
Jan Kundrát | 9138b16 | 2020-01-30 09:27:51 +0100 | [diff] [blame] | 51 | std::shared_ptr<libyang::Data_Node> get(const std::optional<std::string>& filter = std::nullopt); |
Václav Kubernát | d860d98 | 2021-01-08 13:46:02 +0100 | [diff] [blame] | 52 | std::shared_ptr<libyang::Data_Node> 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 | std::string getSchema(const std::string_view identifier, const std::optional<std::string_view> version); |
| 54 | void editConfig(const NC_DATASTORE datastore, |
| 55 | const NC_RPC_EDIT_DFLTOP defaultOperation, |
| 56 | const NC_RPC_EDIT_TESTOPT testOption, |
| 57 | const NC_RPC_EDIT_ERROPT errorOption, |
| 58 | const std::string& data); |
Václav Kubernát | 1fcfa9c | 2021-02-22 03:22:08 +0100 | [diff] [blame] | 59 | void editData(const NmdaDatastore datastore, const std::string& data); |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 60 | void copyConfigFromString(const NC_DATASTORE target, const std::string& data); |
Václav Kubernát | a878960 | 2020-07-20 15:18:19 +0200 | [diff] [blame] | 61 | 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] | 62 | void copyConfig(const NC_DATASTORE source, const NC_DATASTORE destination); |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 63 | void commit(); |
| 64 | void discard(); |
Václav Kubernát | 1d50a5b | 2020-02-03 16:44:22 +0100 | [diff] [blame] | 65 | |
| 66 | std::shared_ptr<libyang::Context> libyangContext(); |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 67 | struct nc_session* session_internal(); // FIXME: remove me |
| 68 | protected: |
| 69 | struct nc_session* m_session; |
| 70 | }; |
| 71 | } |
| 72 | } |