protocol-factory.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2019, Regents of the University of California,
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"
27 
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>
42 ProtocolFactory::create(const std::string& id, const CtorParams& params)
43 {
44  Registry& registry = getRegistry();
45  auto found = registry.find(id);
46  if (found == registry.end()) {
47  return nullptr;
48  }
49 
50  return found->second(params);
51 }
52 
53 std::set<std::string>
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 
63  : addFace(params.addFace)
64  , netmon(params.netmon)
65 {
66  BOOST_ASSERT(addFace != nullptr);
67  BOOST_ASSERT(netmon != nullptr);
68 }
69 
71 
72 void
75 {
76  doProcessConfig(configSection, context);
77 }
78 
79 void
80 ProtocolFactory::doProcessConfig(OptionalConfigSection,
82 {
83 }
84 
85 void
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 
105 shared_ptr<Face>
107  const shared_ptr<const ndn::net::NetworkInterface>& netif)
108 {
109  BOOST_ASSERT(remote.isCanonical());
110  return doCreateNetdevBoundFace(remote, netif);
111 }
112 
113 shared_ptr<Face>
114 ProtocolFactory::doCreateNetdevBoundFace(const FaceUri&,
115  const shared_ptr<const ndn::net::NetworkInterface>&)
116 {
117  NDN_THROW(Error("This protocol factory does not support netdev-bound faces"));
118 }
119 
120 std::vector<shared_ptr<const Channel>>
122 {
123  return doGetChannels();
124 }
125 
126 std::vector<shared_ptr<const Channel>>
127 ProtocolFactory::doGetChannels() const
128 {
129  return {};
130 }
131 
132 } // namespace face
133 } // namespace nfd
FaceCreatedCallback addFace
callback when a new face is created
static std::set< std::string > listRegistered()
Get all registered protocol factory ids.
std::vector< shared_ptr< const Channel > > getChannels() const
Get list of open channels (listening + non-listening)
void processConfig(OptionalConfigSection configSection, FaceSystem::ConfigContext &context)
Process face_system subsection that corresponds to this protocol factory id.
ProtocolFactory(const CtorParams &params)
std::function< void(uint32_t status, const std::string &reason)> FaceCreationFailedCallback
Prototype for the callback that is invoked when a face fails to be created.
Definition: channel.hpp:78
shared_ptr< ndn::net::NetworkMonitor > netmon
NetworkMonitor for listing available network interfaces and monitoring their changes.
boost::optional< const ConfigSection & > OptionalConfigSection
an optional config file section
Definition: config-file.hpp:41
context for processing a config section in ProtocolFactory
Definition: face-system.hpp:96
void createFace(const CreateFaceRequest &req, const FaceCreatedCallback &onCreated, const FaceCreationFailedCallback &onFailure)
Create a unicast face.
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: algorithm.hpp:32
shared_ptr< Face > createNetdevBoundFace(const FaceUri &remote, const shared_ptr< const ndn::net::NetworkInterface > &netdev)
Create a netdev-bound face.
Parameters to ProtocolFactory constructor.
std::function< void(const shared_ptr< Face > &)> FaceCreatedCallback
Prototype for the callback that is invoked when a face is created (in response to an incoming connect...
Definition: channel.hpp:74
Base class for all exceptions thrown by ProtocolFactory subclasses.
static unique_ptr< ProtocolFactory > create(const std::string &id, const CtorParams &params)
Create a protocol factory instance.
Encapsulates a face creation request and all its parameters.