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;
 
diff --git a/daemon/mgmt/face-manager.cpp b/daemon/mgmt/face-manager.cpp
index 95c8a82..8966d9d 100644
--- a/daemon/mgmt/face-manager.cpp
+++ b/daemon/mgmt/face-manager.cpp
@@ -1,5 +1,5 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
  * Copyright (c) 2014-2017,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
@@ -116,11 +116,9 @@
   }
 
   try {
-    factory->createFace(remoteUri,
-      localUri,
-      parameters.getFacePersistency(),
-      parameters.hasFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED) &&
-        parameters.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED),
+    factory->createFace({remoteUri, localUri, parameters.getFacePersistency(),
+        parameters.hasFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED) &&
+        parameters.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)},
       bind(&FaceManager::afterCreateFaceSuccess, this, parameters, _1, done),
       bind(&FaceManager::afterCreateFaceFailure, this, _1, _2, done));
   }
diff --git a/tests/daemon/face/face-system.t.cpp b/tests/daemon/face/face-system.t.cpp
index 1e46240..2bb5a1f 100644
--- a/tests/daemon/face/face-system.t.cpp
+++ b/tests/daemon/face/face-system.t.cpp
@@ -56,10 +56,7 @@
   }
 
   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/tests/daemon/face/factory-test-common.hpp b/tests/daemon/face/factory-test-common.hpp
index 20ccaf3..046aeb2 100644
--- a/tests/daemon/face/factory-test-common.hpp
+++ b/tests/daemon/face/factory-test-common.hpp
@@ -1,5 +1,5 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
  * Copyright (c) 2014-2017,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
@@ -49,7 +49,7 @@
            bool wantLocalFieldsEnabled,
            const CreateFaceExpectedResult& expected)
 {
-  factory.createFace(remoteUri, localUri, persistency, wantLocalFieldsEnabled,
+  factory.createFace({remoteUri, localUri, persistency, wantLocalFieldsEnabled},
                      [expected] (const shared_ptr<Face>&) {
                        BOOST_CHECK_EQUAL(CreateFaceExpectedResult::SUCCESS, expected.result);
                      },
diff --git a/tests/daemon/face/tcp-factory.t.cpp b/tests/daemon/face/tcp-factory.t.cpp
index d994fa2..8dd12ec 100644
--- a/tests/daemon/face/tcp-factory.t.cpp
+++ b/tests/daemon/face/tcp-factory.t.cpp
@@ -260,10 +260,8 @@
 {
   factory.createChannel("0.0.0.0", "20070");
 
-  factory.createFace(FaceUri("tcp4://192.0.2.1:20070"),
-                     {},
-                     ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
-                     false,
+  factory.createFace({FaceUri("tcp4://192.0.2.1:20070"), {},
+                      ndn::nfd::FACE_PERSISTENCY_PERSISTENT, false},
                      bind(&FaceCreateTimeoutFixture::onFaceCreated, this, _1),
                      bind(&FaceCreateTimeoutFixture::onConnectFailed, this, _2));
 
diff --git a/tests/daemon/mgmt/face-manager.t.cpp b/tests/daemon/mgmt/face-manager.t.cpp
index 5f8eef0..03bdd78 100644
--- a/tests/daemon/mgmt/face-manager.t.cpp
+++ b/tests/daemon/mgmt/face-manager.t.cpp
@@ -268,10 +268,7 @@
   }
 
   void
-  createFace(const FaceUri& remoteUri,
-             const ndn::optional<FaceUri>& localUri,
-             ndn::nfd::FacePersistency persistency,
-             bool wantLocalFieldsEnabled,
+  createFace(const CreateFaceParams& params,
              const face::FaceCreatedCallback& onCreated,
              const face::FaceCreationFailedCallback& onConnectFailed) final
   {