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/unix-stream-factory.cpp b/daemon/face/unix-stream-factory.cpp
new file mode 100644
index 0000000..070d8c1
--- /dev/null
+++ b/daemon/face/unix-stream-factory.cpp
@@ -0,0 +1,41 @@
+/* -*- 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 "unix-stream-factory.hpp"
+#include "core/global-io.hpp"
+
+#include <boost/filesystem.hpp> // for canonical()
+
+namespace nfd {
+
+shared_ptr<UnixStreamChannel>
+UnixStreamFactory::create(const std::string& unixSocketPath)
+{
+ boost::filesystem::path p(unixSocketPath);
+ p = boost::filesystem::canonical(p.parent_path()) / p.filename();
+ unix_stream::Endpoint endpoint(p.string());
+
+ shared_ptr<UnixStreamChannel> channel = find(endpoint);
+ if (channel)
+ return channel;
+
+ channel = make_shared<UnixStreamChannel>(boost::ref(getGlobalIoService()),
+ boost::cref(endpoint));
+ m_channels[endpoint] = channel;
+ return channel;
+}
+
+shared_ptr<UnixStreamChannel>
+UnixStreamFactory::find(const unix_stream::Endpoint& endpoint)
+{
+ ChannelMap::iterator i = m_channels.find(endpoint);
+ if (i != m_channels.end())
+ return i->second;
+ else
+ return shared_ptr<UnixStreamChannel>();
+}
+
+} // namespace nfd