1 | /* |
---|
2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
3 | * > www.orxonox.net < |
---|
4 | * |
---|
5 | * |
---|
6 | * License notice: |
---|
7 | * |
---|
8 | * This program is free software; you can redistribute it and/or |
---|
9 | * modify it under the terms of the GNU General Public License |
---|
10 | * as published by the Free Software Foundation; either version 2 |
---|
11 | * of the License, or (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 Free Software |
---|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
21 | * |
---|
22 | * Author: |
---|
23 | * Fabian 'x3n' Landau |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | /** |
---|
30 | @file |
---|
31 | @ingroup Output |
---|
32 | @brief Declaration of the OutputListener interface which receives output |
---|
33 | from orxonox::OutputManager. |
---|
34 | */ |
---|
35 | |
---|
36 | #ifndef _OutputListener_H__ |
---|
37 | #define _OutputListener_H__ |
---|
38 | |
---|
39 | #include "util/UtilPrereqs.h" |
---|
40 | |
---|
41 | #include <vector> |
---|
42 | |
---|
43 | #include "OutputDefinitions.h" |
---|
44 | |
---|
45 | namespace orxonox |
---|
46 | { |
---|
47 | /** |
---|
48 | @brief OutputListener is an interface which is used to receive output of a certain level and context from OutputManager. |
---|
49 | */ |
---|
50 | // See below the class declaration for a more detailed description. |
---|
51 | class _UtilExport OutputListener |
---|
52 | { |
---|
53 | public: |
---|
54 | OutputListener(bool bRegister = true); |
---|
55 | virtual ~OutputListener(); |
---|
56 | |
---|
57 | void registerListener(AdditionalContextListener* listener); |
---|
58 | void unregisterListener(AdditionalContextListener* listener); |
---|
59 | |
---|
60 | void setLevelMax(OutputLevel max); |
---|
61 | void setLevelRange(OutputLevel min, OutputLevel max); |
---|
62 | void setLevelMask(OutputLevel mask); |
---|
63 | |
---|
64 | void setAdditionalContextsLevelMax(OutputLevel max); |
---|
65 | void setAdditionalContextsLevelRange(OutputLevel min, OutputLevel max); |
---|
66 | void setAdditionalContextsLevelMask(OutputLevel mask); |
---|
67 | |
---|
68 | virtual void setAdditionalContextsMask(OutputContextMask mask); |
---|
69 | |
---|
70 | /// @brief Returns the level mask. |
---|
71 | inline OutputLevel getLevelMask() const |
---|
72 | { return this->levelMask_; } |
---|
73 | /// @brief Returns the additional contexts mask. |
---|
74 | inline OutputContextMask getAdditionalContextsMask() const |
---|
75 | { return this->additionalContextsMask_; } |
---|
76 | /// @brief Returns the additional contexts level mask. |
---|
77 | inline OutputLevel getAdditionalContextsLevelMask() const |
---|
78 | { return this->additionalContextsLevelMask_; } |
---|
79 | |
---|
80 | virtual bool acceptsOutput(OutputLevel level, const OutputContextContainer& context) const; |
---|
81 | |
---|
82 | /// @brief Called by OutputManager for each line of output, checks if this listener actually accepts this output before it calls the output() function. |
---|
83 | virtual void unfilteredOutput(OutputLevel level, const OutputContextContainer& context, const std::vector<std::string>& lines) |
---|
84 | { if (this->acceptsOutput(level, context)) this->output(level, context, lines); } |
---|
85 | |
---|
86 | protected: |
---|
87 | /// @brief Pure virtual function, needs to be implemented in order to receive output. |
---|
88 | virtual void output(OutputLevel level, const OutputContextContainer& context, const std::vector<std::string>& lines) = 0; |
---|
89 | |
---|
90 | inline const std::vector<AdditionalContextListener*>& getListeners() const |
---|
91 | { return this->listeners_; } |
---|
92 | |
---|
93 | private: |
---|
94 | std::vector<AdditionalContextListener*> listeners_; ///< List of all registered additional context listeners |
---|
95 | |
---|
96 | OutputLevel levelMask_; ///< Mask of accepted output levels, independent of contexts |
---|
97 | OutputContextMask additionalContextsMask_; ///< Mask of accepted additional contexts |
---|
98 | OutputLevel additionalContextsLevelMask_; ///< Mask of accepted output levels of the additional contexts |
---|
99 | }; |
---|
100 | |
---|
101 | /** |
---|
102 | @class OutputListener |
---|
103 | |
---|
104 | An instance of OutputListener registers itself at OutputManager and |
---|
105 | declares the desired output levels and contexts. OutputManager will |
---|
106 | then send output to it by calling the output() function. |
---|
107 | |
---|
108 | OutputListener has 3 masks to define the desired output. These masks |
---|
109 | can be used in two different ways (or as a combination of both): |
---|
110 | \li 1. By defining the \a "level mask": The OutputListener will then |
---|
111 | receive all output of these levels independent of the context. |
---|
112 | \li 2. By defining the \a "additional contexts mask" and the |
---|
113 | \a "additional contexts level mask": This way the listener |
---|
114 | receives only output of a particular context and level. |
---|
115 | \li 3. By using all 3 masks which combines the output defined by the |
---|
116 | first two ways. |
---|
117 | |
---|
118 | This can be illustrated as follows: |
---|
119 | |
---|
120 | 1. Only level mask: |
---|
121 | \li level-mask = error | warning; |
---|
122 | |
---|
123 | @verbatim |
---|
124 | | Contexts: | |
---|
125 | | A | B | C | D | |
---|
126 | --------|---|---|---|---| |
---|
127 | debug | - | - | - | - | |
---|
128 | --------|---|---|---|---| |
---|
129 | error | x | x | x | x | |
---|
130 | --------|---|---|---|---| [x] Receives output |
---|
131 | warning | x | x | x | x | [-] Does not receive output |
---|
132 | --------|---|---|---|---| |
---|
133 | status | - | - | - | - | |
---|
134 | --------|---|---|---|---| |
---|
135 | verbose | - | - | - | - | |
---|
136 | --------|---|---|---|---| |
---|
137 | @endverbatim |
---|
138 | |
---|
139 | 2. Only additional contexts: |
---|
140 | \li additional-contexts-mask = B | D; |
---|
141 | \li additional-contexts-level-mask = debug | verbose; |
---|
142 | |
---|
143 | @verbatim |
---|
144 | | Contexts: | |
---|
145 | | A | B | C | D | |
---|
146 | --------|---|---|---|---| |
---|
147 | debug | - | x | - | x | |
---|
148 | --------|---|---|---|---| |
---|
149 | error | - | - | - | - | |
---|
150 | --------|---|---|---|---| [x] Receives output |
---|
151 | warning | - | - | - | - | [-] Does not receive output |
---|
152 | --------|---|---|---|---| |
---|
153 | status | - | - | - | - | |
---|
154 | --------|---|---|---|---| |
---|
155 | verbose | - | x | - | x | |
---|
156 | --------|---|---|---|---| |
---|
157 | @endverbatim |
---|
158 | |
---|
159 | 3. Both level mask plus additional contexts: |
---|
160 | \li level-mask = error | warning; |
---|
161 | \li additional-contexts-mask = B | D; |
---|
162 | \li additional-contexts-level-mask = debug | verbose; |
---|
163 | |
---|
164 | @verbatim |
---|
165 | | Contexts: | |
---|
166 | | A | B | C | D | |
---|
167 | --------|---|---|---|---| |
---|
168 | debug | - | x | - | x | |
---|
169 | --------|---|---|---|---| |
---|
170 | error | x | x | x | x | |
---|
171 | --------|---|---|---|---| [x] Receives output |
---|
172 | warning | x | x | x | x | [-] Does not receive output |
---|
173 | --------|---|---|---|---| |
---|
174 | status | - | - | - | - | |
---|
175 | --------|---|---|---|---| |
---|
176 | verbose | - | x | - | x | |
---|
177 | --------|---|---|---|---| |
---|
178 | @endverbatim |
---|
179 | */ |
---|
180 | } |
---|
181 | |
---|
182 | #endif /* _OutputListener_H__ */ |
---|