1 /* ScummVM - Graphic Adventure Engine 2 * 3 * ScummVM is the legal property of its developers, whose names 4 * are too numerous to list here. Please refer to the COPYRIGHT 5 * file distributed with this source distribution. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 */ 22 23 #ifndef COMMON_DEBUG_CHANNELS_H 24 #define COMMON_DEBUG_CHANNELS_H 25 26 #include "common/scummsys.h" 27 28 #include "common/hashmap.h" 29 #include "common/hash-str.h" 30 #include "common/list.h" 31 #include "common/singleton.h" 32 #include "common/str.h" 33 34 35 namespace Common { 36 37 // TODO: Find a better name for this 38 class DebugManager : public Singleton<DebugManager> { 39 public: 40 41 struct DebugChannel { DebugChannelDebugChannel42 DebugChannel() : channel(0), enabled(false) {} DebugChannelDebugChannel43 DebugChannel(uint32 c, const String &n, const String &d) 44 : name(n), description(d), channel(c), enabled(false) {} 45 46 String name; 47 String description; 48 49 uint32 channel; 50 bool enabled; 51 }; 52 53 /** 54 * Adds a debug channel. 55 * 56 * A debug channel is considered roughly similar to what our debug levels described by 57 * gDebugLevel try to achieve: 58 * 59 * Debug channels should only affect the display of additional debug output, based on 60 * their state. That is if they are enabled, channel specific debug messages should 61 * be shown. If they are disabled on the other hand, those messages will be hidden. 62 * 63 * @see gDebugLevel. 64 * 65 * Note that we have debug* functions which depend both on the debug level set and 66 * specific debug channels. Those functions will only show output, when *both* criteria 67 * are satisfied. 68 * 69 * @param channel the channel flag (should be OR-able i.e. first one should be 1 then 2, 4, etc.) 70 * @param name the option name which is used in the debugger/on the command line to enable 71 * this special debug level (case will be ignored) 72 * @param description the description which shows up in the debugger 73 * @return true on success false on failure 74 */ 75 bool addDebugChannel(uint32 channel, const String &name, const String &description); 76 77 /** 78 * Resets all engine specific debug channels. 79 */ 80 void clearAllDebugChannels(); 81 82 /** 83 * Enables an debug channel. 84 * 85 * @param name the name of the debug channel to enable 86 * @return true on success, false on failure 87 */ 88 bool enableDebugChannel(const String &name); 89 90 /** 91 * Disables an debug channel. 92 * 93 * @param name the name of the debug channel to disable 94 * @return true on success, false on failure 95 */ 96 bool disableDebugChannel(const String &name); 97 98 typedef List<DebugChannel> DebugChannelList; 99 100 /** 101 * Lists all engine specific debug channels. 102 * 103 * @return returns an array with all debug channels 104 */ 105 DebugChannelList listDebugChannels(); 106 107 /** 108 * Enable all debug channels. 109 */ 110 void enableAllDebugChannels(); 111 112 /** 113 * Disable all debug channels. 114 */ 115 void disableAllDebugChannels(); 116 117 /** 118 * Test whether the given debug channel is enabled. 119 */ 120 bool isDebugChannelEnabled(uint32 channel, bool enforce = false); 121 122 private: 123 typedef HashMap<String, DebugChannel, IgnoreCase_Hash, IgnoreCase_EqualTo> DebugChannelMap; 124 125 DebugChannelMap gDebugChannels; 126 uint32 gDebugChannelsEnabled; 127 128 friend class Singleton<SingletonBaseType>; DebugManager()129 DebugManager() : gDebugChannelsEnabled(0) {} 130 }; 131 132 /** Shortcut for accessing the debug manager. */ 133 #define DebugMan Common::DebugManager::instance() 134 135 } // End of namespace Common 136 137 #endif 138