NetconfAccess: allow connection over a pair of FDs

Change-Id: I99c5f22195e3f9566b9b51a5cb0c70d42c126450
diff --git a/src/netconf-client.cpp b/src/netconf-client.cpp
index 1ff83de..5b3fa4d 100644
--- a/src/netconf-client.cpp
+++ b/src/netconf-client.cpp
@@ -238,6 +238,17 @@
     return session;
 }
 
+std::unique_ptr<Session> Session::connectFd(const int source, const int sink)
+{
+    impl::ClientInit::instance();
+
+    auto session = std::make_unique<Session>(nc_connect_inout(source, sink, nullptr));
+    if (!session->m_session) {
+        throw std::runtime_error{"nc_connect_inout failed"};
+    }
+    return session;
+}
+
 std::unique_ptr<Session> Session::connectSocket(const std::string& path)
 {
     impl::ClientInit::instance();
diff --git a/src/netconf-client.hpp b/src/netconf-client.hpp
index db004e3..acce38a 100644
--- a/src/netconf-client.hpp
+++ b/src/netconf-client.hpp
@@ -33,6 +33,7 @@
     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);
     static std::unique_ptr<Session> connectKbdInteractive(const std::string& host, const uint16_t port, const std::string& user, const KbdInteractiveCb& callback);
     static std::unique_ptr<Session> connectSocket(const std::string& path);
+    static std::unique_ptr<Session> connectFd(const int source, const int sink);
     [[nodiscard]] std::vector<std::string_view> capabilities() const;
     std::shared_ptr<libyang::Data_Node> getConfig(const NC_DATASTORE datastore,
                                                   const std::optional<const std::string> filter = std::nullopt); // TODO: arguments...
diff --git a/src/netconf_access.cpp b/src/netconf_access.cpp
index 4b151d3..32e0f33 100644
--- a/src/netconf_access.cpp
+++ b/src/netconf_access.cpp
@@ -33,6 +33,12 @@
 {
 }
 
+NetconfAccess::NetconfAccess(const int source, const int sink)
+    : m_session(libnetconf::client::Session::connectFd(source, sink))
+    , m_schema(std::make_shared<YangSchema>(m_session->libyangContext()))
+{
+}
+
 NetconfAccess::NetconfAccess(std::unique_ptr<libnetconf::client::Session>&& session)
     : m_session(std::move(session))
     , m_schema(std::make_shared<YangSchema>(m_session->libyangContext()))
diff --git a/src/netconf_access.hpp b/src/netconf_access.hpp
index d6100a7..29dfd75 100644
--- a/src/netconf_access.hpp
+++ b/src/netconf_access.hpp
@@ -31,6 +31,7 @@
 public:
     NetconfAccess(const std::string& hostname, uint16_t port, const std::string& user, const std::string& pubKey, const std::string& privKey);
     NetconfAccess(const std::string& socketPath);
+    NetconfAccess(const int source, const int sink);
     NetconfAccess(std::unique_ptr<libnetconf::client::Session>&& session);
     ~NetconfAccess() override;
     [[nodiscard]] Tree getItems(const std::string& path) const override;