Kea: config_base.cc Source File

| Kea 1.5.0

config_base.cc
Go to the documentation of this file.
1 // Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7 #include <process/config_base.h>
8 #include <log/logger_manager.h>
9 #include <log/logger_specification.h>
10 #include <list>
11
12 using namespace isc::log;
13 using namespace isc::data;
14
15 namespace isc {
16 namespace process {
17
18 void
19 ConfigBase::applyLoggingCfg() const {
20
21 std::list<LoggerSpecification> specs;
22 for (LoggingInfoStorage::const_iterator it = logging_info_.begin();
23 it != logging_info_.end(); ++it) {
24 specs.push_back(it->toSpec());
25 }
26 LoggerManager manager;
27 manager.process(specs.begin(), specs.end());
28 }
29
30 bool
31 ConfigBase::equals(const ConfigBase& other) const {
32 // If number of loggers is different, then configurations aren't equal.
33 if (logging_info_.size() != other.logging_info_.size()) {
34 return (false);
35 }
36 // Pass through all loggers and try to find the match for each of them
37 // with the loggers from the other configuration. The order doesn't
38 // matter so we can't simply compare the vectors.
39 for (LoggingInfoStorage::const_iterator this_it =
40 logging_info_.begin(); this_it != logging_info_.end();
41 ++this_it) {
42 bool match = false;
43 for (LoggingInfoStorage::const_iterator other_it =
44 other.logging_info_.begin();
45 other_it != other.logging_info_.end(); ++other_it) {
46 if (this_it->equals(*other_it)) {
47 match = true;
48 break;
49 }
50 }
51 // No match found for the particular logger so return false.
52 if (!match) {
53 return (false);
54 }
55 }
56
57 // Check config control info for equality.
58 if ((config_ctl_info_ && !other.config_ctl_info_) ||
59 (!config_ctl_info_ && other.config_ctl_info_) ||
60 ((config_ctl_info_ && other.config_ctl_info_) &&
61 (!config_ctl_info_->equals(*(other.config_ctl_info_))))) {
62 return (false);
63 }
64
65 return (true);
66 }
67
68 void
69 ConfigBase::copy(ConfigBase& other) const {
70 // We will entirely replace loggers in the new configuration.
71 other.logging_info_.clear();
72 for (LoggingInfoStorage::const_iterator it = logging_info_.begin();
73 it != logging_info_.end(); ++it) {
74 other.addLoggingInfo(*it);
75 }
76
77 // Clone the config control info
78 if (config_ctl_info_) {
79 other.config_ctl_info_.reset(new ConfigControlInfo(*config_ctl_info_));
80 } else {
81 other.config_ctl_info_.reset();
82 }
83 }
84
85 ElementPtr
86 ConfigBase::toElement() const {
87 ElementPtr result = Element::createMap();
88
89 // Logging global map (skip if empty)
90 if (!logging_info_.empty()) {
91 ElementPtr logging = Element::createMap();
92 // Set loggers list
93 ElementPtr loggers = Element::createList();
94 for (LoggingInfoStorage::const_iterator logger =
95 logging_info_.cbegin();
96 logger != logging_info_.cend(); ++logger) {
97 loggers->add(logger->toElement());
98 }
99 logging->set("loggers", loggers);
100 result->set("Logging", logging);
101 }
102
103 // We do NOT output ConfigControlInfo here, as it is not a
104 // top level element, but rather belongs within the process
105 // element.
106
107 return (result);
108 }
109
110 };
111 };
isc::process::ConfigBase
Base class for all configurations.
Definition: config_base.h:31
logger_manager.h
isc::data::copy
ElementPtr copy(ConstElementPtr from, int level)
Copy the data up to a nesting level.
Definition: data.cc:1114
isc::log
Definition: buffer_appender_impl.cc:17
isc::data
Definition: cfg_to_element.h:25
isc::process::ConfigControlInfo
Embodies configuration information used during a server's configuration process.
Definition: config_ctl_info.h:138
isc
Defines the logger used by the top-level component of kea-dhcp-ddns.
Definition: agent_parser.cc:144
isc::log::LoggerManager
Logger Manager.
Definition: logger_manager.h:38
logger_specification.h
isc::asiodns::logger
isc::log::Logger logger("asiodns")
Use the ASIO logger.
Definition: asiodns/logger.h:15
isc::process::ConfigBase::addLoggingInfo
void addLoggingInfo(const process::LoggingInfo &logging_info)
Sets logging specific configuration.
Definition: config_base.h:48
isc::log::LoggerManager::process
void process(T start, T finish)
Process Specifications.
Definition: logger_manager.h:55
config_base.h
isc::data::ElementPtr
boost::shared_ptr< Element > ElementPtr
Definition: data.h:20