Kea  2.1.7-git
config_base.cc
Go to the documentation of this file.
1 // Copyright (C) 2018-2020 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 <config.h>
8 
9 #include <process/config_base.h>
10 #include <log/logger_manager.h>
12 #include <list>
13 
14 using namespace isc::log;
15 using namespace isc::data;
16 
17 namespace isc {
18 namespace process {
19 
20 void
21 ConfigBase::applyLoggingCfg() const {
22 
23  std::list<LoggerSpecification> specs;
24  for (LoggingInfoStorage::const_iterator it = logging_info_.begin();
25  it != logging_info_.end(); ++it) {
26  specs.push_back(it->toSpec());
27  }
28  LoggerManager manager;
29  manager.process(specs.begin(), specs.end());
30 }
31 
32 bool
33 ConfigBase::equals(const ConfigBase& other) const {
34  // If number of loggers is different, then configurations aren't equal.
35  if (logging_info_.size() != other.logging_info_.size()) {
36  return (false);
37  }
38  // Pass through all loggers and try to find the match for each of them
39  // with the loggers from the other configuration. The order doesn't
40  // matter so we can't simply compare the vectors.
41  for (LoggingInfoStorage::const_iterator this_it =
42  logging_info_.begin(); this_it != logging_info_.end();
43  ++this_it) {
44  bool match = false;
45  for (LoggingInfoStorage::const_iterator other_it =
46  other.logging_info_.begin();
47  other_it != other.logging_info_.end(); ++other_it) {
48  if (this_it->equals(*other_it)) {
49  match = true;
50  break;
51  }
52  }
53  // No match found for the particular logger so return false.
54  if (!match) {
55  return (false);
56  }
57  }
58 
59  // Check config control info for equality.
60  if ((config_ctl_info_ && !other.config_ctl_info_) ||
61  (!config_ctl_info_ && other.config_ctl_info_) ||
62  ((config_ctl_info_ && other.config_ctl_info_) &&
63  (!config_ctl_info_->equals(*(other.config_ctl_info_))))) {
64  return (false);
65  }
66 
67  return (true);
68 }
69 
70 void
72  // We will entirely replace loggers in the new configuration.
73  other.logging_info_.clear();
74  for (LoggingInfoStorage::const_iterator it = logging_info_.begin();
75  it != logging_info_.end(); ++it) {
76  other.addLoggingInfo(*it);
77  }
78 
79  // Clone the config control info
80  if (config_ctl_info_) {
81  other.config_ctl_info_.reset(new ConfigControlInfo(*config_ctl_info_));
82  } else {
83  other.config_ctl_info_.reset();
84  }
85 
86  // Clone server tag.
87  other.server_tag_ = server_tag_;
88 }
89 
90 void
92  // Merge logging info.
93  if (!other.logging_info_.empty()) {
94  logging_info_ = other.logging_info_;
95  }
96 
97  // Merge the config control info
98  if (other.config_ctl_info_) {
99  if (config_ctl_info_) {
100  config_ctl_info_->merge(*other.config_ctl_info_);
101  } else {
102  config_ctl_info_ = other.config_ctl_info_;
103  }
104  }
105 
106  // Merge server tag.
107  if (!other.server_tag_.unspecified()) {
108  server_tag_ = other.server_tag_.get();
109  }
110 }
111 
113 ConfigBase::toElement() const {
114  ElementPtr result = Element::createMap();
115 
116  // Was in the Logging global map.
117  if (!logging_info_.empty()) {
118  // Set loggers list
119  ElementPtr loggers = Element::createList();
120  for (LoggingInfoStorage::const_iterator logger =
121  logging_info_.cbegin();
122  logger != logging_info_.cend(); ++logger) {
123  loggers->add(logger->toElement());
124  }
125  result->set("loggers", loggers);
126  }
127 
128  // server-tag
129  if (!server_tag_.unspecified()) {
130  result->set("server-tag", Element::create(server_tag_.get()));
131  }
132 
133  return (result);
134 }
135 
136 };
137 };
void unspecified(bool unspecified)
Modifies the flag that indicates whether the value is specified or unspecified.
Definition: optional.h:136
void addLoggingInfo(const process::LoggingInfo &logging_info)
Sets logging specific configuration.
Definition: config_base.h:50
void process(T start, T finish)
Process Specifications.
Base class for all configurations.
Definition: config_base.h:33
Logger Manager.
T get() const
Retrieves the encapsulated value.
Definition: optional.h:114
Embodies configuration information used during a server&#39;s configuration process.
boost::shared_ptr< Element > ElementPtr
Definition: data.h:24
ElementPtr copy(ConstElementPtr from, int level)
Copy the data up to a nesting level.
Definition: data.cc:1152
Defines the logger used by the top-level component of kea-lfc.
isc::log::Logger logger("asiodns")
Use the ASIO logger.
void merge(ElementPtr element, ConstElementPtr other)
Merges the data from other into element.
Definition: data.cc:1134