Junxiao Shi | b47247d | 2017-01-24 15:09:16 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 2d49175 | 2017-07-14 21:32:05 +0000 | [diff] [blame] | 2 | /* |
Davide Pesavento | 19779d8 | 2019-02-14 13:40:04 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2019, Regents of the University of California, |
Junxiao Shi | b47247d | 2017-01-24 15:09:16 +0000 | [diff] [blame] | 4 | * 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 Pesavento | d27841b | 2018-11-13 00:22:24 -0500 | [diff] [blame] | 27 | |
Junxiao Shi | b47247d | 2017-01-24 15:09:16 +0000 | [diff] [blame] | 28 | #include <boost/range/adaptor/map.hpp> |
| 29 | #include <boost/range/algorithm/copy.hpp> |
| 30 | |
| 31 | namespace nfd { |
| 32 | namespace face { |
| 33 | |
| 34 | ProtocolFactory::Registry& |
| 35 | ProtocolFactory::getRegistry() |
| 36 | { |
| 37 | static Registry registry; |
| 38 | return registry; |
| 39 | } |
| 40 | |
| 41 | unique_ptr<ProtocolFactory> |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame] | 42 | ProtocolFactory::create(const std::string& id, const CtorParams& params) |
Junxiao Shi | b47247d | 2017-01-24 15:09:16 +0000 | [diff] [blame] | 43 | { |
| 44 | Registry& registry = getRegistry(); |
| 45 | auto found = registry.find(id); |
Junxiao Shi | 2d49175 | 2017-07-14 21:32:05 +0000 | [diff] [blame] | 46 | if (found == registry.end()) { |
| 47 | return nullptr; |
| 48 | } |
| 49 | |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame] | 50 | return found->second(params); |
Junxiao Shi | b47247d | 2017-01-24 15:09:16 +0000 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | std::set<std::string> |
| 54 | ProtocolFactory::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 Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame] | 62 | ProtocolFactory::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 Pesavento | d27841b | 2018-11-13 00:22:24 -0500 | [diff] [blame] | 70 | ProtocolFactory::~ProtocolFactory() = default; |
| 71 | |
| 72 | void |
| 73 | ProtocolFactory::processConfig(OptionalConfigSection configSection, |
| 74 | FaceSystem::ConfigContext& context) |
| 75 | { |
| 76 | doProcessConfig(configSection, context); |
| 77 | } |
| 78 | |
| 79 | void |
| 80 | ProtocolFactory::doProcessConfig(OptionalConfigSection, |
| 81 | FaceSystem::ConfigContext&) |
| 82 | { |
| 83 | } |
| 84 | |
| 85 | void |
| 86 | ProtocolFactory::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 | |
| 97 | void |
| 98 | ProtocolFactory::doCreateFace(const CreateFaceRequest&, |
| 99 | const FaceCreatedCallback&, |
| 100 | const FaceCreationFailedCallback& onFailure) |
| 101 | { |
| 102 | onFailure(406, "Unsupported protocol"); |
| 103 | } |
| 104 | |
Junxiao Shi | eef49a9 | 2018-11-10 12:19:36 +0000 | [diff] [blame] | 105 | shared_ptr<Face> |
| 106 | ProtocolFactory::createNetdevBoundFace(const FaceUri& remote, |
| 107 | const shared_ptr<const ndn::net::NetworkInterface>& netif) |
| 108 | { |
| 109 | BOOST_ASSERT(remote.isCanonical()); |
Davide Pesavento | d27841b | 2018-11-13 00:22:24 -0500 | [diff] [blame] | 110 | return doCreateNetdevBoundFace(remote, netif); |
Junxiao Shi | eef49a9 | 2018-11-10 12:19:36 +0000 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | shared_ptr<Face> |
Davide Pesavento | d27841b | 2018-11-13 00:22:24 -0500 | [diff] [blame] | 114 | ProtocolFactory::doCreateNetdevBoundFace(const FaceUri&, |
| 115 | const shared_ptr<const ndn::net::NetworkInterface>&) |
Junxiao Shi | eef49a9 | 2018-11-10 12:19:36 +0000 | [diff] [blame] | 116 | { |
Davide Pesavento | 19779d8 | 2019-02-14 13:40:04 -0500 | [diff] [blame] | 117 | NDN_THROW(Error("This protocol factory does not support netdev-bound faces")); |
Davide Pesavento | d27841b | 2018-11-13 00:22:24 -0500 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | std::vector<shared_ptr<const Channel>> |
| 121 | ProtocolFactory::getChannels() const |
| 122 | { |
| 123 | return doGetChannels(); |
| 124 | } |
| 125 | |
| 126 | std::vector<shared_ptr<const Channel>> |
| 127 | ProtocolFactory::doGetChannels() const |
| 128 | { |
| 129 | return {}; |
Junxiao Shi | eef49a9 | 2018-11-10 12:19:36 +0000 | [diff] [blame] | 130 | } |
| 131 | |
Junxiao Shi | b47247d | 2017-01-24 15:09:16 +0000 | [diff] [blame] | 132 | } // namespace face |
| 133 | } // namespace nfd |