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/ethernet-channel-factory.cpp b/daemon/face/ethernet-factory.cpp
similarity index 80%
rename from daemon/face/ethernet-channel-factory.cpp
rename to daemon/face/ethernet-factory.cpp
index 86ad1a5..c8dbcf9 100644
--- a/daemon/face/ethernet-channel-factory.cpp
+++ b/daemon/face/ethernet-factory.cpp
@@ -4,7 +4,7 @@
* See COPYING for copyright and distribution information.
*/
-#include "ethernet-channel-factory.hpp"
+#include "ethernet-factory.hpp"
#include "core/global-io.hpp"
#include <boost/algorithm/string/predicate.hpp>
@@ -12,11 +12,11 @@
namespace nfd {
-NFD_LOG_INIT("EthernetChannelFactory")
+NFD_LOG_INIT("EthernetFactory")
shared_ptr<EthernetFace>
-EthernetChannelFactory::createMulticast(const ethernet::Endpoint& interface,
- const ethernet::Address& address)
+EthernetFactory::createMulticast(const ethernet::Endpoint& interface,
+ const ethernet::Address& address)
{
std::vector<ethernet::Endpoint> ifs = findAllInterfaces();
if (std::find(ifs.begin(), ifs.end(), interface) == ifs.end())
@@ -35,7 +35,7 @@
face = make_shared<EthernetFace>(boost::cref(socket),
boost::cref(interface),
boost::cref(address));
- face->onFail += bind(&EthernetChannelFactory::afterFaceFailed,
+ face->onFail += bind(&EthernetFactory::afterFaceFailed,
this, interface, address);
m_multicastFaces[std::make_pair(interface, address)] = face;
@@ -43,7 +43,7 @@
}
std::vector<ethernet::Endpoint>
-EthernetChannelFactory::findAllInterfaces()
+EthernetFactory::findAllInterfaces()
{
std::vector<ethernet::Endpoint> interfaces;
char errbuf[PCAP_ERRBUF_SIZE];
@@ -84,16 +84,16 @@
}
void
-EthernetChannelFactory::afterFaceFailed(const ethernet::Endpoint& interface,
- const ethernet::Address& address)
+EthernetFactory::afterFaceFailed(const ethernet::Endpoint& interface,
+ const ethernet::Address& address)
{
NFD_LOG_DEBUG("afterFaceFailed: " << interface << "/" << address);
m_multicastFaces.erase(std::make_pair(interface, address));
}
shared_ptr<EthernetFace>
-EthernetChannelFactory::findMulticast(const ethernet::Endpoint& interface,
- const ethernet::Address& address) const
+EthernetFactory::findMulticast(const ethernet::Endpoint& interface,
+ const ethernet::Address& address) const
{
MulticastFacesMap::const_iterator i = m_multicastFaces.find(std::make_pair(interface, address));
if (i != m_multicastFaces.end())
diff --git a/daemon/face/ethernet-channel-factory.hpp b/daemon/face/ethernet-factory.hpp
similarity index 80%
rename from daemon/face/ethernet-channel-factory.hpp
rename to daemon/face/ethernet-factory.hpp
index a9094af..d676f47 100644
--- a/daemon/face/ethernet-channel-factory.hpp
+++ b/daemon/face/ethernet-factory.hpp
@@ -4,23 +4,23 @@
* See COPYING for copyright and distribution information.
*/
-#ifndef NFD_FACE_ETHERNET_CHANNEL_FACTORY_HPP
-#define NFD_FACE_ETHERNET_CHANNEL_FACTORY_HPP
+#ifndef NFD_FACE_ETHERNET_FACTORY_HPP
+#define NFD_FACE_ETHERNET_FACTORY_HPP
#include "ethernet-face.hpp"
-#include "channel-factory.hpp"
+#include "protocol-factory.hpp"
namespace nfd {
-class EthernetChannelFactory : public ChannelFactory
+class EthernetFactory : public ProtocolFactory
{
public:
/**
- * \brief Exception of EthernetChannelFactory
+ * \brief Exception of EthernetFactory
*/
- struct Error : public ChannelFactory::Error
+ struct Error : public ProtocolFactory::Error
{
- Error(const std::string& what) : ChannelFactory::Error(what) {}
+ Error(const std::string& what) : ProtocolFactory::Error(what) {}
};
/**
@@ -36,7 +36,7 @@
* \returns always a valid shared pointer to an EthernetFace object,
* an exception will be thrown if the creation fails
*
- * \throws EthernetChannelFactory::Error or EthernetFace::Error
+ * \throws EthernetFactory::Error or EthernetFace::Error
*/
shared_ptr<EthernetFace>
createMulticast(const ethernet::Endpoint& interface,
@@ -75,4 +75,4 @@
} // namespace nfd
-#endif // NFD_FACE_ETHERNET_CHANNEL_FACTORY_HPP
+#endif // NFD_FACE_ETHERNET_FACTORY_HPP
diff --git a/daemon/face/channel-factory.hpp b/daemon/face/protocol-factory.hpp
similarity index 76%
rename from daemon/face/channel-factory.hpp
rename to daemon/face/protocol-factory.hpp
index 566063b..f02941e 100644
--- a/daemon/face/channel-factory.hpp
+++ b/daemon/face/protocol-factory.hpp
@@ -4,14 +4,14 @@
* See COPYING for copyright and distribution information.
*/
-#ifndef NFD_FACE_CHANNEL_FACTORY_HPP
-#define NFD_FACE_CHANNEL_FACTORY_HPP
+#ifndef NFD_FACE_PROTOCOL_FACTORY_HPP
+#define NFD_FACE_PROTOCOL_FACTORY_HPP
#include "common.hpp"
namespace nfd {
-class ChannelFactory
+class ProtocolFactory
{
public:
/**
@@ -21,9 +21,8 @@
{
Error(const std::string& what) : std::runtime_error(what) {}
};
-
};
} // namespace nfd
-#endif // NFD_FACE_CHANNEL_FACTORY_HPP
+#endif // NFD_FACE_PROTOCOL_FACTORY_HPP
diff --git a/daemon/face/tcp-channel-factory.cpp b/daemon/face/tcp-factory.cpp
similarity index 81%
rename from daemon/face/tcp-channel-factory.cpp
rename to daemon/face/tcp-factory.cpp
index 3a75183..072ce2e 100644
--- a/daemon/face/tcp-channel-factory.cpp
+++ b/daemon/face/tcp-factory.cpp
@@ -4,13 +4,13 @@
* See COPYING for copyright and distribution information.
*/
-#include "tcp-channel-factory.hpp"
+#include "tcp-factory.hpp"
#include "core/global-io.hpp"
namespace nfd {
shared_ptr<TcpChannel>
-TcpChannelFactory::create(const tcp::Endpoint& endpoint)
+TcpFactory::create(const tcp::Endpoint& endpoint)
{
shared_ptr<TcpChannel> channel = find(endpoint);
if(static_cast<bool>(channel))
@@ -22,7 +22,7 @@
}
shared_ptr<TcpChannel>
-TcpChannelFactory::create(const std::string& localHost, const std::string& localPort)
+TcpFactory::create(const std::string& localHost, const std::string& localPort)
{
using boost::asio::ip::tcp;
@@ -38,7 +38,7 @@
}
shared_ptr<TcpChannel>
-TcpChannelFactory::find(const tcp::Endpoint& localEndpoint)
+TcpFactory::find(const tcp::Endpoint& localEndpoint)
{
ChannelMap::iterator i = m_channels.find(localEndpoint);
if (i != m_channels.end())
diff --git a/daemon/face/tcp-channel-factory.hpp b/daemon/face/tcp-factory.hpp
similarity index 77%
rename from daemon/face/tcp-channel-factory.hpp
rename to daemon/face/tcp-factory.hpp
index c87cdf4..fbda795 100644
--- a/daemon/face/tcp-channel-factory.hpp
+++ b/daemon/face/tcp-factory.hpp
@@ -4,23 +4,23 @@
* See COPYING for copyright and distribution information.
*/
-#ifndef NFD_FACE_TCP_CHANNEL_FACTORY_HPP
-#define NFD_FACE_TCP_CHANNEL_FACTORY_HPP
+#ifndef NFD_FACE_TCP_FACTORY_HPP
+#define NFD_FACE_TCP_FACTORY_HPP
-#include "channel-factory.hpp"
+#include "protocol-factory.hpp"
#include "tcp-channel.hpp"
namespace nfd {
-class TcpChannelFactory : public ChannelFactory
+class TcpFactory : public ProtocolFactory
{
public:
/**
- * \brief Exception of TcpChannelFactory
+ * \brief Exception of TcpFactory
*/
- struct Error : public ChannelFactory::Error
+ struct Error : public ProtocolFactory::Error
{
- Error(const std::string& what) : ChannelFactory::Error(what) {}
+ Error(const std::string& what) : ProtocolFactory::Error(what) {}
};
/**
@@ -35,7 +35,7 @@
* \returns always a valid pointer to a TcpChannel object, an exception
* is thrown if it cannot be created.
*
- * \throws TcpChannelFactory::Error
+ * \throws TcpFactory::Error
*
* \see http://www.boost.org/doc/libs/1_42_0/doc/html/boost_asio/reference/ip__tcp/endpoint.html
* for details on ways to create tcp::Endpoint
@@ -47,11 +47,11 @@
* \brief Create TCP-based channel using specified host and port number
*
* This method will attempt to resolve the provided host and port numbers
- * and will throw TcpChannelFactory::Error when channel cannot be created.
+ * and will throw TcpFactory::Error when channel cannot be created.
*
* Note that this call will **BLOCK** until resolution is done or failed.
*
- * \throws TcpChannelFactory::Error
+ * \throws TcpFactory::Error
*/
shared_ptr<TcpChannel>
create(const std::string& localHost, const std::string& localPort);
@@ -75,4 +75,4 @@
} // namespace nfd
-#endif // NFD_FACE_TCP_CHANNEL_FACTORY_HPP
+#endif // NFD_FACE_TCP_FACTORY_HPP
diff --git a/daemon/face/unix-stream-channel-factory.cpp b/daemon/face/unix-stream-factory.cpp
similarity index 80%
rename from daemon/face/unix-stream-channel-factory.cpp
rename to daemon/face/unix-stream-factory.cpp
index 040c1e2..070d8c1 100644
--- a/daemon/face/unix-stream-channel-factory.cpp
+++ b/daemon/face/unix-stream-factory.cpp
@@ -4,19 +4,15 @@
* See COPYING for copyright and distribution information.
*/
-#include "unix-stream-channel-factory.hpp"
+#include "unix-stream-factory.hpp"
#include "core/global-io.hpp"
#include <boost/filesystem.hpp> // for canonical()
namespace nfd {
-UnixStreamChannelFactory::UnixStreamChannelFactory()
-{
-}
-
shared_ptr<UnixStreamChannel>
-UnixStreamChannelFactory::create(const std::string& unixSocketPath)
+UnixStreamFactory::create(const std::string& unixSocketPath)
{
boost::filesystem::path p(unixSocketPath);
p = boost::filesystem::canonical(p.parent_path()) / p.filename();
@@ -33,7 +29,7 @@
}
shared_ptr<UnixStreamChannel>
-UnixStreamChannelFactory::find(const unix_stream::Endpoint& endpoint)
+UnixStreamFactory::find(const unix_stream::Endpoint& endpoint)
{
ChannelMap::iterator i = m_channels.find(endpoint);
if (i != m_channels.end())
diff --git a/daemon/face/unix-stream-channel-factory.hpp b/daemon/face/unix-stream-factory.hpp
similarity index 71%
rename from daemon/face/unix-stream-channel-factory.hpp
rename to daemon/face/unix-stream-factory.hpp
index bf14117..4b26a3f 100644
--- a/daemon/face/unix-stream-channel-factory.hpp
+++ b/daemon/face/unix-stream-factory.hpp
@@ -4,28 +4,25 @@
* See COPYING for copyright and distribution information.
*/
-#ifndef NFD_FACE_UNIX_STREAM_CHANNEL_FACTORY_HPP
-#define NFD_FACE_UNIX_STREAM_CHANNEL_FACTORY_HPP
+#ifndef NFD_FACE_UNIX_STREAM_FACTORY_HPP
+#define NFD_FACE_UNIX_STREAM_FACTORY_HPP
-#include "channel-factory.hpp"
+#include "protocol-factory.hpp"
#include "unix-stream-channel.hpp"
namespace nfd {
-class UnixStreamChannelFactory : public ChannelFactory
+class UnixStreamFactory : public ProtocolFactory
{
public:
/**
- * \brief Exception of UnixStreamChannelFactory
+ * \brief Exception of UnixStreamFactory
*/
- struct Error : public ChannelFactory::Error
+ struct Error : public ProtocolFactory::Error
{
- Error(const std::string& what) : ChannelFactory::Error(what) {}
+ Error(const std::string& what) : ProtocolFactory::Error(what) {}
};
- explicit
- UnixStreamChannelFactory();
-
/**
* \brief Create stream-oriented Unix channel using specified socket path
*
@@ -36,7 +33,7 @@
* \returns always a valid pointer to a UnixStreamChannel object,
* an exception will be thrown if the channel cannot be created.
*
- * \throws UnixStreamChannelFactory::Error
+ * \throws UnixStreamFactory::Error
*/
shared_ptr<UnixStreamChannel>
create(const std::string& unixSocketPath);
@@ -60,4 +57,4 @@
} // namespace nfd
-#endif // NFD_FACE_UNIX_STREAM_CHANNEL_FACTORY_HPP
+#endif // NFD_FACE_UNIX_STREAM_FACTORY_HPP
diff --git a/daemon/main.cpp b/daemon/main.cpp
index b8165f8..e971a35 100644
--- a/daemon/main.cpp
+++ b/daemon/main.cpp
@@ -10,10 +10,10 @@
#include "mgmt/internal-face.hpp"
#include "mgmt/fib-manager.hpp"
#include "mgmt/local-control-header-manager.hpp"
-#include "face/tcp-channel-factory.hpp"
+#include "face/tcp-factory.hpp"
#ifdef HAVE_UNIX_SOCKETS
-#include "face/unix-stream-channel-factory.hpp"
+#include "face/unix-stream-factory.hpp"
#endif
namespace nfd {
@@ -43,12 +43,12 @@
static Forwarder* g_forwarder;
static FibManager* g_fibManager;
static LocalControlHeaderManager* g_localControlHeaderManager;
-static TcpChannelFactory* g_tcpFactory;
+static TcpFactory* g_tcpFactory;
static shared_ptr<TcpChannel> g_tcpChannel;
static shared_ptr<InternalFace> g_internalFace;
#ifdef HAVE_UNIX_SOCKETS
-static UnixStreamChannelFactory* g_unixFactory;
+static UnixStreamFactory* g_unixFactory;
static shared_ptr<UnixStreamChannel> g_unixChannel;
#endif
@@ -171,7 +171,7 @@
void
initializeTcp()
{
- g_tcpFactory = new TcpChannelFactory();
+ g_tcpFactory = new TcpFactory();
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();
+ g_unixFactory = new UnixStreamFactory();
g_unixChannel = g_unixFactory->create(g_options.m_unixListen);
g_unixChannel->listen(
diff --git a/daemon/mgmt/manager-base.hpp b/daemon/mgmt/manager-base.hpp
index 8fb8cd3..78c6efe 100644
--- a/daemon/mgmt/manager-base.hpp
+++ b/daemon/mgmt/manager-base.hpp
@@ -19,6 +19,11 @@
class ManagerBase
{
public:
+ struct Error : public std::runtime_error
+ {
+ Error(const std::string& what) : std::runtime_error(what) {}
+ };
+
ManagerBase(shared_ptr<AppFace> face);
virtual
diff --git a/tests/face/ethernet.cpp b/tests/face/ethernet.cpp
index f03cb68..f2e7134 100644
--- a/tests/face/ethernet.cpp
+++ b/tests/face/ethernet.cpp
@@ -4,7 +4,7 @@
* See COPYING for copyright and distribution information.
*/
-#include "face/ethernet-channel-factory.hpp"
+#include "face/ethernet-factory.hpp"
#include <ndn-cpp-dev/security/key-chain.hpp>
#include "tests/test-common.hpp"
@@ -16,9 +16,9 @@
BOOST_AUTO_TEST_CASE(MulticastFacesMap)
{
- EthernetChannelFactory factory;
+ EthernetFactory factory;
- std::vector<ethernet::Endpoint> interfaces = EthernetChannelFactory::findAllInterfaces();
+ std::vector<ethernet::Endpoint> interfaces = EthernetFactory::findAllInterfaces();
if (interfaces.size() > 0)
{
shared_ptr<EthernetFace> face1;
@@ -56,9 +56,9 @@
BOOST_AUTO_TEST_CASE(SendPacket)
{
- EthernetChannelFactory factory;
+ EthernetFactory factory;
- std::vector<ethernet::Endpoint> interfaces = EthernetChannelFactory::findAllInterfaces();
+ std::vector<ethernet::Endpoint> interfaces = EthernetFactory::findAllInterfaces();
if (interfaces.empty())
{
BOOST_WARN_MESSAGE(interfaces.empty(),
diff --git a/tests/face/tcp.cpp b/tests/face/tcp.cpp
index cba8796..bc65c8b 100644
--- a/tests/face/tcp.cpp
+++ b/tests/face/tcp.cpp
@@ -4,7 +4,7 @@
* See COPYING for copyright and distribution information.
*/
-#include "face/tcp-channel-factory.hpp"
+#include "face/tcp-factory.hpp"
#include "core/scheduler.hpp"
#include <ndn-cpp-dev/security/key-chain.hpp>
@@ -17,7 +17,7 @@
BOOST_AUTO_TEST_CASE(ChannelMap)
{
- TcpChannelFactory factory;
+ TcpFactory factory;
shared_ptr<TcpChannel> channel1 = factory.create("127.0.0.1", "20070");
shared_ptr<TcpChannel> channel1a = factory.create("127.0.0.1", "20070");
@@ -174,7 +174,7 @@
BOOST_FIXTURE_TEST_CASE(EndToEnd, EndToEndFixture)
{
- TcpChannelFactory factory;
+ TcpFactory factory;
EventId abortEvent =
scheduler::schedule(time::seconds(10),
@@ -250,7 +250,7 @@
BOOST_FIXTURE_TEST_CASE(MultipleAccepts, EndToEndFixture)
{
- TcpChannelFactory factory;
+ TcpFactory factory;
EventId abortEvent =
scheduler::schedule(time::seconds(10),
@@ -317,7 +317,7 @@
BOOST_FIXTURE_TEST_CASE(FaceClosing, EndToEndFixture)
{
- TcpChannelFactory factory;
+ TcpFactory factory;
EventId abortEvent =
scheduler::schedule(time::seconds(10),
diff --git a/tests/face/unix-stream.cpp b/tests/face/unix-stream.cpp
index 85bac65..c7cec87 100644
--- a/tests/face/unix-stream.cpp
+++ b/tests/face/unix-stream.cpp
@@ -4,7 +4,7 @@
* See COPYING for copyright and distribution information.
*/
-#include "face/unix-stream-channel-factory.hpp"
+#include "face/unix-stream-factory.hpp"
#include "core/scheduler.hpp"
#include <ndn-cpp-dev/security/key-chain.hpp>
@@ -19,7 +19,7 @@
BOOST_AUTO_TEST_CASE(ChannelMap)
{
- UnixStreamChannelFactory factory;
+ UnixStreamFactory factory;
shared_ptr<UnixStreamChannel> channel1 = factory.create("foo");
shared_ptr<UnixStreamChannel> channel1a = factory.create("foo");
@@ -140,7 +140,7 @@
BOOST_FIXTURE_TEST_CASE(EndToEnd, EndToEndFixture)
{
- UnixStreamChannelFactory factory;
+ UnixStreamFactory factory;
EventId abortEvent =
scheduler::schedule(time::seconds(1),
@@ -210,7 +210,7 @@
BOOST_FIXTURE_TEST_CASE(MultipleAccepts, EndToEndFixture)
{
- UnixStreamChannelFactory factory;
+ UnixStreamFactory factory;
EventId abortEvent =
scheduler::schedule(time::seconds(1),
@@ -312,7 +312,7 @@
BOOST_FIXTURE_TEST_CASE(UnixStreamFaceLocalControlHeader, EndToEndFixture)
{
- UnixStreamChannelFactory factory;
+ UnixStreamFactory factory;
EventId abortEvent =
scheduler::schedule(time::seconds(1),