helper: Adds a new helper to create applications

This helper is primarily motivated to simplify creating applications for
unit tests, but can be used more in general simulation scenarios as
well.

Change-Id: I02db0c882a5b17e847bef0f10b7b69eb00d1fa45
diff --git a/helper/ndn-app-helper.cpp b/helper/ndn-app-helper.cpp
index 2efdee4..2556659 100644
--- a/helper/ndn-app-helper.cpp
+++ b/helper/ndn-app-helper.cpp
@@ -97,5 +97,35 @@
   return app;
 }
 
+////////////////////////////////////////////////////////////////////////////
+
+FactoryCallbackApp::FactoryCallbackApp(const FactoryCallback& factory)
+  : m_factory(factory)
+{
+}
+
+ApplicationContainer
+FactoryCallbackApp::Install(Ptr<Node> node, const FactoryCallback& factory)
+{
+  ApplicationContainer apps;
+  auto app = CreateObject<FactoryCallbackApp>(factory);
+  node->AddApplication(app);
+  apps.Add(app);
+  return apps;
+}
+
+void
+FactoryCallbackApp::StartApplication()
+{
+  m_impl = m_factory();
+}
+
+void
+FactoryCallbackApp::StopApplication()
+{
+  m_impl.reset();
+}
+
+
 } // namespace ndn
 } // namespace ns3
diff --git a/helper/ndn-app-helper.hpp b/helper/ndn-app-helper.hpp
index 88051d4..f50d643 100644
--- a/helper/ndn-app-helper.hpp
+++ b/helper/ndn-app-helper.hpp
@@ -105,6 +105,47 @@
   ObjectFactory m_factory;
 };
 
+/**
+ * @brief An application that can be created using the supplied callback
+ *
+ * Example:
+ *
+ *     class SomeApp
+ *     {
+ *     public:
+ *       SomeApp(size_t initParameter);
+ *       ...
+ *     };
+ *
+ *     FactoryCallbackApp::Install(node, [] () -> shared_ptr<void> {
+ *         return make_shared<SomeApp>(42);
+ *       })
+ *       .Start(Seconds(1.01));
+ */
+class FactoryCallbackApp : public Application
+{
+public:
+  typedef std::function<shared_ptr<void>()> FactoryCallback;
+
+  FactoryCallbackApp(const FactoryCallback& factory);
+
+public:
+  static ApplicationContainer
+  Install(Ptr<Node> node, const FactoryCallback& factory);
+
+protected:
+  // inherited from Application base class.
+  virtual void
+  StartApplication();
+
+  virtual void
+  StopApplication();
+
+private:
+  FactoryCallback m_factory;
+  std::shared_ptr<void> m_impl;
+};
+
 } // namespace ndn
 } // namespace ns3
 
diff --git a/helper/ndn-fib-helper.cpp b/helper/ndn-fib-helper.cpp
index 19536bf..95c0309 100644
--- a/helper/ndn-fib-helper.cpp
+++ b/helper/ndn-fib-helper.cpp
@@ -81,7 +81,6 @@
 
   Ptr<L3Protocol> L3protocol = node->GetObject<L3Protocol>();
   shared_ptr<nfd::FibManager> fibManager = L3protocol->getFibManager();
-  // fibManager->addInterestRule(commandName.toUri(), key, *keyChain.getPublicKey (key));
   fibManager->onFibRequest(*command);
 }