tools: nfdc creates Face and KeyChain in main function
refs #3749
Change-Id: I169ad766634371b0192ebae640355298b78aaaa4
diff --git a/tools/nfdc/legacy-nfdc.cpp b/tools/nfdc/legacy-nfdc.cpp
index 5b7ff45..f5c4fa7 100644
--- a/tools/nfdc/legacy-nfdc.cpp
+++ b/tools/nfdc/legacy-nfdc.cpp
@@ -38,14 +38,14 @@
const time::milliseconds LegacyNfdc::DEFAULT_EXPIRATION_PERIOD = time::milliseconds::max();
const uint64_t LegacyNfdc::DEFAULT_COST = 0;
-LegacyNfdc::LegacyNfdc(ndn::Face& face)
+LegacyNfdc::LegacyNfdc(Face& face, KeyChain& keyChain)
: m_flags(ndn::nfd::ROUTE_FLAG_CHILD_INHERIT)
, m_cost(DEFAULT_COST)
, m_origin(ndn::nfd::ROUTE_ORIGIN_STATIC)
, m_expires(DEFAULT_EXPIRATION_PERIOD)
, m_facePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT)
, m_face(face)
- , m_controller(face, m_keyChain)
+ , m_controller(face, keyChain)
{
}
@@ -326,11 +326,12 @@
}
int
-legacyNfdcMain(const std::string& subcommand, const std::vector<std::string>& args)
+legacyNfdcMain(ExecuteContext& ctx)
{
- ndn::Face face;
- LegacyNfdc p(face);
+ LegacyNfdc p(ctx.face, ctx.keyChain);
+ const std::string& subcommand = ctx.noun;
+ auto args = ctx.args.get<std::vector<std::string>>("args");
bool wantUnsetChildInherit = false;
bool wantCapture = false;
bool wantPermanentFace = false;
@@ -381,18 +382,12 @@
}
p.m_commandLineArguments = unparsed;
- try {
- bool isOk = p.dispatch(subcommand);
- if (!isOk) {
- legacyNfdcUsage();
- return 1;
- }
- face.processEvents();
+ bool isOk = p.dispatch(subcommand);
+ if (!isOk) {
+ legacyNfdcUsage();
+ return 1;
}
- catch (const std::exception& e) {
- std::cerr << "ERROR: " << e.what() << std::endl;
- return 2;
- }
+ ctx.face.processEvents();
return 0;
}