4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief Config public header */
31 #ifndef HH_SENF_Scheduler_Console_Config_
32 #define HH_SENF_Scheduler_Console_Config_ 1
35 #include <boost/utility.hpp>
37 #include "Executor.hh"
39 //#include "Config.mpp"
41 //-/////////////////////////////////////////////////////////////////////////////////////////////////
46 /** \brief Combine multiple configuration sources
48 A ConfigBundle combines several sources and parses them together, in the order they were
49 added. Parse restrictions are applied uniformly to all sources.
51 // Add three configuration sources: A system configuration file, a user configuration file
52 // and command line options
53 senf::console::ConfigBundle conf;
54 conf.add( senf::console::FileConfig("/etc/some.conf") );
55 conf.add( senf::console::FileConfig("local.conf") );
56 conf.add( senf::console::OptionsConfig(senf::Daemon::instance().argc(),
57 senf::Daemon::instance().argv()) );
62 This bundle may also be passed to other code which may use restricted parsing to parse
63 partial information from all configuration sources.
65 \ingroup console_access
70 //-////////////////////////////////////////////////////////////////////////
71 ///\name Structors and default members
74 ConfigBundle(); ///< root node is set to console::root()
75 ConfigBundle(DirectoryNode & root); ///< Set custom root node
78 //-////////////////////////////////////////////////////////////////////////
80 template <class Source>
81 Source & add(boost::intrusive_ptr<Source> source);
82 ///< Add configuration source
84 void parse(); ///< Parse config bundle
85 /**< All nodes already parsed are skipped */
86 void parse(DirectoryNode & restrict); ///< Parse config bundle under \a restrict
87 /**< Only nodes which are children of \a restrict are
90 bool complete() const; ///< \c true, if all nodes have been parsed
91 bool parsed(GenericNode & node) const; ///< \c true. if \a node has been parsed
92 void reset(); ///< Reset node parse info state
93 /**< After a call to reset(), all information about already
94 parsed nodes is cleared. Calling parse() will parse the
95 complete config bundle again. */
97 DirectoryNode & root() const;
98 void chroot(DirectoryNode & node);
103 void parseInternal();
105 typedef std::list<detail::ConfigSource::ptr> Sources;
108 detail::RestrictedExecutor executor_;
112 // hrmpf ... Can't place this into Config.ih ...
114 /** \brief Internal: Provide ConfigBundle facade for a single-source config.
116 The BundleMixin is used to define supplementary configuration objects for one specific
117 configuration source. A BundleMixin is \e not a ConfigBundle since it has no public \c add()
124 BundleMixin(DirectoryNode & root);
126 void parse(); ///< Parse config file
127 /**< All nodes already parsed are skipped */
128 void parse(DirectoryNode & restrict); ///< Parse config file under \a restrict
129 /**< Only nodes which are children of \a restrict are
132 bool complete() const; ///< \c true, if all nodes have been parsed
133 bool parsed(GenericNode & node) const; ///< \c true. if \a node has been parsed
134 void reset(); ///< Reset node parse info state
135 /**< After a call to reset(), all information about already
136 parsed nodes is cleared. Calling parse() will parse the
137 complete config file again. */
140 template <class Source>
141 Source & add(boost::intrusive_ptr<Source> source);
144 ConfigBundle bundle_;
149 //-/////////////////////////////////////////////////////////////////////////////////////////////////
150 #include "Config.cci"
151 //#include "Config.ct"
152 #include "Config.cti"
159 // comment-column: 40
160 // c-file-style: "senf"
161 // indent-tabs-mode: nil
162 // ispell-local-dictionary: "american"
163 // compile-command: "scons -u test"