summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomek Mrugalski <tomasz@isc.org>2018-08-31 21:06:21 +0200
committerTomek Mrugalski <tomasz@isc.org>2018-09-07 16:40:06 +0200
commit327aa101fce66c0b5999afbbfc125d8ccb8490be (patch)
tree4310ba0c5713df69e1ba99ab04bcc97c12c71bfa
parent[#25,!14] Logging related files moved to process (diff)
downloadkea-327aa101fce66c0b5999afbbfc125d8ccb8490be.tar.xz
kea-327aa101fce66c0b5999afbbfc125d8ccb8490be.zip
[#25,!14] ConfigBase class added.
-rw-r--r--src/lib/process/Makefile.am5
-rw-r--r--src/lib/process/config_base.cc86
-rw-r--r--src/lib/process/config_base.h88
3 files changed, 178 insertions, 1 deletions
diff --git a/src/lib/process/Makefile.am b/src/lib/process/Makefile.am
index b65b05c962..5842c37356 100644
--- a/src/lib/process/Makefile.am
+++ b/src/lib/process/Makefile.am
@@ -38,12 +38,15 @@ CLEANFILES = *.gcno *.gcda process_messages.h process_messages.cc s-messages
DISTCLEANFILES = spec_config.h.pre
lib_LTLIBRARIES = libkea-process.la
-libkea_process_la_SOURCES = d_cfg_mgr.cc d_cfg_mgr.h
+libkea_process_la_SOURCES = config_base.cc config_base.h
+libkea_process_la_SOURCES += d_cfg_mgr.cc d_cfg_mgr.h
libkea_process_la_SOURCES += d_controller.cc d_controller.h
libkea_process_la_SOURCES += d_log.cc d_log.h
libkea_process_la_SOURCES += d_process.h
libkea_process_la_SOURCES += daemon.cc daemon.h
libkea_process_la_SOURCES += io_service_signal.cc io_service_signal.h
+libkea_process_la_SOURCES += log_parser.cc log_parser.h
+libkea_process_la_SOURCES += logging_info.cc logging_info.h
nodist_libkea_process_la_SOURCES = process_messages.cc process_messages.h
diff --git a/src/lib/process/config_base.cc b/src/lib/process/config_base.cc
new file mode 100644
index 0000000000..e032155a2b
--- /dev/null
+++ b/src/lib/process/config_base.cc
@@ -0,0 +1,86 @@
+#include <process/config_base.h>
+#include <log/logger_manager.h>
+#include <log/logger_specification.h>
+#include <list>
+
+using namespace isc::log;
+using namespace isc::data;
+
+namespace isc {
+namespace process {
+
+void
+ConfigBase::applyLoggingCfg() const {
+
+ std::list<LoggerSpecification> specs;
+ for (LoggingInfoStorage::const_iterator it = logging_info_.begin();
+ it != logging_info_.end(); ++it) {
+ specs.push_back(it->toSpec());
+ }
+ LoggerManager manager;
+ manager.process(specs.begin(), specs.end());
+}
+
+bool
+ConfigBase::equals(const ConfigBase& other) const {
+ // If number of loggers is different, then configurations aren't equal.
+ if (logging_info_.size() != other.logging_info_.size()) {
+ return (false);
+ }
+ // Pass through all loggers and try to find the match for each of them
+ // with the loggers from the other configuration. The order doesn't
+ // matter so we can't simply compare the vectors.
+ for (LoggingInfoStorage::const_iterator this_it =
+ logging_info_.begin(); this_it != logging_info_.end();
+ ++this_it) {
+ bool match = false;
+ for (LoggingInfoStorage::const_iterator other_it =
+ other.logging_info_.begin();
+ other_it != other.logging_info_.end(); ++other_it) {
+ if (this_it->equals(*other_it)) {
+ match = true;
+ break;
+ }
+ }
+ // No match found for the particular logger so return false.
+ if (!match) {
+ return (false);
+ }
+ }
+
+ return (true);
+}
+
+void
+ConfigBase::copy(ConfigBase& other) const {
+ // We will entirely replace loggers in the new configuration.
+ other.logging_info_.clear();
+ for (LoggingInfoStorage::const_iterator it = logging_info_.begin();
+ it != logging_info_.end(); ++it) {
+ other.addLoggingInfo(*it);
+ }
+}
+
+ElementPtr
+ConfigBase::toElement() const {
+ ElementPtr result = Element::createMap();
+
+ // Logging global map (skip if empty)
+ if (!logging_info_.empty()) {
+ ElementPtr logging = Element::createMap();
+ // Set loggers list
+ ElementPtr loggers = Element::createList();
+ for (LoggingInfoStorage::const_iterator logger =
+ logging_info_.cbegin();
+ logger != logging_info_.cend(); ++logger) {
+ loggers->add(logger->toElement());
+ }
+ logging->set("loggers", loggers);
+ result->set("Logging", logging);
+ }
+
+ return (result);
+}
+
+};
+};
diff --git a/src/lib/process/config_base.h b/src/lib/process/config_base.h
new file mode 100644
index 0000000000..71ba21534e
--- /dev/null
+++ b/src/lib/process/config_base.h
@@ -0,0 +1,88 @@
+// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef CONFIG_BASE_H
+#define CONFIG_BASE_H
+
+#include <cc/cfg_to_element.h>
+#include <cc/user_context.h>
+#include <process/logging_info.h>
+
+namespace isc {
+namespace process {
+
+/// @brief Base class for all configurations
+///
+/// This is a common base class that represents configurations.
+/// SrvConfig, D2CfgContext, CtrlAgentCfgContext and possibly other
+/// classes holding configurations are derived from this.
+///
+/// It should contain only those elements that are applicable to really
+/// every daemon we may have. Before adding anything here, please consider
+/// whether it would be usable by all of the following: DHCP servers,
+/// DDNS update daemon, Control Agent, Netconf daemon, DHCP relay,
+/// DHCP client.
+///
+/// This class currently holds information about logging configuration.
+class ConfigBase : public isc::data::UserContext, public isc::data::CfgToElement {
+public:
+ /// @name Modifiers and accesors for the configuration objects.
+ ///
+ /// @warning References to the objects returned by accessors are only
+ /// valid during the lifetime of the @c SrvConfig object which
+ /// returned them.
+ ///
+ //@{
+ /// @brief Returns logging specific configuration.
+ const process::LoggingInfoStorage& getLoggingInfo() const {
+ return (logging_info_);
+ }
+
+ /// @brief Sets logging specific configuration.
+ ///
+ /// @param logging_info New logging configuration.
+ void addLoggingInfo(const process::LoggingInfo& logging_info) {
+ logging_info_.push_back(logging_info);
+ }
+
+ /// @brief Apply logging configuration to log4cplus.
+ void applyLoggingCfg() const;
+
+ /// @brief Compares two configuration.
+ ///
+ /// @param other the other configuration to compare to
+ virtual bool equals(const ConfigBase& other) const;
+
+ /// @brief Converts to Element representation
+ ///
+ /// @return Element representation.
+ virtual isc::data::ElementPtr toElement() const;
+
+protected:
+ /// @brief Copies the current configuration to a new configuration.
+ ///
+ /// This method copies only the parameters defined in this class.
+ /// Since derived classes are expected to provide their own
+ /// copy methods, this one is protected and can be used only
+ /// by descendant classes.
+ ///
+ /// @param new_config this configuration will be copied to new_config
+ virtual void copy(ConfigBase& new_config) const;
+
+private:
+ /// @brief Logging specific information.
+ process::LoggingInfoStorage logging_info_;
+
+};
+
+/// @brief Non-const pointer to the @c SrvConfig.
+typedef boost::shared_ptr<ConfigBase> ConfigPtr;
+
+};
+};
+
+
+#endif /* CONFIG_BASE_H */