face: Parametrizing DatagramFace to correct MulticastUdpFace logging

Change-Id: I8a117dd0209b3babe3b7df35cd692c268c059866
Refs: #1675
diff --git a/daemon/face/datagram-face.hpp b/daemon/face/datagram-face.hpp
index 2dbe8fa..bae4fb2 100644
--- a/daemon/face/datagram-face.hpp
+++ b/daemon/face/datagram-face.hpp
@@ -21,7 +21,7 @@
  *
  * You should have received a copy of the GNU General Public License along with
  * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
- **/
+ */
 
 #ifndef NFD_DAEMON_FACE_DATAGRAM_FACE_HPP
 #define NFD_DAEMON_FACE_DATAGRAM_FACE_HPP
@@ -31,7 +31,10 @@
 
 namespace nfd {
 
-template <class Protocol>
+class Unicast {};
+class Multicast {};
+
+template<class Protocol, class Type = Unicast>
 class DatagramFace : public Face
 {
 public:
@@ -101,54 +104,54 @@
 };
 
 
-template <class T>
+template<class T, class U>
 inline
-DatagramFace<T>::DatagramFace(const FaceUri& remoteUri, const FaceUri& localUri,
-                              const shared_ptr<typename DatagramFace::protocol::socket>& socket,
-                              bool isOnDemand)
+DatagramFace<T, U>::DatagramFace(const FaceUri& remoteUri, const FaceUri& localUri,
+                                 const shared_ptr<typename DatagramFace::protocol::socket>& socket,
+                                 bool isOnDemand)
   : Face(remoteUri, localUri)
   , m_socket(socket)
 {
   setOnDemand(isOnDemand);
 
   m_socket->async_receive(boost::asio::buffer(m_inputBuffer, MAX_NDN_PACKET_SIZE), 0,
-                          bind(&DatagramFace<T>::handleReceive, this, _1, _2));
+                          bind(&DatagramFace<T, U>::handleReceive, this, _1, _2));
 }
 
-template <class T>
+template<class T, class U>
 inline
-DatagramFace<T>::~DatagramFace()
+DatagramFace<T, U>::~DatagramFace()
 {
 }
 
-template <class T>
+template<class T, class U>
 inline void
-DatagramFace<T>::sendInterest(const Interest& interest)
+DatagramFace<T, U>::sendInterest(const Interest& interest)
 {
   this->onSendInterest(interest);
   m_socket->async_send(boost::asio::buffer(interest.wireEncode().wire(),
                                            interest.wireEncode().size()),
-                       bind(&DatagramFace<T>::handleSend, this, _1, interest.wireEncode()));
+                       bind(&DatagramFace<T, U>::handleSend, this, _1, interest.wireEncode()));
 
   // anything else should be done here?
 }
 
-template <class T>
+template<class T, class U>
 inline void
-DatagramFace<T>::sendData(const Data& data)
+DatagramFace<T, U>::sendData(const Data& data)
 {
   this->onSendData(data);
   m_socket->async_send(boost::asio::buffer(data.wireEncode().wire(),
                                            data.wireEncode().size()),
-                       bind(&DatagramFace<T>::handleSend, this, _1, data.wireEncode()));
+                       bind(&DatagramFace<T, U>::handleSend, this, _1, data.wireEncode()));
 
   // anything else should be done here?
 }
 
-template <class T>
+template<class T, class U>
 inline void
-DatagramFace<T>::handleSend(const boost::system::error_code& error,
-                            const Block& wire)
+DatagramFace<T, U>::handleSend(const boost::system::error_code& error,
+                               const Block& wire)
 {
   if (error != 0) {
     if (error == boost::system::errc::operation_canceled) // when socket is closed by someone
@@ -185,9 +188,9 @@
   // do nothing (needed to retain validity of wire memory block
 }
 
-template <class T>
+template<class T, class U>
 inline void
-DatagramFace<T>::close()
+DatagramFace<T, U>::close()
 {
   if (!m_socket->is_open())
     return;
@@ -200,23 +203,23 @@
   fail("Close tunnel");
 }
 
-template <class T>
+template<class T, class U>
 inline void
-DatagramFace<T>::handleReceive(const boost::system::error_code& error,
-                               size_t nBytesReceived)
+DatagramFace<T, U>::handleReceive(const boost::system::error_code& error,
+                                  size_t nBytesReceived)
 {
   NFD_LOG_DEBUG("handleReceive: " << nBytesReceived);
   receiveDatagram(m_inputBuffer, nBytesReceived, error);
   if (m_socket->is_open())
     m_socket->async_receive(boost::asio::buffer(m_inputBuffer, MAX_NDN_PACKET_SIZE), 0,
-                            bind(&DatagramFace<T>::handleReceive, this, _1, _2));
+                            bind(&DatagramFace<T, U>::handleReceive, this, _1, _2));
 }
 
-template <class T>
+template<class T, class U>
 inline void
-DatagramFace<T>::receiveDatagram(const uint8_t* buffer,
-                                 size_t nBytesReceived,
-                                 const boost::system::error_code& error)
+DatagramFace<T, U>::receiveDatagram(const uint8_t* buffer,
+                                    size_t nBytesReceived,
+                                    const boost::system::error_code& error)
 {
   if (error != 0 || nBytesReceived == 0) {
     if (error == boost::system::errc::operation_canceled) // when socket is closed by someone
@@ -287,15 +290,15 @@
 }
 
 
-template <class T>
+template<class T, class U>
 inline void
-DatagramFace<T>::keepFaceAliveUntilAllHandlersExecuted(const shared_ptr<Face>& face)
+DatagramFace<T, U>::keepFaceAliveUntilAllHandlersExecuted(const shared_ptr<Face>& face)
 {
 }
 
-template <class T>
+template<class T, class U>
 inline void
-DatagramFace<T>::closeSocket()
+DatagramFace<T, U>::closeSocket()
 {
   NFD_LOG_DEBUG("closeSocket  " << m_socket->local_endpoint());
   boost::asio::io_service& io = m_socket->get_io_service();
@@ -308,27 +311,27 @@
 
   // ensure that the Face object is alive at least until all pending
   // handlers are dispatched
-  io.post(bind(&DatagramFace<T>::keepFaceAliveUntilAllHandlersExecuted,
+  io.post(bind(&DatagramFace<T, U>::keepFaceAliveUntilAllHandlersExecuted,
                this, this->shared_from_this()));
 }
 
-template <class T>
+template<class T, class U>
 inline void
-DatagramFace<T>::setOnDemand(bool isOnDemand)
+DatagramFace<T, U>::setOnDemand(bool isOnDemand)
 {
   Face::setOnDemand(isOnDemand);
 }
 
-template <class T>
+template<class T, class U>
 inline void
-DatagramFace<T>::resetRecentUsage()
+DatagramFace<T, U>::resetRecentUsage()
 {
   m_hasBeenUsedRecently = false;
 }
 
-template <class T>
+template<class T, class U>
 inline bool
-DatagramFace<T>::hasBeenUsedRecently() const
+DatagramFace<T, U>::hasBeenUsedRecently() const
 {
   return m_hasBeenUsedRecently;
 }
diff --git a/daemon/face/multicast-udp-face.cpp b/daemon/face/multicast-udp-face.cpp
index 75c691e..d12ba5b 100644
--- a/daemon/face/multicast-udp-face.cpp
+++ b/daemon/face/multicast-udp-face.cpp
@@ -1,11 +1,12 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014  Regents of the University of California,
- *                     Arizona Board of Regents,
- *                     Colorado State University,
- *                     University Pierre & Marie Curie, Sorbonne University,
- *                     Washington University in St. Louis,
- *                     Beijing Institute of Technology
+ * Copyright (c) 2014,  Regents of the University of California,
+ *                      Arizona Board of Regents,
+ *                      Colorado State University,
+ *                      University Pierre & Marie Curie, Sorbonne University,
+ *                      Washington University in St. Louis,
+ *                      Beijing Institute of Technology,
+ *                      The University of Memphis
  *
  * This file is part of NFD (Named Data Networking Forwarding Daemon).
  * See AUTHORS.md for complete list of NFD authors and contributors.
@@ -20,20 +21,22 @@
  *
  * You should have received a copy of the GNU General Public License along with
  * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
- **/
+ */
 
 #include "multicast-udp-face.hpp"
 
 namespace nfd {
 
-NFD_LOG_INIT("MulticastUdpFace");
+NFD_LOG_INCLASS_2TEMPLATE_SPECIALIZATION_DEFINE(DatagramFace,
+                                                MulticastUdpFace::protocol, Multicast,
+                                                "MulticastUdpFace");
 
 MulticastUdpFace::MulticastUdpFace(const shared_ptr<MulticastUdpFace::protocol::socket>& socket,
                                    const MulticastUdpFace::protocol::endpoint& localEndpoint)
-  : DatagramFace<protocol>(FaceUri(socket->local_endpoint()),
-                           FaceUri(localEndpoint),
-                           socket, false)
-  , m_multicastGroup(m_socket->local_endpoint())
+  : DatagramFace<protocol, Multicast>(FaceUri(socket->local_endpoint()),
+                                      FaceUri(localEndpoint),
+                                      socket, false)
+  , m_multicastGroup(socket->local_endpoint())
 {
   NFD_LOG_INFO("Creating multicast UDP face for group " << m_multicastGroup);
 }
@@ -45,17 +48,21 @@
 }
 
 void
+MulticastUdpFace::sendBlock(const Block& block)
+{
+  m_socket->async_send_to(boost::asio::buffer(block.wire(), block.size()),
+                          m_multicastGroup,
+                          bind(&DatagramFace<protocol, Multicast>::handleSend,
+                               this, _1, block));
+}
+
+void
 MulticastUdpFace::sendInterest(const Interest& interest)
 {
   onSendInterest(interest);
 
   NFD_LOG_DEBUG("Sending interest");
-  m_socket->async_send_to(boost::asio::buffer(interest.wireEncode().wire(),
-                                              interest.wireEncode().size()),
-                          m_multicastGroup,
-                          bind(&DatagramFace<protocol>::handleSend, this, _1, interest.wireEncode()));
-
-  // anything else should be done here?
+  sendBlock(interest.wireEncode());
 }
 
 void
@@ -66,12 +73,7 @@
   onSendData(data);
 
   NFD_LOG_DEBUG("Sending data");
-  m_socket->async_send_to(boost::asio::buffer(data.wireEncode().wire(),
-                                              data.wireEncode().size()),
-                          m_multicastGroup,
-                          bind(&DatagramFace<protocol>::handleSend, this, _1, data.wireEncode()));
-
-  // anything else should be done here?
+  sendBlock(data.wireEncode());
 }
 
 bool
diff --git a/daemon/face/multicast-udp-face.hpp b/daemon/face/multicast-udp-face.hpp
index 3a5c75d..743cf56 100644
--- a/daemon/face/multicast-udp-face.hpp
+++ b/daemon/face/multicast-udp-face.hpp
@@ -1,11 +1,12 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014  Regents of the University of California,
- *                     Arizona Board of Regents,
- *                     Colorado State University,
- *                     University Pierre & Marie Curie, Sorbonne University,
- *                     Washington University in St. Louis,
- *                     Beijing Institute of Technology
+ * Copyright (c) 2014,  Regents of the University of California,
+ *                      Arizona Board of Regents,
+ *                      Colorado State University,
+ *                      University Pierre & Marie Curie, Sorbonne University,
+ *                      Washington University in St. Louis,
+ *                      Beijing Institute of Technology,
+ *                      The University of Memphis
  *
  * This file is part of NFD (Named Data Networking Forwarding Daemon).
  * See AUTHORS.md for complete list of NFD authors and contributors.
@@ -20,7 +21,7 @@
  *
  * You should have received a copy of the GNU General Public License along with
  * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
- **/
+ */
 
 #ifndef NFD_DAEMON_FACE_MULTICAST_UDP_FACE_HPP
 #define NFD_DAEMON_FACE_MULTICAST_UDP_FACE_HPP
@@ -33,7 +34,7 @@
  * \brief Implementation of Face abstraction that uses
  *        multicast UDP as underlying transport mechanism
  */
-class MulticastUdpFace : public DatagramFace<boost::asio::ip::udp>
+class MulticastUdpFace : public DatagramFace<boost::asio::ip::udp, Multicast>
 {
 public:
   /**
@@ -56,6 +57,10 @@
   isMultiAccess() const;
 
 private:
+  void
+  sendBlock(const Block& block);
+
+private:
   protocol::endpoint m_multicastGroup;
 };