rib: fix initialization error in Service
refs #4723
Change-Id: Ibfe313a3e2f1b0e57ee81661aa387397101228f9
diff --git a/rib/service.cpp b/rib/service.cpp
index ddf13ed..067806f 100644
--- a/rib/service.cpp
+++ b/rib/service.cpp
@@ -85,25 +85,24 @@
}
Service::Service(const std::string& configFile, ndn::KeyChain& keyChain)
- : Service(keyChain, makeLocalNfdTransport(loadConfigSectionFromFile(configFile)))
+ : Service(keyChain, makeLocalNfdTransport(loadConfigSectionFromFile(configFile)),
+ [&configFile] (ConfigFile& config, bool isDryRun) {
+ config.parse(configFile, isDryRun);
+ })
{
- ConfigFile config(ConfigFile::ignoreUnknownSection);
- config.addSectionHandler(CFG_SECTION, bind(&Service::processConfig, this, _1, _2, _3));
- config.parse(configFile, true);
- config.parse(configFile, false);
}
Service::Service(const ConfigSection& configSection, ndn::KeyChain& keyChain)
- : Service(keyChain, makeLocalNfdTransport(configSection))
+ : Service(keyChain, makeLocalNfdTransport(configSection),
+ [&configSection] (ConfigFile& config, bool isDryRun) {
+ config.parse(configSection, isDryRun, "internal://nfd.conf");
+ })
{
- ConfigFile config(ConfigFile::ignoreUnknownSection);
- config.addSectionHandler(CFG_SECTION, bind(&Service::processConfig, this, _1, _2, _3));
- const std::string INTERNAL_CONFIG = "internal://nfd.conf";
- config.parse(configSection, true, INTERNAL_CONFIG);
- config.parse(configSection, false, INTERNAL_CONFIG);
}
-Service::Service(ndn::KeyChain& keyChain, shared_ptr<ndn::Transport> localNfdTransport)
+template<typename ConfigParseFunc>
+Service::Service(ndn::KeyChain& keyChain, shared_ptr<ndn::Transport> localNfdTransport,
+ const ConfigParseFunc& configParse)
: m_keyChain(keyChain)
, m_face(std::move(localNfdTransport), getGlobalIoService(), m_keyChain)
, m_nfdController(m_face, m_keyChain)
@@ -118,6 +117,14 @@
BOOST_THROW_EXCEPTION(std::logic_error("RIB service must run on RIB thread"));
}
s_instance = this;
+
+ ConfigFile config(ConfigFile::ignoreUnknownSection);
+ config.addSectionHandler(CFG_SECTION, bind(&Service::processConfig, this, _1, _2, _3));
+ configParse(config, true);
+ configParse(config, false);
+
+ m_ribManager.registerWithNfd();
+ m_ribManager.enableLocalFields();
}
Service::~Service()
@@ -153,9 +160,10 @@
{
for (const auto& item : section) {
const std::string& key = item.first;
+ const ConfigSection& value = item.second;
if (key == CFG_LOCALHOST_SECURITY || key == CFG_LOCALHOP_SECURITY) {
ndn::security::v2::validator_config::ValidationPolicyConfig policy;
- policy.load(section, filename);
+ policy.load(value, filename);
}
else if (key == CFG_PREFIX_PROPAGATE) {
// AutoPrefixPropagator does not support config dry-run
@@ -217,12 +225,5 @@
}
}
-void
-Service::initialize()
-{
- m_ribManager.registerWithNfd();
- m_ribManager.enableLocalFields();
-}
-
} // namespace rib
} // namespace nfd
diff --git a/rib/service.hpp b/rib/service.hpp
index b39f5c6..a349787 100644
--- a/rib/service.hpp
+++ b/rib/service.hpp
@@ -86,7 +86,9 @@
get();
private:
- Service(ndn::KeyChain& keyChain, shared_ptr<ndn::Transport> localNfdTransport);
+ template<typename ConfigParseFunc>
+ Service(ndn::KeyChain& keyChain, shared_ptr<ndn::Transport> localNfdTransport,
+ const ConfigParseFunc& configParse);
void
processConfig(const ConfigSection& section, bool isDryRun, const std::string& filename);
@@ -97,9 +99,6 @@
void
applyConfig(const ConfigSection& section, const std::string& filename);
- void
- initialize();
-
private:
static Service* s_instance;