face: Adding new 'createFace' method in all Factories
This method accepts parsed URI object and attempts to create Face on the
right channel (e.g., if hostname in URI resolved to IPv6, IPv6 TCP channel
will be used).
Factories that do not support 'createFace' operation will throw an exception.
As of this commit, *Factory::create methods are renamed to more explicit
*Factory::createChannel, and *Factory::connect to *Factory::createFace.
All other Factory-specific methods should denote what exactly is
created: channel, face, or multicast face.
Change-Id: I6396dc84c4cd8bbcdde9f55cfac90635d99e93e9
Refs: #1195
diff --git a/daemon/face/protocol-factory.hpp b/daemon/face/protocol-factory.hpp
index f02941e..8a00bde 100644
--- a/daemon/face/protocol-factory.hpp
+++ b/daemon/face/protocol-factory.hpp
@@ -8,9 +8,26 @@
#define NFD_FACE_PROTOCOL_FACTORY_HPP
#include "common.hpp"
+#include "core/face-uri.hpp"
namespace nfd {
+class Face;
+
+/**
+ * \brief Prototype for the callback called when face is created
+ * (as a response to incoming connection or after connection
+ * is established)
+ */
+typedef function<void(const shared_ptr<Face>& newFace)> FaceCreatedCallback;
+
+/**
+ * \brief Prototype for the callback that is called when face is failed to
+ * get created
+ */
+typedef function<void(const std::string& reason)> FaceConnectFailedCallback;
+
+
class ProtocolFactory
{
public:
@@ -21,6 +38,18 @@
{
Error(const std::string& what) : std::runtime_error(what) {}
};
+
+ /** \brief Try to create Face using the supplied Face URI
+ *
+ * This method should automatically choose channel, based on supplied Face URI
+ * and create face.
+ *
+ * \throws Factory::Error if Factory does not support connect operation
+ */
+ virtual void
+ createFace(const FaceUri& uri,
+ const FaceCreatedCallback& onCreated,
+ const FaceConnectFailedCallback& onConnectFailed) = 0;
};
} // namespace nfd