41 : m_faceTable(faceTable)
42 , m_netmon(std::move(netmon))
44 auto pfCtorParams = this->makePFCtorParams();
50 m_netdevBound = make_unique<NetdevBound>(pfCtorParams, *
this);
54 FaceSystem::makePFCtorParams()
56 auto addFace = [&ft = m_faceTable] (
auto face) { ft.add(std::move(face)); };
57 return {addFace, m_netmon};
62 std::set<const ProtocolFactory*>
65 std::set<const ProtocolFactory*> factories;
66 for (
const auto& p : m_factories) {
67 factories.insert(p.second.get());
75 auto found = m_factories.find(
id);
76 return found == m_factories.end() ? nullptr : found->second.get();
82 auto found = m_factoryByScheme.find(scheme);
83 return found == m_factoryByScheme.end() ? nullptr : found->second;
89 return m_factoryByScheme.count(scheme) > 0;
95 configFile.
addSectionHandler(
"face_system", bind(&FaceSystem::processConfig,
this, _1, _2, _3));
99 FaceSystem::processConfig(
const ConfigSection& configSection,
bool isDryRun,
const std::string& filename)
101 ConfigContext context;
102 context.isDryRun = isDryRun;
105 auto generalSection = configSection.get_child_optional(
SECTION_GENERAL);
106 if (generalSection) {
107 for (
const auto& pair : *generalSection) {
108 const std::string& key = pair.first;
109 if (key ==
"enable_congestion_marking") {
113 BOOST_THROW_EXCEPTION(
ConfigFile::Error(
"Unrecognized option face_system.general." + key));
119 for (
const auto& pair : m_factories) {
120 const std::string& sectionName = pair.first;
121 ProtocolFactory* factory = pair.second.get();
123 std::set<std::string> oldProvidedSchemes = factory->getProvidedSchemes();
124 factory->processConfig(configSection.get_child_optional(sectionName), context);
127 for (
const std::string& scheme : factory->getProvidedSchemes()) {
128 m_factoryByScheme[scheme] = factory;
129 if (oldProvidedSchemes.erase(scheme) == 0) {
131 " provides " << scheme <<
" FaceUri scheme");
134 for (
const std::string& scheme : oldProvidedSchemes) {
135 m_factoryByScheme.erase(scheme);
137 " no longer provides " << scheme <<
" FaceUri scheme");
144 m_netdevBound->processConfig(netdevBoundSection, context);
147 std::set<std::string> seenSections;
148 for (
const auto& pair : configSection) {
149 const std::string& sectionName = pair.first;
152 if (!seenSections.insert(sectionName).second) {
153 BOOST_THROW_EXCEPTION(ConfigFile::Error(
"Duplicate section face_system." + sectionName));
157 m_factories.count(sectionName) > 0) {
161 BOOST_THROW_EXCEPTION(ConfigFile::Error(
"Unrecognized option face_system." + sectionName));
static std::set< std::string > listRegistered()
Get all registered protocol factory ids.
static bool parseYesNo(const ConfigSection &node, const std::string &key, const std::string §ionName)
parse a config option that can be either "yes" or "no"
ProtocolFactory * getFactoryById(const std::string &id)
configuration file parsing utility
ProtocolFactory * getFactoryByScheme(const std::string &scheme)
entry point of the face system
std::set< const ProtocolFactory * > listProtocolFactories() const
FaceSystem(FaceTable &faceTable, shared_ptr< ndn::net::NetworkMonitor > netmon)
Provides support for an underlying protocol.
Copyright (c) 2011-2015 Regents of the University of California.
void addSectionHandler(const std::string §ionName, ConfigSectionHandler subscriber)
setup notification of configuration file sections
void setConfigFile(ConfigFile &configFile)
register handler for face_system section of NFD configuration file
Parameters to ProtocolFactory constructor.
boost::property_tree::ptree ConfigSection
a config file section
bool hasFactoryForScheme(const std::string &scheme) const
static unique_ptr< ProtocolFactory > create(const std::string &id, const CtorParams ¶ms)
Create a protocol factory instance.
static const std::string SECTION_GENERAL
static const std::string SECTION_NETDEVBOUND
#define NFD_LOG_INIT(name)