face: Rename all ChannelFactories to protocol Factories

Base class is ProtocolFactory and implementations are TcpFactory,
UnixStreamFactory, EthernetFactory.

Since Factories are doing more than just creating channels (some can
create faces directly), more general name is more appropriate.

Change-Id: I3d6c2460a1b29e244f8462453720f4e7785893ca
diff --git a/daemon/face/tcp-factory.cpp b/daemon/face/tcp-factory.cpp
new file mode 100644
index 0000000..072ce2e
--- /dev/null
+++ b/daemon/face/tcp-factory.cpp
@@ -0,0 +1,50 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (C) 2014 Named Data Networking Project
+ * See COPYING for copyright and distribution information.
+ */
+
+#include "tcp-factory.hpp"
+#include "core/global-io.hpp"
+
+namespace nfd {
+
+shared_ptr<TcpChannel>
+TcpFactory::create(const tcp::Endpoint& endpoint)
+{
+  shared_ptr<TcpChannel> channel = find(endpoint);
+  if(static_cast<bool>(channel))
+    return channel;
+
+  channel = make_shared<TcpChannel>(boost::ref(getGlobalIoService()), boost::cref(endpoint));
+  m_channels[endpoint] = channel;
+  return channel;
+}
+
+shared_ptr<TcpChannel>
+TcpFactory::create(const std::string& localHost, const std::string& localPort)
+{
+  using boost::asio::ip::tcp;
+
+  tcp::resolver::query query(localHost, localPort);
+  tcp::resolver resolver(getGlobalIoService());
+
+  tcp::resolver::iterator end;
+  tcp::resolver::iterator i = resolver.resolve(query);
+  if (i == end)
+    return shared_ptr<TcpChannel>();
+
+  return create(*i);
+}
+
+shared_ptr<TcpChannel>
+TcpFactory::find(const tcp::Endpoint& localEndpoint)
+{
+  ChannelMap::iterator i = m_channels.find(localEndpoint);
+  if (i != m_channels.end())
+    return i->second;
+  else
+    return shared_ptr<TcpChannel>();
+}
+
+} // namespace nfd