28 #include <boost/range/adaptor/map.hpp>
29 #include <boost/range/algorithm/copy.hpp>
33 ProtocolFactory::Registry&
34 ProtocolFactory::getRegistry()
36 static Registry registry;
40 unique_ptr<ProtocolFactory>
43 Registry& registry = getRegistry();
44 auto found = registry.find(
id);
45 if (found == registry.end()) {
49 return found->second(params);
55 std::set<std::string> factoryIds;
56 boost::copy(getRegistry() | boost::adaptors::map_keys,
57 std::inserter(factoryIds, factoryIds.end()));
62 : addFace(params.addFace)
63 , netmon(params.netmon)
65 BOOST_ASSERT(
addFace !=
nullptr);
66 BOOST_ASSERT(
netmon !=
nullptr);
75 doProcessConfig(configSection, context);
89 BOOST_ASSERT(!FaceUri::canCanonize(req.
remoteUri.getScheme()) ||
91 BOOST_ASSERT(!req.
localUri || !FaceUri::canCanonize(req.
localUri->getScheme()) ||
93 doCreateFace(req, onCreated, onFailure);
97 ProtocolFactory::doCreateFace(
const CreateFaceRequest&,
101 onFailure(406,
"Unsupported protocol");
106 const shared_ptr<const ndn::net::NetworkInterface>& netif)
108 BOOST_ASSERT(remote.isCanonical());
109 return doCreateNetdevBoundFace(remote, netif);
113 ProtocolFactory::doCreateNetdevBoundFace(
const FaceUri&,
114 const shared_ptr<const ndn::net::NetworkInterface>&)
116 NDN_THROW(
Error(
"This protocol factory does not support netdev-bound faces"));
119 std::vector<shared_ptr<const Channel>>
122 return doGetChannels();
125 std::vector<shared_ptr<const Channel>>
126 ProtocolFactory::doGetChannels()
const
Context for processing a config section in ProtocolFactory.
Base class for all exceptions thrown by ProtocolFactory subclasses.
shared_ptr< Face > createNetdevBoundFace(const FaceUri &remote, const shared_ptr< const ndn::net::NetworkInterface > &netdev)
Create a netdev-bound face.
ProtocolFactory(const CtorParams ¶ms)
void createFace(const CreateFaceRequest &req, const FaceCreatedCallback &onCreated, const FaceCreationFailedCallback &onFailure)
Create a unicast face.
void processConfig(OptionalConfigSection configSection, FaceSystem::ConfigContext &context)
Process face_system subsection that corresponds to this protocol factory id.
FaceCreatedCallback addFace
callback when a new face is created
static std::set< std::string > listRegistered()
Get all registered protocol factory IDs.
shared_ptr< ndn::net::NetworkMonitor > netmon
NetworkMonitor for listing available network interfaces and monitoring their changes.
std::vector< shared_ptr< const Channel > > getChannels() const
Get list of open channels (listening + non-listening)
virtual ~ProtocolFactory()=0
static unique_ptr< ProtocolFactory > create(const std::string &id, const CtorParams ¶ms)
Create a protocol factory instance.
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.
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...
boost::optional< const ConfigSection & > OptionalConfigSection
An optional configuration file section.
Encapsulates a face creation request and all its parameters.
std::optional< FaceUri > localUri
Parameters to ProtocolFactory constructor.