daemon.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #include <config.h>
  15. #include <string>
  16. #include <boost/noncopyable.hpp>
  17. namespace isc {
  18. namespace dhcp {
  19. /// @brief Base class for all services
  20. ///
  21. /// This is the base class that all daemons (DHCPv4, DHCPv6, D2 and possibly
  22. /// others) are derived from. It provides a standard interface for starting up,
  23. /// reconfiguring, shutting down and several other operations. It also covers
  24. /// some common operations.
  25. ///
  26. /// This class is not expected to be instantiated directly, but rather daemon
  27. /// implementations should derive from it.
  28. ///
  29. /// Methods are not pure virtual, as we need to instantiate basic daemons (e.g.
  30. /// Dhcpv6Srv) in tests, without going through the hassles of implemeting stub
  31. /// methods.
  32. ///
  33. /// @note Only one instance of this class is instantiated as it encompasses
  34. /// the whole operation of the server. Nothing, however, enforces the
  35. /// singleton status of the object.
  36. class Daemon : public boost::noncopyable {
  37. public:
  38. /// @brief Default constructor
  39. ///
  40. /// Currently it does nothing.
  41. Daemon();
  42. /// @brief Initializes the server.
  43. ///
  44. /// Depending on the configuration backend, it establishes msgq session,
  45. /// or reads the
  46. /// Creates session that will be used to receive commands and updated
  47. /// configuration from cfgmgr (or indirectly from user via bindctl).
  48. ///
  49. /// Note: This function may throw to report enountered problems. It may
  50. /// also return false if the initialization was skipped. That may seem
  51. /// redundant, but the idea here is that in some cases the configuration
  52. /// was read, understood and the decision was made to not start. One
  53. /// case where such capability could be needed is when we have a single
  54. /// config file for Kea4 and D2, but the DNS Update is disabled. It is
  55. /// likely that the D2 will be started, it will analyze its config file,
  56. /// decide that it is not needed and will shut down.
  57. ///
  58. /// @note this method may throw
  59. virtual void init(const std::string& config_file);
  60. /// @brief Performs final deconfiguration.
  61. ///
  62. /// Performs configuration backend specific final clean-up. This is called
  63. /// shortly before the daemon terminates. Depending on backend, it may
  64. /// terminat existing msgq session, close LDAP connection or similar.
  65. ///
  66. /// The daemon is not expected to receive any further commands or
  67. /// configuration updates as it is in final stages of shutdown.
  68. virtual void cleanup();
  69. /// @brief Initiates shutdown procedure for the whole DHCPv6 server.
  70. virtual void shutdown();
  71. /// @brief Desctructor
  72. ///
  73. /// Having virtual destructor ensures that all derived classes will have
  74. /// virtual destructor as well.
  75. virtual ~Daemon();
  76. /// Initializez logger
  77. ///
  78. /// This method initializes logger. I
  79. static void loggerInit(const char* log_name, bool verbose, bool stand_alone);
  80. };
  81. }; // end of isc::dhcp namespace
  82. }; // end of isc namespace