daemon.cc 2.57 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// Copyright (C) 2014  Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.

#include <config.h>
16
#include <dhcpsrv/cfgmgr.h>
17 18
#include <dhcpsrv/daemon.h>
#include <exceptions/exceptions.h>
19
#include <cc/data.h>
20
#include <boost/bind.hpp>
21
#include <logging.h>
22 23
#include <log/logger_name.h>
#include <log/logger_support.h>
24 25 26
#include <errno.h>

/// @brief provides default implementation for basic daemon operations
27
///
28 29 30 31 32
/// This file provides stub implementations that are expected to be redefined
/// in derived classes (e.g. ControlledDhcpv6Srv)
namespace isc {
namespace dhcp {

33 34 35
// This is an initial config file location.
std::string Daemon::config_file_ = "";

36
Daemon::Daemon()
37
    : signal_set_(), signal_handler_() {
38 39 40
}

Daemon::~Daemon() {
41 42
}

43 44
void Daemon::init(const std::string& config_file) {
    config_file_ = config_file;
45 46 47 48 49 50 51 52 53 54
}

void Daemon::cleanup() {

}

void Daemon::shutdown() {

}

55 56 57 58
void Daemon::handleSignal() {
    if (signal_set_ && signal_handler_) {
        signal_set_->handleNext(boost::bind(signal_handler_, _1));
    }
59 60
}

Tomek Mrugalski's avatar
Tomek Mrugalski committed
61
void Daemon::configureLogger(const isc::data::ConstElementPtr& log_config,
62
                             const SrvConfigPtr& storage) {
63 64 65 66 67 68 69

    if (log_config) {
        isc::data::ConstElementPtr loggers = log_config->get("loggers");
        if (loggers) {
            LogConfigParser parser(storage);
            parser.parseConfiguration(loggers, CfgMgr::instance().isVerbose());
        }
70
    }
71
}
72

73 74 75 76
void
Daemon::setVerbose(bool verbose) {
    CfgMgr::instance().setVerbose(verbose);
}
77

78 79 80
bool
Daemon::getVerbose() const {
    return (CfgMgr::instance().isVerbose());
81
}
82

83
void Daemon::loggerInit(const char* name, bool verbose) {
84 85

    // Initialize logger system
86
    isc::log::initLogger(name, isc::log::DEBUG, isc::log::MAX_DEBUG_LEVEL,
87 88 89
                         NULL);

    // Apply default configuration (log INFO or DEBUG to stdout)
90
    isc::log::setDefaultLoggingOutput(verbose);
91 92
}

93 94
};
};