/include/nebu-app-framework/applicationHooks.h

https://github.com/deltaforge/nebu-app-framework-cpp · C Header · 125 lines · 55 code · 15 blank · 55 comment · 0 complexity · 769c30f22129721e39341e9b3b452109 MD5 · raw file

  1. #ifndef NEBUAPPFRAMEWORK_APPLICATIONHOOKS_H_
  2. #define NEBUAPPFRAMEWORK_APPLICATIONHOOKS_H_
  3. #include <memory>
  4. #include <string>
  5. #include <vector>
  6. namespace nebu
  7. {
  8. namespace app
  9. {
  10. namespace framework
  11. {
  12. class Application;
  13. class DaemonCollection;
  14. class DaemonManager;
  15. class TopologyManager;
  16. class VMManager;
  17. /** Interface of all hooks provided to an application built on libnebu-app-framework.
  18. * The ApplicationHooks interface should be implemented by a single class in an application.
  19. * It is used for all customisation of the framework for a specific application.
  20. * Several getters allow for dependency injection of key classes into the Application class.
  21. * All actions in the main loop are directly preceded/followed by a pre/post hook, respectively,
  22. * allowing for further customisation of the application.
  23. */
  24. class ApplicationHooks
  25. {
  26. public:
  27. /** Empty constructor provided for inheritance. */
  28. ApplicationHooks() : application() { }
  29. /** Empty destructor provided for inheritance. */
  30. virtual ~ApplicationHooks() { }
  31. /** Hook provided for registering configuration options.
  32. * This hook is called before command line parsing.
  33. */
  34. virtual void registerConfigurationOptions() { }
  35. /** Hook provided for initialising the logging framework.
  36. * The provided implementation defaults to writing to standard output at a DEBUG level.
  37. * This hook is called after the command line arguments have been parsed, but before the
  38. * application has initialised.
  39. */
  40. virtual void prepareLogging();
  41. /** Hook provided for initialising the application using command line arguments.
  42. * This hook is called after the command line has been parsed for known configuration options,
  43. * and after the logging framework has been configured.
  44. * @param[in] command the value of <code>argv[0]</code> as passed to <code>main</code>.
  45. * @param[in] arguments command line arguments passed to the application, excluding any
  46. * arguments that have been parsed by the Configuration class.
  47. */
  48. virtual void initialise(std::string command __attribute__((unused)),
  49. std::vector<std::string> &arguments __attribute__((unused))) { }
  50. /** Hook called at the start of the main loop, before any other action takes place. */
  51. virtual void preLoop() { }
  52. /** Hook called before the VMManager's list of VMs is refreshed */
  53. virtual void preRefreshVMs() { }
  54. /** Hook called after the VMManager's list of VMs has been refreshed */
  55. virtual void postRefreshVMs() { }
  56. /** Hook called before the TopologyManager's topology representation is refreshed */
  57. virtual void preRefreshTopology() { }
  58. /** Hook called after the TopologyManager's topology representation has been refreshed */
  59. virtual void postRefreshTopology() { }
  60. /** Hook called before the DaemonManager refreshes its information on Daemons */
  61. virtual void preRefreshDaemons() { }
  62. /** Hook called after the DaemonManager has refreshed its information on Daemons */
  63. virtual void postRefreshDaemons() { }
  64. /** Hook called before the DaemonManager deploys Daemmons */
  65. virtual void preDeployDaemons() { }
  66. /** Hook called after the DaemonManager deploys Daemons */
  67. virtual void postDeployDaemons() { }
  68. /** Hook called at the end of the main loop, before the application sleeps for a configured interval. */
  69. virtual void postLoop() { }
  70. /** Getter for a concrete DaemonManager object, should be singleton.
  71. * @return a DaemonManager object.
  72. */
  73. virtual std::shared_ptr<DaemonManager> getDaemonManager() = 0;
  74. /** Getter for a DaemonCollection object, should be singleton.
  75. * The provided implementation returns a singleton of the DaemonCollection class.
  76. * @return a DaemonCollection object.
  77. */
  78. virtual std::shared_ptr<DaemonCollection> getDaemonCollection();
  79. /** Getter for a TopologyManager object, should be singleton.
  80. * The provided implementation returns a singleton of the TopologyManager class.
  81. * @return a TopologyManager object.
  82. */
  83. virtual std::shared_ptr<TopologyManager> getTopologyManager();
  84. /** Getter for a VMManager object, should be singleton.
  85. * The provided implementation returns a singleton of the VMManager class.
  86. * @return a VMManager object.
  87. */
  88. virtual std::shared_ptr<VMManager> getVMManager();
  89. /** Setter for the Application singleton, for use by the implementing Nebu application. */
  90. virtual void setApplication(std::shared_ptr<Application> application)
  91. {
  92. this->application = application;
  93. }
  94. protected:
  95. /** The Application singleton */
  96. std::shared_ptr<Application> application;
  97. private:
  98. std::shared_ptr<DaemonCollection> daemonCollection;
  99. std::shared_ptr<TopologyManager> topologyManager;
  100. std::shared_ptr<VMManager> vmManager;
  101. };
  102. /** Initialization function to create application-specific hooks and singletons.
  103. * This function must be provided by the application using libnebu-app-framework.
  104. * @return an object implementing the application-specific hooks.
  105. */
  106. std::shared_ptr<ApplicationHooks> initApplication();
  107. }
  108. }
  109. }
  110. #endif