Console: Documentation of the configuration support
[senf.git] / Console / Config.ih
1 // $Id$
2 //
3 // Copyright (C) 2008 
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
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.
12 //
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.
17 //
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.
22
23 /** \file
24     \brief Config internal header */
25
26 #ifndef IH_Console_Config_
27 #define IH_Console_Config_ 1
28
29 // Custom includes
30 #include <boost/utility.hpp>
31 #include <boost/intrusive_ptr.hpp>
32 #include "Executor.hh"
33 #include "../Utils/intrusive_refcount.hh"
34
35 ///////////////////////////////ih.p////////////////////////////////////////
36
37 namespace senf {
38 namespace console {
39 namespace detail {
40
41     /** \brief Internal: Executor wrapper implementing restricted execution
42         
43         A RestrictedExecutor will only process commands which a re children of a given node. It does
44         \e not follow any links.
45      */
46     class RestrictedExecutor
47         : boost::noncopyable
48     {
49     public:
50         typedef void result_type;
51
52         ///////////////////////////////////////////////////////////////////////////
53         //\/name Structors and default members
54         ///\{
55
56         RestrictedExecutor(DirectoryNode & root = senf::console::root());
57
58         ///\}
59         ///////////////////////////////////////////////////////////////////////////
60
61         void execute(std::ostream & output, ParseCommandInfo const & command);
62                                         ///< Execute command
63                                         /**< Output will be written to \a output. 
64                                              Same as operator()(). */
65
66         void operator()(std::ostream & output, ParseCommandInfo const & command);
67                                         ///< Execute command
68                                         /**< Output will be written to \a output. 
69                                              Same as execute(). */
70
71         bool complete() const;          ///< \c true, if all nodes have been parsed
72         bool parsed(GenericNode & node) const; ///< \c true. if \a node has been parsed
73         void reset();                   ///< Reset node parse info state
74                                         /**< After a call to reset(), all information about already
75                                              parsed nodes is cleared. Calling parse() will parse the
76                                              complete config file again. */
77
78         DirectoryNode & root() const;
79
80         class RestrictGuard;
81
82     protected:
83
84     private:
85         void policyCallback(DirectoryNode & dir, std::string const & item);
86         void insertParsedNode(DirectoryNode & node);
87
88         typedef std::vector<DirectoryNode::weak_ptr> ParsedNodes;
89
90         Executor executor_;
91         ParsedNodes parsedNodes_;
92         DirectoryNode::ptr restrict_;
93
94         friend class RestrictGuard;
95     };
96
97     /** \brief Internal: Set restricted node of a RestrictedExecutor
98         
99         A RestrictGuard will set the node to which to restrict. It will automatically reset the node
100         in it's destructor.
101      */
102     class RestrictedExecutor::RestrictGuard
103     {
104     public:
105         ///////////////////////////////////////////////////////////////////////////
106         //\/name Structors and default members
107         ///\{
108
109         explicit RestrictGuard(RestrictedExecutor & executor);
110         RestrictGuard(RestrictedExecutor & executor, DirectoryNode & restrict);
111         ~RestrictGuard();
112
113         ///\}
114         ///////////////////////////////////////////////////////////////////////////
115
116     protected:
117
118     private:
119         RestrictedExecutor & executor_;
120
121     };
122
123     /** \brief Internal: ConfigSource base class
124
125         All configuration sources derive from ConfigSource. A ConigSource somehow reads
126         configuration commands and passes them to a RestrictedExecutor.
127       */
128     class ConfigSource
129         : public senf::intrusive_refcount
130     {
131     public:
132         typedef boost::intrusive_ptr<ConfigSource> ptr;
133         virtual ~ConfigSource();
134
135         void parse(RestrictedExecutor & executor);
136
137     protected:
138
139     private:
140         virtual void v_parse(RestrictedExecutor & executor) = 0;
141     };
142
143 }}}
144
145 ///////////////////////////////ih.e////////////////////////////////////////
146 #endif
147
148 \f
149 // Local Variables:
150 // mode: c++
151 // fill-column: 100
152 // comment-column: 40
153 // c-file-style: "senf"
154 // indent-tabs-mode: nil
155 // ispell-local-dictionary: "american"
156 // compile-command: "scons -u test"
157 // End: