face: Convert to use the global IO service by all ChannelFactories

Change-Id: Ibd8d5cea142171b5700d8920eb3eedc084bbd588
diff --git a/daemon/face/channel-factory.hpp b/daemon/face/channel-factory.hpp
index 184703a..566063b 100644
--- a/daemon/face/channel-factory.hpp
+++ b/daemon/face/channel-factory.hpp
@@ -11,16 +11,9 @@
 
 namespace nfd {
 
-/**
- * \brief Base class for all channel factories
- */
-template<class E, class C>
 class ChannelFactory
 {
 public:
-  typedef E Endpoint;
-  typedef C Channel;
-  
   /**
    * \brief Base class for all exceptions thrown by channel factories
    */
@@ -29,9 +22,6 @@
     Error(const std::string& what) : std::runtime_error(what) {}
   };
 
-protected:
-  typedef std::map< Endpoint, shared_ptr<Channel> > ChannelMap;
-  ChannelMap m_channels;  
 };
 
 } // namespace nfd
diff --git a/daemon/face/ethernet-channel-factory.hpp b/daemon/face/ethernet-channel-factory.hpp
index 4f655bd..a9094af 100644
--- a/daemon/face/ethernet-channel-factory.hpp
+++ b/daemon/face/ethernet-channel-factory.hpp
@@ -8,18 +8,19 @@
 #define NFD_FACE_ETHERNET_CHANNEL_FACTORY_HPP
 
 #include "ethernet-face.hpp"
+#include "channel-factory.hpp"
 
 namespace nfd {
 
-class EthernetChannelFactory
+class EthernetChannelFactory : public ChannelFactory
 {
 public:
   /**
    * \brief Exception of EthernetChannelFactory
    */
-  struct Error : public std::runtime_error
+  struct Error : public ChannelFactory::Error
   {
-    Error(const std::string& what) : std::runtime_error(what) {}
+    Error(const std::string& what) : ChannelFactory::Error(what) {}
   };
 
   /**
diff --git a/daemon/face/tcp-channel-factory.cpp b/daemon/face/tcp-channel-factory.cpp
index be3a9d4..3a75183 100644
--- a/daemon/face/tcp-channel-factory.cpp
+++ b/daemon/face/tcp-channel-factory.cpp
@@ -5,14 +5,10 @@
  */
 
 #include "tcp-channel-factory.hpp"
+#include "core/global-io.hpp"
 
 namespace nfd {
 
-TcpChannelFactory::TcpChannelFactory(boost::asio::io_service& ioService)
-  : m_ioService(ioService)
-{
-}
-
 shared_ptr<TcpChannel>
 TcpChannelFactory::create(const tcp::Endpoint& endpoint)
 {
@@ -20,7 +16,7 @@
   if(static_cast<bool>(channel))
     return channel;
 
-  channel = make_shared<TcpChannel>(boost::ref(m_ioService), boost::cref(endpoint));
+  channel = make_shared<TcpChannel>(boost::ref(getGlobalIoService()), boost::cref(endpoint));
   m_channels[endpoint] = channel;
   return channel;
 }
@@ -29,11 +25,9 @@
 TcpChannelFactory::create(const std::string& localHost, const std::string& localPort)
 {
   using boost::asio::ip::tcp;
-  
+
   tcp::resolver::query query(localHost, localPort);
-  // shared_ptr<tcp::resolver> resolver =
-  //   make_shared<tcp::resolver>(boost::ref(m_ioService));
-  tcp::resolver resolver(m_ioService);
+  tcp::resolver resolver(getGlobalIoService());
 
   tcp::resolver::iterator end;
   tcp::resolver::iterator i = resolver.resolve(query);
diff --git a/daemon/face/tcp-channel-factory.hpp b/daemon/face/tcp-channel-factory.hpp
index 171c24f..c87cdf4 100644
--- a/daemon/face/tcp-channel-factory.hpp
+++ b/daemon/face/tcp-channel-factory.hpp
@@ -12,23 +12,17 @@
 
 namespace nfd {
 
-class TcpChannelFactory : public ChannelFactory<tcp::Endpoint, TcpChannel>
+class TcpChannelFactory : public ChannelFactory
 {
 public:
   /**
    * \brief Exception of TcpChannelFactory
    */
-  struct Error : public ChannelFactory<tcp::Endpoint, TcpChannel>::Error
+  struct Error : public ChannelFactory::Error
   {
-    Error(const std::string& what)
-      : ChannelFactory<tcp::Endpoint, TcpChannel>::Error(what)
-    {
-    }
+    Error(const std::string& what) : ChannelFactory::Error(what) {}
   };
 
-  explicit
-  TcpChannelFactory(boost::asio::io_service& ioService);
-
   /**
    * \brief Create TCP-based channel using tcp::Endpoint
    *
@@ -67,7 +61,7 @@
    * \brief Look up TcpChannel using specified local endpoint
    *
    * \returns shared pointer to the existing TcpChannel object
-   *          or empty shared pointer when such channel does not exist 
+   *          or empty shared pointer when such channel does not exist
    *
    * \throws never
    */
@@ -75,7 +69,8 @@
   find(const tcp::Endpoint& localEndpoint);
 
 private:
-  boost::asio::io_service& m_ioService;
+  typedef std::map< tcp::Endpoint, shared_ptr<TcpChannel> > ChannelMap;
+  ChannelMap m_channels;
 };
 
 } // namespace nfd
diff --git a/daemon/face/unix-stream-channel-factory.cpp b/daemon/face/unix-stream-channel-factory.cpp
index ededecd..040c1e2 100644
--- a/daemon/face/unix-stream-channel-factory.cpp
+++ b/daemon/face/unix-stream-channel-factory.cpp
@@ -5,13 +5,13 @@
  */
 
 #include "unix-stream-channel-factory.hpp"
+#include "core/global-io.hpp"
 
 #include <boost/filesystem.hpp> // for canonical()
 
 namespace nfd {
 
-UnixStreamChannelFactory::UnixStreamChannelFactory(boost::asio::io_service& ioService)
-  : m_ioService(ioService)
+UnixStreamChannelFactory::UnixStreamChannelFactory()
 {
 }
 
@@ -26,7 +26,7 @@
   if (channel)
     return channel;
 
-  channel = make_shared<UnixStreamChannel>(boost::ref(m_ioService),
+  channel = make_shared<UnixStreamChannel>(boost::ref(getGlobalIoService()),
                                            boost::cref(endpoint));
   m_channels[endpoint] = channel;
   return channel;
diff --git a/daemon/face/unix-stream-channel-factory.hpp b/daemon/face/unix-stream-channel-factory.hpp
index 8d0a6e7..bf14117 100644
--- a/daemon/face/unix-stream-channel-factory.hpp
+++ b/daemon/face/unix-stream-channel-factory.hpp
@@ -12,22 +12,19 @@
 
 namespace nfd {
 
-class UnixStreamChannelFactory : public ChannelFactory<unix_stream::Endpoint, UnixStreamChannel>
+class UnixStreamChannelFactory : public ChannelFactory
 {
 public:
   /**
    * \brief Exception of UnixStreamChannelFactory
    */
-  struct Error : public ChannelFactory<unix_stream::Endpoint, UnixStreamChannel>::Error
+  struct Error : public ChannelFactory::Error
   {
-    Error(const std::string& what)
-      : ChannelFactory<unix_stream::Endpoint, UnixStreamChannel>::Error(what)
-    {
-    }
+    Error(const std::string& what) : ChannelFactory::Error(what) {}
   };
 
   explicit
-  UnixStreamChannelFactory(boost::asio::io_service& ioService);
+  UnixStreamChannelFactory();
 
   /**
    * \brief Create stream-oriented Unix channel using specified socket path
@@ -57,7 +54,8 @@
   find(const unix_stream::Endpoint& endpoint);
 
 private:
-  boost::asio::io_service& m_ioService;
+  typedef std::map< unix_stream::Endpoint, shared_ptr<UnixStreamChannel> > ChannelMap;
+  ChannelMap m_channels;
 };
 
 } // namespace nfd
diff --git a/daemon/main.cpp b/daemon/main.cpp
index 2c83177..b8165f8 100644
--- a/daemon/main.cpp
+++ b/daemon/main.cpp
@@ -171,7 +171,7 @@
 void
 initializeTcp()
 {
-  g_tcpFactory = new TcpChannelFactory(getGlobalIoService());
+  g_tcpFactory = new TcpChannelFactory();
   g_tcpChannel = g_tcpFactory->create(g_options.m_tcpListen.first,
                                       g_options.m_tcpListen.second);
   g_tcpChannel->listen(
@@ -190,7 +190,7 @@
 void
 initializeUnix()
 {
-  g_unixFactory = new UnixStreamChannelFactory(getGlobalIoService());
+  g_unixFactory = new UnixStreamChannelFactory();
   g_unixChannel = g_unixFactory->create(g_options.m_unixListen);
 
   g_unixChannel->listen(