face: move face parameters into CreateFaceParams struct
refs #4003
Change-Id: I6e1149e7075eb055912fd452a21b22fcb610829a
diff --git a/daemon/face/ethernet-factory.cpp b/daemon/face/ethernet-factory.cpp
index 9ff5fd5..0ba49ae 100644
--- a/daemon/face/ethernet-factory.cpp
+++ b/daemon/face/ethernet-factory.cpp
@@ -173,30 +173,27 @@
}
void
-EthernetFactory::createFace(const FaceUri& remoteUri,
- const ndn::optional<FaceUri>& localUri,
- ndn::nfd::FacePersistency persistency,
- bool wantLocalFieldsEnabled,
+EthernetFactory::createFace(const CreateFaceParams& params,
const FaceCreatedCallback& onCreated,
const FaceCreationFailedCallback& onFailure)
{
- BOOST_ASSERT(remoteUri.isCanonical());
+ BOOST_ASSERT(params.remoteUri.isCanonical());
- if (!localUri || localUri->getScheme() != "dev") {
+ if (!params.localUri || params.localUri->getScheme() != "dev") {
NFD_LOG_TRACE("Cannot create unicast Ethernet face without dev:// LocalUri");
onFailure(406, "Creation of unicast Ethernet faces requires a LocalUri with dev:// scheme");
return;
}
- BOOST_ASSERT(localUri->isCanonical());
+ BOOST_ASSERT(params.localUri->isCanonical());
- if (persistency == ndn::nfd::FACE_PERSISTENCY_ON_DEMAND) {
+ if (params.persistency == ndn::nfd::FACE_PERSISTENCY_ON_DEMAND) {
NFD_LOG_TRACE("createFace does not support FACE_PERSISTENCY_ON_DEMAND");
onFailure(406, "Outgoing Ethernet faces do not support on-demand persistency");
return;
}
- ethernet::Address remoteEndpoint(ethernet::Address::fromString(remoteUri.getHost()));
- std::string localEndpoint(localUri->getHost());
+ ethernet::Address remoteEndpoint(ethernet::Address::fromString(params.remoteUri.getHost()));
+ std::string localEndpoint(params.localUri->getHost());
if (remoteEndpoint.isMulticast()) {
NFD_LOG_TRACE("createFace does not support multicast faces");
@@ -204,7 +201,7 @@
return;
}
- if (wantLocalFieldsEnabled) {
+ if (params.wantLocalFieldsEnabled) {
// Ethernet faces are never local
NFD_LOG_TRACE("createFace cannot create non-local face with local fields enabled");
onFailure(406, "Local fields can only be enabled on faces with local scope");
@@ -213,7 +210,7 @@
for (const auto& i : m_channels) {
if (i.first == localEndpoint) {
- i.second->connect(remoteEndpoint, persistency, onCreated, onFailure);
+ i.second->connect(remoteEndpoint, params.persistency, onCreated, onFailure);
return;
}
}
diff --git a/daemon/face/ethernet-factory.hpp b/daemon/face/ethernet-factory.hpp
index e4cf7d9..244f769 100644
--- a/daemon/face/ethernet-factory.hpp
+++ b/daemon/face/ethernet-factory.hpp
@@ -50,10 +50,7 @@
FaceSystem::ConfigContext& context) override;
void
- createFace(const FaceUri& remoteUri,
- const ndn::optional<FaceUri>& localUri,
- ndn::nfd::FacePersistency persistency,
- bool wantLocalFieldsEnabled,
+ createFace(const CreateFaceParams& params,
const FaceCreatedCallback& onCreated,
const FaceCreationFailedCallback& onFailure) override;
diff --git a/daemon/face/protocol-factory.hpp b/daemon/face/protocol-factory.hpp
index 524f901..0eee552 100644
--- a/daemon/face/protocol-factory.hpp
+++ b/daemon/face/protocol-factory.hpp
@@ -129,21 +129,28 @@
return providedSchemes;
}
- /** \brief Try to create Face using the supplied FaceUri
+ /** \brief Parameters to ProtocolFactory::createFace
*
- * \param remoteUri remote URI of the new face
- * \param localUri local URI of the new face
- * \param persistency persistency of the new face
- * \param wantLocalFieldsEnabled whether local fields should be enabled on the face
+ * Parameters are passed as a struct rather than individually, so that a future change in the list
+ * of parameters does not require an update to the method signature in all subclasses.
+ */
+ struct CreateFaceParams
+ {
+ FaceUri remoteUri;
+ ndn::optional<FaceUri> localUri;
+ ndn::nfd::FacePersistency persistency;
+ bool wantLocalFieldsEnabled;
+ };
+
+ /** \brief Try to create face using the supplied parameters
+ *
+ * \param params parameters to create face with
* \param onCreated callback if face creation succeeds or face already exists;
* persistency and local fields settings are not updated on an existing face
* \param onFailure callback if face creation fails
*/
virtual void
- createFace(const FaceUri& remoteUri,
- const ndn::optional<FaceUri>& localUri,
- ndn::nfd::FacePersistency persistency,
- bool wantLocalFieldsEnabled,
+ createFace(const CreateFaceParams& params,
const FaceCreatedCallback& onCreated,
const FaceCreationFailedCallback& onFailure) = 0;
diff --git a/daemon/face/tcp-factory.cpp b/daemon/face/tcp-factory.cpp
index 28ac251..9833ee6 100644
--- a/daemon/face/tcp-factory.cpp
+++ b/daemon/face/tcp-factory.cpp
@@ -125,29 +125,26 @@
}
void
-TcpFactory::createFace(const FaceUri& remoteUri,
- const ndn::optional<FaceUri>& localUri,
- ndn::nfd::FacePersistency persistency,
- bool wantLocalFieldsEnabled,
+TcpFactory::createFace(const CreateFaceParams& params,
const FaceCreatedCallback& onCreated,
const FaceCreationFailedCallback& onFailure)
{
- BOOST_ASSERT(remoteUri.isCanonical());
+ BOOST_ASSERT(params.remoteUri.isCanonical());
- if (localUri) {
+ if (params.localUri) {
NFD_LOG_TRACE("Cannot create unicast TCP face with LocalUri");
onFailure(406, "Unicast TCP faces cannot be created with a LocalUri");
return;
}
- if (persistency == ndn::nfd::FACE_PERSISTENCY_ON_DEMAND) {
+ if (params.persistency == ndn::nfd::FACE_PERSISTENCY_ON_DEMAND) {
NFD_LOG_TRACE("createFace does not support FACE_PERSISTENCY_ON_DEMAND");
onFailure(406, "Outgoing TCP faces do not support on-demand persistency");
return;
}
- tcp::Endpoint endpoint(ip::address::from_string(remoteUri.getHost()),
- boost::lexical_cast<uint16_t>(remoteUri.getPort()));
+ tcp::Endpoint endpoint(ip::address::from_string(params.remoteUri.getHost()),
+ boost::lexical_cast<uint16_t>(params.remoteUri.getPort()));
// a canonical tcp4/tcp6 FaceUri cannot have a multicast address
BOOST_ASSERT(!endpoint.address().is_multicast());
@@ -159,7 +156,7 @@
return;
}
- if (wantLocalFieldsEnabled && !endpoint.address().is_loopback()) {
+ if (params.wantLocalFieldsEnabled && !endpoint.address().is_loopback()) {
NFD_LOG_TRACE("createFace cannot create non-local face with local fields enabled");
onFailure(406, "Local fields can only be enabled on faces with local scope");
return;
@@ -169,7 +166,8 @@
for (const auto& i : m_channels) {
if ((i.first.address().is_v4() && endpoint.address().is_v4()) ||
(i.first.address().is_v6() && endpoint.address().is_v6())) {
- i.second->connect(endpoint, persistency, wantLocalFieldsEnabled, onCreated, onFailure);
+ i.second->connect(endpoint, params.persistency, params.wantLocalFieldsEnabled,
+ onCreated, onFailure);
return;
}
}
diff --git a/daemon/face/tcp-factory.hpp b/daemon/face/tcp-factory.hpp
index 36ee320..cbbbae6 100644
--- a/daemon/face/tcp-factory.hpp
+++ b/daemon/face/tcp-factory.hpp
@@ -50,10 +50,7 @@
FaceSystem::ConfigContext& context) override;
void
- createFace(const FaceUri& remoteUri,
- const ndn::optional<FaceUri>& localUri,
- ndn::nfd::FacePersistency persistency,
- bool wantLocalFieldsEnabled,
+ createFace(const CreateFaceParams& params,
const FaceCreatedCallback& onCreated,
const FaceCreationFailedCallback& onFailure) override;
diff --git a/daemon/face/udp-factory.cpp b/daemon/face/udp-factory.cpp
index 8303aa8..702d02f 100644
--- a/daemon/face/udp-factory.cpp
+++ b/daemon/face/udp-factory.cpp
@@ -206,29 +206,26 @@
}
void
-UdpFactory::createFace(const FaceUri& remoteUri,
- const ndn::optional<FaceUri>& localUri,
- ndn::nfd::FacePersistency persistency,
- bool wantLocalFieldsEnabled,
+UdpFactory::createFace(const CreateFaceParams& params,
const FaceCreatedCallback& onCreated,
const FaceCreationFailedCallback& onFailure)
{
- BOOST_ASSERT(remoteUri.isCanonical());
+ BOOST_ASSERT(params.remoteUri.isCanonical());
- if (localUri) {
+ if (params.localUri) {
NFD_LOG_TRACE("Cannot create unicast UDP face with LocalUri");
onFailure(406, "Unicast UDP faces cannot be created with a LocalUri");
return;
}
- if (persistency == ndn::nfd::FACE_PERSISTENCY_ON_DEMAND) {
+ if (params.persistency == ndn::nfd::FACE_PERSISTENCY_ON_DEMAND) {
NFD_LOG_TRACE("createFace does not support FACE_PERSISTENCY_ON_DEMAND");
onFailure(406, "Outgoing UDP faces do not support on-demand persistency");
return;
}
- udp::Endpoint endpoint(ip::address::from_string(remoteUri.getHost()),
- boost::lexical_cast<uint16_t>(remoteUri.getPort()));
+ udp::Endpoint endpoint(ip::address::from_string(params.remoteUri.getHost()),
+ boost::lexical_cast<uint16_t>(params.remoteUri.getPort()));
if (endpoint.address().is_multicast()) {
NFD_LOG_TRACE("createFace does not support multicast faces");
@@ -243,7 +240,7 @@
return;
}
- if (wantLocalFieldsEnabled) {
+ if (params.wantLocalFieldsEnabled) {
// UDP faces are never local
NFD_LOG_TRACE("createFace cannot create non-local face with local fields enabled");
onFailure(406, "Local fields can only be enabled on faces with local scope");
@@ -254,7 +251,7 @@
for (const auto& i : m_channels) {
if ((i.first.address().is_v4() && endpoint.address().is_v4()) ||
(i.first.address().is_v6() && endpoint.address().is_v6())) {
- i.second->connect(endpoint, persistency, onCreated, onFailure);
+ i.second->connect(endpoint, params.persistency, onCreated, onFailure);
return;
}
}
diff --git a/daemon/face/udp-factory.hpp b/daemon/face/udp-factory.hpp
index 2f809ac..589817d 100644
--- a/daemon/face/udp-factory.hpp
+++ b/daemon/face/udp-factory.hpp
@@ -66,10 +66,7 @@
FaceSystem::ConfigContext& context) override;
void
- createFace(const FaceUri& remoteUri,
- const ndn::optional<FaceUri>& localUri,
- ndn::nfd::FacePersistency persistency,
- bool wantLocalFieldsEnabled,
+ createFace(const CreateFaceParams& params,
const FaceCreatedCallback& onCreated,
const FaceCreationFailedCallback& onFailure) override;
diff --git a/daemon/face/unix-stream-factory.cpp b/daemon/face/unix-stream-factory.cpp
index 0bba3be..7c1c7d5 100644
--- a/daemon/face/unix-stream-factory.cpp
+++ b/daemon/face/unix-stream-factory.cpp
@@ -84,10 +84,7 @@
}
void
-UnixStreamFactory::createFace(const FaceUri& remoteUri,
- const ndn::optional<FaceUri>& localUri,
- ndn::nfd::FacePersistency persistency,
- bool wantLocalFieldsEnabled,
+UnixStreamFactory::createFace(const CreateFaceParams& params,
const FaceCreatedCallback& onCreated,
const FaceCreationFailedCallback& onFailure)
{
diff --git a/daemon/face/unix-stream-factory.hpp b/daemon/face/unix-stream-factory.hpp
index 53baadf..fc5579c 100644
--- a/daemon/face/unix-stream-factory.hpp
+++ b/daemon/face/unix-stream-factory.hpp
@@ -50,10 +50,7 @@
FaceSystem::ConfigContext& context) override;
void
- createFace(const FaceUri& remoteUri,
- const ndn::optional<FaceUri>& localUri,
- ndn::nfd::FacePersistency persistency,
- bool wantLocalFieldsEnabled,
+ createFace(const CreateFaceParams& params,
const FaceCreatedCallback& onCreated,
const FaceCreationFailedCallback& onFailure) override;
diff --git a/daemon/face/websocket-factory.cpp b/daemon/face/websocket-factory.cpp
index 21933a4..9572216 100644
--- a/daemon/face/websocket-factory.cpp
+++ b/daemon/face/websocket-factory.cpp
@@ -118,10 +118,7 @@
}
void
-WebSocketFactory::createFace(const FaceUri& remoteUri,
- const ndn::optional<FaceUri>& localUri,
- ndn::nfd::FacePersistency persistency,
- bool wantLocalFieldsEnabled,
+WebSocketFactory::createFace(const CreateFaceParams& params,
const FaceCreatedCallback& onCreated,
const FaceCreationFailedCallback& onFailure)
{
diff --git a/daemon/face/websocket-factory.hpp b/daemon/face/websocket-factory.hpp
index 0eaa767..a8c4600 100644
--- a/daemon/face/websocket-factory.hpp
+++ b/daemon/face/websocket-factory.hpp
@@ -52,10 +52,7 @@
/** \brief unicast face creation is not supported and will always fail
*/
void
- createFace(const FaceUri& remoteUri,
- const ndn::optional<FaceUri>& localUri,
- ndn::nfd::FacePersistency persistency,
- bool wantLocalFieldsEnabled,
+ createFace(const CreateFaceParams& params,
const FaceCreatedCallback& onCreated,
const FaceCreationFailedCallback& onFailure) override;