1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// Copyright (C) 2018-2019 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/config_ctl_info.h>
#include <process/logging_info.h>
#include <util/optional.h>
#include <boost/date_time/posix_time/posix_time.hpp><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.

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 common server 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 ConfigBase 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
    bool equals(const ConfigBase& other) const;

    /// @brief Merges specified configuration into this configuration.
    ///
    /// This method merges logging and config control configuration into
    /// this configuration. The new logging configuration replaces the
    /// existing configuration if the new logging configuration is
    /// non-empty. The new config control configuration replaces the
    /// existing configuration if the new logging configuration is
    /// non-null and non-empty.
    ///
    /// @warning The call to @c merge may modify the data in the @c other
    /// object. Therefore, the caller must not rely on the data held
    /// in the @c other object after the call to @c merge. Also, the
    /// data held in @c other must not be modified after the call to
    /// @c merge because it may affect the merged configuration.
    ///
    /// If a derivation of this class implements the @c merge method
    /// it should call @c ConfigBase::merge.
    ///
    /// @param other the other configuration to be merged into this
    /// configuration.
    virtual void merge(ConfigBase& other);

    /// @brief Converts to Element representation
    ///
    /// This creates a Map element with the following content (expressed
    /// as JSON):
    /// {{{
    /// {
    ///     "Server": {
    ///         :
    ///     }
    /// }
    /// }}}
    ///
    /// Note that it will not contain the configuration control information
    /// (i.e. "config-control"), as this is not a top-level element, rather
    /// it belongs within the configured process element.
    ///
    /// @return Element representation.
    virtual isc::data::ElementPtr toElement() const;<--- Function in derived class

    /// @brief Fetches a read-only copy of the configuration control
    /// information
    /// @return pointer to the const ConfigControlInfo
    process::ConstConfigControlInfoPtr getConfigControlInfo() const {
        return (config_ctl_info_);
    }

    /// @brief Set the configuration control information
    ///
    /// Updates the internal pointer to the configuration control
    /// information with the given pointer value.  If the given pointer
    /// is empty, the internal pointer will be reset.
    ///
    /// @param config_ctl_info pointer to the configuration value
    /// to store.
    void setConfigControlInfo(const process::ConfigControlInfoPtr&
                              config_ctl_info) {
        config_ctl_info_ = config_ctl_info;
    }

    /// @brief Sets the server's logical name
    ///
    /// @param server_tag a unique string name which identifies this server
    /// from any other configured servers
    void setServerTag(const util::Optional<std::string>& server_tag) {
        server_tag_ = server_tag;
    }

    /// @brief Returns the server's logical name
    ///
    /// @return string containing the server's tag
    util::Optional<std::string> getServerTag() const {
        return (server_tag_);
    }

    /// @brief Returns the last commit timestamp.
    /// @return the last commit timestamp.
    boost::posix_time::ptime getLastCommitTime() const {
        return (last_commit_time_);
    }

    /// @brief Sets the last commit timestamp.
    /// @param last_commit_time last commit timestamp.
    void setLastCommitTime(const boost::posix_time::ptime& last_commit_time) {
        last_commit_time_ = last_commit_time;
    }

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
    void copy(ConfigBase& new_config) const;

private:
    /// @brief Logging specific information.
    process::LoggingInfoStorage logging_info_;

    /// @brief Configuration control information.
    process::ConfigControlInfoPtr config_ctl_info_;

    /// @brief Logical name of the server
    util::Optional<std::string> server_tag_;

    /// @brief Stores the last commit timestamp.
    boost::posix_time::ptime last_commit_time_;
};

/// @brief Non-const pointer to the @c ConfigBase.
typedef boost::shared_ptr<ConfigBase> ConfigPtr;

};
};

#endif /* CONFIG_BASE_H */