blob: 5acb18f87c1eef0aabb360c0a589b8049e417b3b [file] [log] [blame]
Junxiao Shib47247d2017-01-24 15:09:16 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shi2d491752017-07-14 21:32:05 +00002/*
Davide Pesavento19779d82019-02-14 13:40:04 -05003 * Copyright (c) 2014-2019, Regents of the University of California,
Junxiao Shib47247d2017-01-24 15:09:16 +00004 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
10 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26#include "protocol-factory.hpp"
Davide Pesaventod27841b2018-11-13 00:22:24 -050027
Junxiao Shib47247d2017-01-24 15:09:16 +000028#include <boost/range/adaptor/map.hpp>
29#include <boost/range/algorithm/copy.hpp>
30
31namespace nfd {
32namespace face {
33
34ProtocolFactory::Registry&
35ProtocolFactory::getRegistry()
36{
37 static Registry registry;
38 return registry;
39}
40
41unique_ptr<ProtocolFactory>
Junxiao Shi0ba6d642017-07-17 00:53:22 +000042ProtocolFactory::create(const std::string& id, const CtorParams& params)
Junxiao Shib47247d2017-01-24 15:09:16 +000043{
44 Registry& registry = getRegistry();
45 auto found = registry.find(id);
Junxiao Shi2d491752017-07-14 21:32:05 +000046 if (found == registry.end()) {
47 return nullptr;
48 }
49
Junxiao Shi0ba6d642017-07-17 00:53:22 +000050 return found->second(params);
Junxiao Shib47247d2017-01-24 15:09:16 +000051}
52
53std::set<std::string>
54ProtocolFactory::listRegistered()
55{
56 std::set<std::string> factoryIds;
57 boost::copy(getRegistry() | boost::adaptors::map_keys,
58 std::inserter(factoryIds, factoryIds.end()));
59 return factoryIds;
60}
61
Junxiao Shi0ba6d642017-07-17 00:53:22 +000062ProtocolFactory::ProtocolFactory(const CtorParams& params)
63 : addFace(params.addFace)
64 , netmon(params.netmon)
65{
66 BOOST_ASSERT(addFace != nullptr);
67 BOOST_ASSERT(netmon != nullptr);
68}
69
Davide Pesaventod27841b2018-11-13 00:22:24 -050070ProtocolFactory::~ProtocolFactory() = default;
71
72void
73ProtocolFactory::processConfig(OptionalConfigSection configSection,
74 FaceSystem::ConfigContext& context)
75{
76 doProcessConfig(configSection, context);
77}
78
79void
80ProtocolFactory::doProcessConfig(OptionalConfigSection,
81 FaceSystem::ConfigContext&)
82{
83}
84
85void
86ProtocolFactory::createFace(const CreateFaceRequest& req,
87 const FaceCreatedCallback& onCreated,
88 const FaceCreationFailedCallback& onFailure)
89{
90 BOOST_ASSERT(!FaceUri::canCanonize(req.remoteUri.getScheme()) ||
91 req.remoteUri.isCanonical());
92 BOOST_ASSERT(!req.localUri || !FaceUri::canCanonize(req.localUri->getScheme()) ||
93 req.localUri->isCanonical());
94 doCreateFace(req, onCreated, onFailure);
95}
96
97void
98ProtocolFactory::doCreateFace(const CreateFaceRequest&,
99 const FaceCreatedCallback&,
100 const FaceCreationFailedCallback& onFailure)
101{
102 onFailure(406, "Unsupported protocol");
103}
104
Junxiao Shieef49a92018-11-10 12:19:36 +0000105shared_ptr<Face>
106ProtocolFactory::createNetdevBoundFace(const FaceUri& remote,
107 const shared_ptr<const ndn::net::NetworkInterface>& netif)
108{
109 BOOST_ASSERT(remote.isCanonical());
Davide Pesaventod27841b2018-11-13 00:22:24 -0500110 return doCreateNetdevBoundFace(remote, netif);
Junxiao Shieef49a92018-11-10 12:19:36 +0000111}
112
113shared_ptr<Face>
Davide Pesaventod27841b2018-11-13 00:22:24 -0500114ProtocolFactory::doCreateNetdevBoundFace(const FaceUri&,
115 const shared_ptr<const ndn::net::NetworkInterface>&)
Junxiao Shieef49a92018-11-10 12:19:36 +0000116{
Davide Pesavento19779d82019-02-14 13:40:04 -0500117 NDN_THROW(Error("This protocol factory does not support netdev-bound faces"));
Davide Pesaventod27841b2018-11-13 00:22:24 -0500118}
119
120std::vector<shared_ptr<const Channel>>
121ProtocolFactory::getChannels() const
122{
123 return doGetChannels();
124}
125
126std::vector<shared_ptr<const Channel>>
127ProtocolFactory::doGetChannels() const
128{
129 return {};
Junxiao Shieef49a92018-11-10 12:19:36 +0000130}
131
Junxiao Shib47247d2017-01-24 15:09:16 +0000132} // namespace face
133} // namespace nfd