config_data.h 5.02 KB
Newer Older
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
// Copyright (C) 2009  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.

// $Id$

#ifndef __CONFIG_DATA_H
#define __CONFIG_DATA_H 1

#include <string>
#include <vector>

#include <config/module_spec.h>
#include <exceptions/exceptions.h>

namespace isc {
namespace config {

Jelte Jansen's avatar
doxygen    
Jelte Jansen committed
29
30
31
/// This exception is thrown when the caller is trying to access
/// data that doesn't exist (i.e. with an identifier that does not
/// point to anything defined in the .spec file)
32
33
class DataNotFoundError : public isc::Exception {
public:
34
    DataNotFoundError(const char* file, size_t line, const std::string& what) :
35
36
37
38
39
        isc::Exception(file, line, what) {}
};
    
class ConfigData {
public:
Jelte Jansen's avatar
doxygen    
Jelte Jansen committed
40
41
    /// Constructs a ConfigData option with no specification and an
    /// empty configuration.
42
    ConfigData() { _config = Element::createMap(); };
43

Jelte Jansen's avatar
doxygen    
Jelte Jansen committed
44
45
46
    /// Constructs a ConfigData option with the given specification
    /// and an empty configuration.
    /// \param module_spec A ModuleSpec for the relevant module
47
    ConfigData(const ModuleSpec& module_spec) : _module_spec(module_spec) { _config = Element::createMap(); }
48

49
50
    virtual ~ConfigData() {};

Jelte Jansen's avatar
doxygen    
Jelte Jansen committed
51
52
53
54
55
56
57
    /// Returns the value currently set for the given identifier
    /// If no value is set, the default value (as specified by the
    /// .spec file) is returned. If there is no value and no default,
    /// an empty ElementPtr is returned.
    /// Raises a DataNotFoundError if the identifier is bad.
    /// \param identifier The identifier pointing to the configuration
    ///        value that is to be returned
58
    ConstElementPtr getValue(const std::string& identifier) const;
Jelte Jansen's avatar
doxygen    
Jelte Jansen committed
59
60
61
62
63
64
65
66
67
68
69

    /// Returns the value currently set for the given identifier
    /// If no value is set, the default value (as specified by the
    /// .spec file) is returned. If there is no value and no default,
    /// an empty ElementPtr is returned.
    /// Raises a DataNotFoundError if the identifier is bad.
    /// \param is_default will be set to true if the value is taken
    ///                   from the specifications item_default setting,
    ///                   false otherwise
    /// \param identifier The identifier pointing to the configuration
    ///        value that is to be returned
70
71
    ConstElementPtr getValue(bool& is_default,
                             const std::string& identifier) const;
Jelte Jansen's avatar
doxygen    
Jelte Jansen committed
72
73

    /// Returns the ModuleSpec associated with this ConfigData object
74
    const ModuleSpec& getModuleSpec() const { return (_module_spec); }
75

Jelte Jansen's avatar
doxygen    
Jelte Jansen committed
76
    /// Set the ModuleSpec associated with this ConfigData object
77
    void setModuleSpec(ModuleSpec module_spec) { _module_spec = module_spec; };
78

Jelte Jansen's avatar
doxygen    
Jelte Jansen committed
79
80
81
82
    /// Set the local configuration (i.e. all non-default values)
    /// \param config An ElementPtr pointing to a MapElement containing
    ///        *all* non-default configuration values. Existing values
    ///        will be removed.
83
    void setLocalConfig(ElementPtr config) { _config = config; }
84

Jelte Jansen's avatar
doxygen    
Jelte Jansen committed
85
86
87
    /// Returns the local (i.e. non-default) configuration.
    /// \returns An ElementPtr pointing to a MapElement containing all
    ///          non-default configuration options.
JINMEI Tatuya's avatar
JINMEI Tatuya committed
88
    ElementPtr getLocalConfig() { return (_config); }
89

Jelte Jansen's avatar
doxygen    
Jelte Jansen committed
90
91
92
93
94
95
96
97
98
99
    /// Returns a list of all possible configuration options as specified
    ///         by the ModuleSpec.
    /// \param identifier If given, show the items at the given identifier
    ///                   (iff that is also a MapElement)
    /// \param recurse If true, child MapElements will be traversed to
    ///                add their identifiers to the result list
    /// \return An ElementPtr pointing to a ListElement containing
    ///         StringElements that specify the identifiers at the given
    ///         location (or all possible identifiers if identifier==""
    ///         and recurse==false)
100
101
    ConstElementPtr getItemList(const std::string& identifier = "",
                                bool recurse = false) const;
102

Jelte Jansen's avatar
doxygen    
Jelte Jansen committed
103
104
105
106
107
    /// Returns all current configuration settings (both non-default and default).
    /// \return An ElementPtr pointing to a MapElement containing
    ///         string->value elements, where the string is the
    ///         full identifier of the configuration option and the
    ///         value is an ElementPtr with the value.
108
    ConstElementPtr getFullConfig() const;
109
110
111
112
113
114
115
116
117

private:
    ElementPtr _config;
    ModuleSpec _module_spec;
};

}
}
#endif
118
119
120
121

// Local Variables: 
// mode: c++
// End: