[8765] | 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 | |
---|
[8848] | 29 | /** |
---|
| 30 | @file |
---|
| 31 | @ingroup Output |
---|
| 32 | @brief Declaration of the OutputManager class which receives output from orxonox::OutputStream |
---|
| 33 | and distributes it to all instances of orxonox::OutputListener. |
---|
| 34 | */ |
---|
| 35 | |
---|
[8765] | 36 | #ifndef _OutputManager_H__ |
---|
| 37 | #define _OutputManager_H__ |
---|
| 38 | |
---|
| 39 | #include "util/UtilPrereqs.h" |
---|
| 40 | |
---|
| 41 | #include <vector> |
---|
[8833] | 42 | #include <map> |
---|
[10829] | 43 | #include <memory> |
---|
[8771] | 44 | |
---|
[8765] | 45 | #include "OutputDefinitions.h" |
---|
[9550] | 46 | #include "AdditionalContextListener.h" |
---|
[8765] | 47 | |
---|
| 48 | namespace orxonox |
---|
| 49 | { |
---|
[8848] | 50 | /** |
---|
| 51 | @brief OutputManager acts as the center of the output system and is implemented as a singleton. |
---|
| 52 | |
---|
| 53 | All instances of OutputStream (and hence also the orxout() function) |
---|
| 54 | send their buffered output to OutputManager. OutputManager then |
---|
| 55 | distributes this output to all registered instances of OutputListener. |
---|
| 56 | |
---|
| 57 | For each listener OutputManager checks if it wants to receive output |
---|
| 58 | with the given level and context. OutputManager itself also maintains |
---|
| 59 | masks that define the accepted levels and concept. They are a |
---|
| 60 | combination of the masks of all output listeners. See the description |
---|
| 61 | of OutputListener for a more conclusive description of these masks. |
---|
| 62 | |
---|
| 63 | Additionally OutputManager is used to register output contexts. |
---|
| 64 | */ |
---|
[9550] | 65 | class _UtilExport OutputManager : public AdditionalContextListener |
---|
[8765] | 66 | { |
---|
| 67 | public: |
---|
[9550] | 68 | OutputManager(); |
---|
| 69 | OutputManager(const OutputManager&); |
---|
| 70 | virtual ~OutputManager(); |
---|
| 71 | |
---|
[8765] | 72 | static OutputManager& getInstance(); |
---|
[8776] | 73 | static OutputManager& getInstanceAndCreateListeners(); |
---|
[8765] | 74 | |
---|
[9550] | 75 | inline MemoryWriter* getMemoryWriter() { return this->memoryWriterInstance_; } |
---|
| 76 | inline ConsoleWriter* getConsoleWriter() { return this->consoleWriterInstance_; } |
---|
| 77 | inline LogWriter* getLogWriter() { return this->logWriterInstance_; } |
---|
[8765] | 78 | |
---|
[9550] | 79 | virtual void pushMessage(OutputLevel level, const OutputContextContainer& context, const std::string& message); |
---|
[8765] | 80 | |
---|
[9550] | 81 | virtual void registerListener(OutputListener* listener); |
---|
| 82 | virtual void unregisterListener(OutputListener* listener); |
---|
[8765] | 83 | |
---|
[10817] | 84 | virtual void updatedLevelMask(const OutputListener* listener) override |
---|
[9550] | 85 | { this->updateCombinedLevelMask(); } |
---|
[10817] | 86 | virtual void updatedAdditionalContextsLevelMask(const OutputListener* listener) override |
---|
[9550] | 87 | { this->updateCombinedAdditionalContextsLevelMask(); } |
---|
[10817] | 88 | virtual void updatedAdditionalContextsMask(const OutputListener* listener) override |
---|
[9550] | 89 | { this->updateCombinedAdditionalContextsMask(); } |
---|
| 90 | |
---|
[8848] | 91 | /** |
---|
| 92 | @brief Returns true if at least one of the output listeners will accept output with the given level and context. |
---|
| 93 | |
---|
| 94 | For the sake of performance, output messages with levels or |
---|
| 95 | contexts that are not accepted should be ignored or, even |
---|
| 96 | better, not generated at all. |
---|
| 97 | */ |
---|
[8833] | 98 | inline bool acceptsOutput(OutputLevel level, const OutputContextContainer& context) const |
---|
| 99 | { |
---|
| 100 | return (this->combinedLevelMask_ & level) || |
---|
| 101 | ((this->combinedAdditionalContextsLevelMask_ & level) && (this->combinedAdditionalContextsMask_ & context.mask)); |
---|
| 102 | } |
---|
[8765] | 103 | |
---|
[8833] | 104 | const OutputContextContainer& registerContext(const std::string& name, const std::string& subname = ""); |
---|
[8765] | 105 | |
---|
[8771] | 106 | const std::string& getLevelName(OutputLevel level) const; |
---|
[8833] | 107 | std::string getDefaultPrefix(OutputLevel level, const OutputContextContainer& context) const; |
---|
[8799] | 108 | |
---|
[9550] | 109 | inline const std::vector<OutputListener*>& getListeners() const |
---|
| 110 | { return this->listeners_; } |
---|
| 111 | |
---|
| 112 | inline OutputLevel getCombinedLevelMask() const { return this->combinedLevelMask_; } |
---|
| 113 | inline OutputLevel getCombinedAdditionalContextsLevelMask() const { return this->combinedAdditionalContextsLevelMask_; } |
---|
| 114 | inline OutputContextMask getCombinedAdditionalContextsMask() const { return this->combinedAdditionalContextsMask_; } |
---|
| 115 | |
---|
[8765] | 116 | private: |
---|
[9550] | 117 | void updateMasks(); |
---|
| 118 | void updateCombinedLevelMask(); |
---|
| 119 | void updateCombinedAdditionalContextsLevelMask(); |
---|
| 120 | void updateCombinedAdditionalContextsMask(); |
---|
[8765] | 121 | |
---|
[8848] | 122 | std::vector<OutputListener*> listeners_; ///< List of all registered output listeners |
---|
[8765] | 123 | |
---|
[8848] | 124 | OutputLevel combinedLevelMask_; ///< The combined mask of accepted levels of all listeners |
---|
| 125 | OutputLevel combinedAdditionalContextsLevelMask_; ///< The combined mask of accepted additional contexts levels of all listeners |
---|
| 126 | OutputContextMask combinedAdditionalContextsMask_; ///< The combined mask of accepted additional contexts of all listeners |
---|
[8771] | 127 | |
---|
[8848] | 128 | std::map<std::string, OutputContextMask> contextMasks_; ///< Contains all main-contexts and their masks |
---|
| 129 | std::map<std::string, OutputContextContainer> contextContainers_; ///< Contains all contexts including sub-contexts and their containers |
---|
| 130 | OutputContextSubID subcontextCounter_; ///< Counts the number of sub-contexts (and generates their IDs) |
---|
[9550] | 131 | |
---|
| 132 | bool isInitialized_; ///< Becomes true once the following instances were created |
---|
| 133 | MemoryWriter* memoryWriterInstance_; ///< The main instance of MemoryWriter, managed by OutputManager |
---|
| 134 | ConsoleWriter* consoleWriterInstance_; ///< The main instance of ConsoleWriter, managed by OutputManager |
---|
| 135 | LogWriter* logWriterInstance_; ///< The main instance of LogWriter, managed by OutputManager |
---|
| 136 | |
---|
| 137 | public: |
---|
| 138 | struct _UtilExport Testing |
---|
| 139 | { |
---|
[10829] | 140 | static std::shared_ptr<OutputManager>& getInstancePointer(); |
---|
[9550] | 141 | }; |
---|
[8765] | 142 | }; |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | #endif /* _OutputManager_H__ */ |
---|