PageRenderTime 16ms CodeModel.GetById 1ms app.highlight 9ms RepoModel.GetById 2ms app.codeStats 0ms

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

https://github.com/deltaforge/nebu-app-framework-cpp
C Header | 91 lines | 41 code | 15 blank | 35 comment | 0 complexity | b99dcb1943c5e7fe499b0f8e17a507d9 MD5 | raw file
 1
 2/** @file */
 3
 4#ifndef NEBUAPPFRAMEWORK_DAEMON_H_
 5#define NEBUAPPFRAMEWORK_DAEMON_H_
 6
 7#include "nebu/virtualMachine.h"
 8
 9#include <memory>
10#include <time.h>
11
12namespace nebu
13{
14	namespace app
15	{
16		namespace framework
17		{
18
19			/** Represents the type of a Daemon.
20			 *  Values can be assigned by an application, and are not explicitly used by the framework.
21			 */
22			typedef unsigned int DaemonType;
23
24			/**	Represents a daemon managed by the application.
25			 *  Daemons are managed by a DaemonManager and are contained in a DaemonCollection.
26			 */
27			class Daemon
28			{
29			public:
30				/** Creates a new Daemon on the given VirtualMachine.
31				 *  @param hostVM the VirtualMachine hosting the Daemon.
32				 */
33				Daemon(std::shared_ptr<nebu::common::VirtualMachine> hostVM);
34				/** Empty destructor provided for inheritance */
35				virtual ~Daemon() { }
36
37				/** Getter for the VirtualMachine hosting the Daemon, as specified in the constructor.
38				 *  @return the VirtualMachine hosting the Daemon.
39				 */
40				virtual std::shared_ptr<nebu::common::VirtualMachine> getHostVM() const
41				{
42					return this->hostVM;
43				}
44
45				/** Getter for the hostname of the VirtualMachine that hosts the Daemon.
46				 *  @return the hostname of the hosting VirtualMachine.
47				 */
48				virtual std::string getHostname() const
49				{
50					return hostVM->getHostname();
51				}
52
53				/** Launches the Daemon.
54				 *  Must be implemented by subclasses, as launching is specific to the type of Daemon.
55				 *  @return true iff the launch was succesful.
56				 */
57				virtual bool launch() = 0;
58				/** Checks if the Daemon has been launched.
59				 *  @return true iff the Daemon has launched succesfully.
60				 */
61				virtual bool hasLaunched() const
62				{
63					return this->launched;
64				}
65
66				/** Getter for the type of the Daemon.
67				 *  Must be implemented, and should be unique for different types of Daemons.
68				 *  @return the type of the Daemon.
69				 */
70				virtual DaemonType getType() const = 0;
71
72				/** Caclulates the amount of seconds that have passed since the Daemon was discovered.
73				 *  The 'discovery time' of the Daemon is defined as the moment the Daemon object was created.
74				 *  @return amount of seconds elapsed since discovery.
75				 */
76				virtual time_t secondsSinceDiscovery() const;
77
78			protected:
79				/** The discovery time of the Daemon. */
80				time_t discoveryTime;
81				/** True iff the Daemon has been launched succesfully. */
82				bool launched;
83				/** The VirtualMachine hosting the Daemon. */
84				std::shared_ptr<nebu::common::VirtualMachine> hostVM;
85			};
86
87		}
88	}
89}
90
91#endif