PageRenderTime 23ms CodeModel.GetById 14ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

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