From f2f28c45490a7f25ea1ed366d0450e0fac97e08b Mon Sep 17 00:00:00 2001 From: sluicebox <22204938+sluicebox@users.noreply.github.com> Date: Wed, 9 Jun 2021 19:08:02 -0600 Subject: [PATCH] COMMON: Rename DebugManager methods, update comments --- base/main.cpp | 8 ++++---- base/plugins.cpp | 10 +++++----- common/debug-channels.h | 25 +++++++++++++++---------- common/debug.cpp | 20 ++++++++++---------- engines/scumm/debugger.cpp | 2 +- gui/debugger.cpp | 2 +- 6 files changed, 36 insertions(+), 31 deletions(-) diff --git a/base/main.cpp b/base/main.cpp index df2711bf976..6229c5ae85f 100644 --- a/base/main.cpp +++ b/base/main.cpp @@ -134,7 +134,7 @@ static const Plugin *detectPlugin() { // Query the plugin for the game descriptor printf(" Looking for a plugin supporting this target... %s\n", plugin->getName()); const MetaEngineDetection &metaEngine = plugin->get(); - DebugMan.debugFlagsRegister(metaEngine.getDebugChannels()); + DebugMan.addAllDebugChannels(metaEngine.getDebugChannels()); PlainGameDescriptor game = metaEngine.findGame(gameId.c_str()); if (!game.gameId) { warning("'%s' is an invalid game ID for the engine '%s'. Use the --list-games option to list supported game IDs", gameId.c_str(), engineId.c_str()); @@ -194,7 +194,7 @@ static Common::Error runGame(const Plugin *plugin, const Plugin *enginePlugin, O } // before we instantiate the engine, we register debug channels for it - DebugMan.debugFlagsRegister(metaEngineDetection.getDebugChannels()); + DebugMan.addAllDebugChannels(metaEngineDetection.getDebugChannels()); // Create the game's MetaEngine. MetaEngine &metaEngine = enginePlugin->get(); @@ -219,7 +219,7 @@ static Common::Error runGame(const Plugin *plugin, const Plugin *enginePlugin, O ConfMan.removeGameDomain(target.c_str()); } - DebugMan.clearAllDebugChannels(); + DebugMan.removeAllDebugChannels(); return err; } @@ -319,7 +319,7 @@ static Common::Error runGame(const Plugin *plugin, const Plugin *enginePlugin, O // Free up memory delete engine; - DebugMan.clearAllDebugChannels(); + DebugMan.removeAllDebugChannels(); // Reset the file/directory mappings SearchMan.clear(); diff --git a/base/plugins.cpp b/base/plugins.cpp index 0cbabd4ff08..af804a8e592 100644 --- a/base/plugins.cpp +++ b/base/plugins.cpp @@ -678,7 +678,7 @@ QualifiedGameList EngineManager::findGamesMatching(const Common::String &engineI const Plugin *p = EngineMan.findPlugin(engineId); if (p) { const MetaEngineDetection &engine = p->get(); - DebugMan.debugFlagsRegister(engine.getDebugChannels()); + DebugMan.addAllDebugChannels(engine.getDebugChannels()); PlainGameDescriptor pluginResult = engine.findGame(gameId.c_str()); if (pluginResult.gameId) { @@ -708,7 +708,7 @@ QualifiedGameList EngineManager::findGameInLoadedPlugins(const Common::String &g for (iter = plugins.begin(); iter != plugins.end(); ++iter) { const MetaEngineDetection &engine = (*iter)->get(); - DebugMan.debugFlagsRegister(engine.getDebugChannels()); + DebugMan.addAllDebugChannels(engine.getDebugChannels()); PlainGameDescriptor pluginResult = engine.findGame(gameId.c_str()); if (pluginResult.gameId) { @@ -736,7 +736,7 @@ DetectionResults EngineManager::detectGames(const Common::FSList &fslist) const for (iter = plugins.begin(); iter != plugins.end(); ++iter) { const MetaEngineDetection &metaEngine = (*iter)->get(); // set the debug flags - DebugMan.debugFlagsRegister(metaEngine.getDebugChannels()); + DebugMan.addAllDebugChannels(metaEngine.getDebugChannels()); DetectedGames engineCandidates = metaEngine.detectGames(fslist); for (uint i = 0; i < engineCandidates.size(); i++) { @@ -867,7 +867,7 @@ QualifiedGameDescriptor EngineManager::findTarget(const Common::String &target, // Make sure it does support the game ID const MetaEngineDetection &engine = foundPlugin->get(); - DebugMan.debugFlagsRegister(engine.getDebugChannels()); + DebugMan.addAllDebugChannels(engine.getDebugChannels()); PlainGameDescriptor desc = engine.findGame(domain->getVal("gameid").c_str()); if (!desc.gameId) { return QualifiedGameDescriptor(); @@ -934,7 +934,7 @@ void EngineManager::upgradeTargetForEngineId(const Common::String &target) const // Take the first detection entry const MetaEngineDetection &metaEngine = plugin->get(); // set debug flags before call detectGames - DebugMan.debugFlagsRegister(metaEngine.getDebugChannels()); + DebugMan.addAllDebugChannels(metaEngine.getDebugChannels()); DetectedGames candidates = metaEngine.detectGames(files); if (candidates.empty()) { warning("No games supported by the engine '%s' were found in path '%s' when upgrading target '%s'", diff --git a/common/debug-channels.h b/common/debug-channels.h index 6f081c3118e..151c3242b9c 100644 --- a/common/debug-channels.h +++ b/common/debug-channels.h @@ -85,9 +85,15 @@ public: bool addDebugChannel(uint32 channel, const String &name, const String &description); /** - * Reset all engine-specific debug channels. + * Add all the debug channels for an engine. This replaces any existing engine + * debug channels and disables all channels. */ - void clearAllDebugChannels(); + void addAllDebugChannels(const DebugChannelDef *channels); + + /** + * Remove all engine debug channels and disable all global debug channels. + */ + void removeAllDebugChannels(); /** * Enable a debug channel. @@ -124,11 +130,12 @@ public: typedef List DebugChannelList; /** - * Lists all engine specific debug channels. + * Lists all debug channels. This includes engine and global + * debug channels. * - * @return returns an array with all debug channels + * @return List of all debug channels sorted by debug level. */ - DebugChannelList listDebugChannels(); + DebugChannelList getDebugChannels(); /** * Enable all debug channels. @@ -145,11 +152,6 @@ public: */ bool isDebugChannelEnabled(uint32 channel, bool enforce = false); - /** - * register engine specified flags - */ - void debugFlagsRegister(const DebugChannelDef *channels); - private: typedef HashMap DebugChannelMap; @@ -160,6 +162,9 @@ private: DebugManager(); + /** + * Internal method for adding an array of debug channels. + */ void addDebugChannels(const DebugChannelDef *channels); }; diff --git a/common/debug.cpp b/common/debug.cpp index c11684377f6..132fd949eb2 100644 --- a/common/debug.cpp +++ b/common/debug.cpp @@ -69,7 +69,15 @@ bool DebugManager::addDebugChannel(uint32 channel, const String &name, const Str return true; } -void DebugManager::clearAllDebugChannels() { +void DebugManager::addAllDebugChannels(const DebugChannelDef *channels) { + removeAllDebugChannels(); + + if (channels) { + addDebugChannels(channels); + } +} + +void DebugManager::removeAllDebugChannels() { _debugChannelsEnabled = 0; _debugChannels.clear(); addDebugChannels(gDebugChannels); @@ -111,7 +119,7 @@ bool DebugManager::disableDebugChannel(uint32 channel) { return true; } -DebugManager::DebugChannelList DebugManager::listDebugChannels() { +DebugManager::DebugChannelList DebugManager::getDebugChannels() { DebugChannelList tmp; for (DebugChannelMap::iterator i = _debugChannels.begin(); i != _debugChannels.end(); ++i) tmp.push_back(i->_value); @@ -138,14 +146,6 @@ bool DebugManager::isDebugChannelEnabled(uint32 channel, bool enforce) { return (_debugChannelsEnabled & channel) != 0; } -void DebugManager::debugFlagsRegister(const DebugChannelDef *channels) { - clearAllDebugChannels(); - - if (channels) { - addDebugChannels(channels); - } -} - void DebugManager::addDebugChannels(const DebugChannelDef *channels) { for (uint i = 0; channels[i].channel != 0; ++i) { addDebugChannel(channels[i].channel, channels[i].name, channels[i].description); diff --git a/engines/scumm/debugger.cpp b/engines/scumm/debugger.cpp index 48c5017bfc8..1a16a4cc6d3 100644 --- a/engines/scumm/debugger.cpp +++ b/engines/scumm/debugger.cpp @@ -507,7 +507,7 @@ bool ScummDebugger::Cmd_Object(int argc, const char **argv) { } bool ScummDebugger::Cmd_Debug(int argc, const char **argv) { - const Common::DebugManager::DebugChannelList &lvls = DebugMan.listDebugChannels(); + const Common::DebugManager::DebugChannelList &lvls = DebugMan.getDebugChannels(); // No parameters given: Print out a list of all channels and their status if (argc <= 1) { diff --git a/gui/debugger.cpp b/gui/debugger.cpp index a06ca186e2a..b9f8906ab2f 100644 --- a/gui/debugger.cpp +++ b/gui/debugger.cpp @@ -733,7 +733,7 @@ bool Debugger::cmdDebugLevel(int argc, const char **argv) { } bool Debugger::cmdDebugFlagsList(int argc, const char **argv) { - const Common::DebugManager::DebugChannelList &debugLevels = DebugMan.listDebugChannels(); + const Common::DebugManager::DebugChannelList &debugLevels = DebugMan.getDebugChannels(); debugPrintf("Engine debug levels:\n"); debugPrintf("--------------------\n");