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.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