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 internal header */
31 #ifndef IH_SENF_Scheduler_Console_Config_
32 #define IH_SENF_Scheduler_Console_Config_ 1
35 #include <boost/utility.hpp>
36 #include <boost/intrusive_ptr.hpp>
37 #include "Executor.hh"
38 #include <senf/Utils/intrusive_refcount.hh>
39 #include <senf/Utils/DiscardStream.hh>
41 //-/////////////////////////////////////////////////////////////////////////////////////////////////
47 /** \brief Internal: Executor wrapper implementing restricted execution
49 A RestrictedExecutor will only process commands which a re children of a given node. It does
50 \e not follow any links.
52 class RestrictedExecutor
56 typedef void result_type;
58 //-/////////////////////////////////////////////////////////////////////////////////////////
59 //\/name Structors and default members
62 RestrictedExecutor(DirectoryNode & root = senf::console::root());
65 //-/////////////////////////////////////////////////////////////////////////////////////////
67 void execute(std::ostream & output, ParseCommandInfo const & command);
69 /**< Output will be written to \a output.
70 Same as operator()(). */
72 void operator()(std::ostream & output, ParseCommandInfo const & command);
74 /**< Output will be written to \a output.
77 GenericNode & getNode(ParseCommandInfo const & command);
79 bool complete() const; ///< \c true, if all nodes have been parsed
80 bool parsed(GenericNode & node) const; ///< \c true. if \a node has been parsed
81 void reset(); ///< Reset node parse info state
82 /**< After a call to reset(), all information about already
83 parsed nodes is cleared. Calling parse() will parse the
84 complete config file again. */
86 DirectoryNode & root() const;
87 void chroot(DirectoryNode & node);
89 std::ostream & stream();
96 void policyCallback(DirectoryNode & dir, std::string const & item);
97 void insertParsedNode(DirectoryNode & node);
99 typedef std::vector<DirectoryNode::weak_ptr> ParsedNodes;
102 ParsedNodes parsedNodes_;
103 DirectoryNode::ptr restrict_;
104 DiscardStream stream_;
106 friend class RestrictGuard;
109 /** \brief Internal: Set restricted node of a RestrictedExecutor
111 A RestrictGuard will set the node to which to restrict. It will automatically reset the node
114 class RestrictedExecutor::RestrictGuard
117 //-/////////////////////////////////////////////////////////////////////////////////////////
118 //\/name Structors and default members
121 explicit RestrictGuard(RestrictedExecutor & executor);
122 RestrictGuard(RestrictedExecutor & executor, DirectoryNode & restrict);
126 //-/////////////////////////////////////////////////////////////////////////////////////////
131 RestrictedExecutor & executor_;
135 /** \brief Internal: ConfigSource base class
137 All configuration sources derive from ConfigSource. A ConigSource somehow reads
138 configuration commands and passes them to a RestrictedExecutor.
141 : public senf::intrusive_refcount
144 typedef boost::intrusive_ptr<ConfigSource> ptr;
145 virtual ~ConfigSource();
147 void parse(RestrictedExecutor & executor);
152 virtual void v_parse(RestrictedExecutor & executor) = 0;
157 //-/////////////////////////////////////////////////////////////////////////////////////////////////
164 // comment-column: 40
165 // c-file-style: "senf"
166 // indent-tabs-mode: nil
167 // ispell-local-dictionary: "american"
168 // compile-command: "scons -u test"