4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief Config internal header */
26 #ifndef IH_SENF_Scheduler_Console_Config_
27 #define IH_SENF_Scheduler_Console_Config_ 1
30 #include <boost/utility.hpp>
31 #include <boost/intrusive_ptr.hpp>
32 #include "Executor.hh"
33 #include "../../Utils/intrusive_refcount.hh"
34 #include "../../Utils/DiscardStream.hh"
36 ///////////////////////////////ih.p////////////////////////////////////////
42 /** \brief Internal: Executor wrapper implementing restricted execution
44 A RestrictedExecutor will only process commands which a re children of a given node. It does
45 \e not follow any links.
47 class RestrictedExecutor
51 typedef void result_type;
53 ///////////////////////////////////////////////////////////////////////////
54 //\/name Structors and default members
57 RestrictedExecutor(DirectoryNode & root = senf::console::root());
60 ///////////////////////////////////////////////////////////////////////////
62 void execute(std::ostream & output, ParseCommandInfo const & command);
64 /**< Output will be written to \a output.
65 Same as operator()(). */
67 void operator()(std::ostream & output, ParseCommandInfo const & command);
69 /**< Output will be written to \a output.
72 bool complete() const; ///< \c true, if all nodes have been parsed
73 bool parsed(GenericNode & node) const; ///< \c true. if \a node has been parsed
74 void reset(); ///< Reset node parse info state
75 /**< After a call to reset(), all information about already
76 parsed nodes is cleared. Calling parse() will parse the
77 complete config file again. */
79 DirectoryNode & root() const;
80 void chroot(DirectoryNode & node);
82 std::ostream & stream();
89 void policyCallback(DirectoryNode & dir, std::string const & item);
90 void insertParsedNode(DirectoryNode & node);
92 typedef std::vector<DirectoryNode::weak_ptr> ParsedNodes;
95 ParsedNodes parsedNodes_;
96 DirectoryNode::ptr restrict_;
97 DiscardStream stream_;
99 friend class RestrictGuard;
102 /** \brief Internal: Set restricted node of a RestrictedExecutor
104 A RestrictGuard will set the node to which to restrict. It will automatically reset the node
107 class RestrictedExecutor::RestrictGuard
110 ///////////////////////////////////////////////////////////////////////////
111 //\/name Structors and default members
114 explicit RestrictGuard(RestrictedExecutor & executor);
115 RestrictGuard(RestrictedExecutor & executor, DirectoryNode & restrict);
119 ///////////////////////////////////////////////////////////////////////////
124 RestrictedExecutor & executor_;
128 /** \brief Internal: ConfigSource base class
130 All configuration sources derive from ConfigSource. A ConigSource somehow reads
131 configuration commands and passes them to a RestrictedExecutor.
134 : public senf::intrusive_refcount
137 typedef boost::intrusive_ptr<ConfigSource> ptr;
138 virtual ~ConfigSource();
140 void parse(RestrictedExecutor & executor);
145 virtual void v_parse(RestrictedExecutor & executor) = 0;
150 ///////////////////////////////ih.e////////////////////////////////////////
157 // comment-column: 40
158 // c-file-style: "senf"
159 // indent-tabs-mode: nil
160 // ispell-local-dictionary: "american"
161 // compile-command: "scons -u test"