daemon.cc 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 <dhcpsrv/daemon.h>
  16. #include <exceptions/exceptions.h>
  17. #include <cc/data.h>
  18. #include <boost/bind.hpp>
  19. #include <logging.h>
  20. #include <errno.h>
  21. /// @brief provides default implementation for basic daemon operations
  22. ///
  23. /// This file provides stub implementations that are expected to be redefined
  24. /// in derived classes (e.g. ControlledDhcpv6Srv)
  25. namespace isc {
  26. namespace dhcp {
  27. // This is an initial config file location.
  28. std::string Daemon::config_file_ = "";
  29. Daemon::Daemon()
  30. : signal_set_(), signal_handler_(), verbose_(false) {
  31. }
  32. Daemon::~Daemon() {
  33. }
  34. void Daemon::init(const std::string& config_file) {
  35. config_file_ = config_file;
  36. }
  37. void Daemon::cleanup() {
  38. }
  39. void Daemon::shutdown() {
  40. }
  41. void Daemon::handleSignal() {
  42. if (signal_set_ && signal_handler_) {
  43. signal_set_->handleNext(boost::bind(signal_handler_, _1));
  44. }
  45. }
  46. void Daemon::configureLogger(const isc::data::ConstElementPtr& log_config,
  47. const ConfigurationPtr& storage,
  48. bool verbose) {
  49. // This is utility class that translates JSON structures into formats
  50. // understandable by log4cplus.
  51. LogConfigParser parser(storage);
  52. if (!log_config) {
  53. // There was no logger configuration. Let's clear any config
  54. // and revert to the default.
  55. parser.applyDefaultConfiguration(verbose); // Set up default logging
  56. return;
  57. }
  58. isc::data::ConstElementPtr loggers;
  59. loggers = log_config->get("loggers");
  60. if (!loggers) {
  61. // There is Logging structure, but it doesn't have loggers
  62. // array in it. Let's clear any old logging configuration
  63. // we may have and revert to the default.
  64. parser.applyDefaultConfiguration(verbose); // Set up default logging
  65. return;
  66. }
  67. // Translate JSON structures into log4cplus formats
  68. parser.parseConfiguration(loggers, verbose);
  69. // Apply the configuration
  70. /// @todo: Once configuration unrolling is implemented,
  71. /// this call will be moved to a separate method.
  72. parser.applyConfiguration();
  73. }
  74. };
  75. };