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