[Orxonox-commit 3848] r8524 - in code/branches/unity_build/src/libraries: core core/command util
rgrieder at orxonox.net
rgrieder at orxonox.net
Sat May 21 04:23:20 CEST 2011
Author: rgrieder
Date: 2011-05-21 04:23:19 +0200 (Sat, 21 May 2011)
New Revision: 8524
Modified:
code/branches/unity_build/src/libraries/core/ConfigValueIncludes.h
code/branches/unity_build/src/libraries/core/Core.cc
code/branches/unity_build/src/libraries/core/Core.h
code/branches/unity_build/src/libraries/core/command/Shell.cc
code/branches/unity_build/src/libraries/core/command/Shell.h
code/branches/unity_build/src/libraries/util/OutputHandler.h
Log:
Fixed a serious problem with the debug levels for the Shells by introducing DevModeListener and moving the debug levels to the Shell again..
Modified: code/branches/unity_build/src/libraries/core/ConfigValueIncludes.h
===================================================================
--- code/branches/unity_build/src/libraries/core/ConfigValueIncludes.h 2011-05-20 21:32:34 UTC (rev 8523)
+++ code/branches/unity_build/src/libraries/core/ConfigValueIncludes.h 2011-05-21 02:23:19 UTC (rev 8524)
@@ -254,4 +254,19 @@
#define ModifyConfigValue(varname, modifier, ...) \
ModifyConfigValueGeneric(this, &varname, #varname, modifier, __VA_ARGS__)
+/** Modifies a runtime configurable value by using a modifier and some arguments.
+ If the container for the value doesn't yet exist, a warning is displayed.
+ Also, the @a variable argument will be modified and set to the current value.
+ at param variable
+ Pointer to the variable where the value should be written to
+ at param entryName
+ Name of the entry in the ini file (e.g. [MySection] myValue)
+ at param modifier
+ On of these functions: set, tset, add, remove, reset, update
+ at param ...
+ Arguments for the modifier function
+*/
+#define ModifyConfigValueExternal(variable, entryName, modifier, ...) \
+ ModifyConfigValueGeneric(this, &variable, entryName, modifier, __VA_ARGS__)
+
#endif /* _ConfigValueIncludes_H__ */
Modified: code/branches/unity_build/src/libraries/core/Core.cc
===================================================================
--- code/branches/unity_build/src/libraries/core/Core.cc 2011-05-20 21:32:34 UTC (rev 8523)
+++ code/branches/unity_build/src/libraries/core/Core.cc 2011-05-21 02:23:19 UTC (rev 8524)
@@ -68,6 +68,7 @@
#include "Identifier.h"
#include "Language.h"
#include "LuaState.h"
+#include "ObjectList.h"
#include "command/ConsoleCommand.h"
#include "command/IOConsole.h"
#include "command/TclBind.h"
@@ -228,40 +229,22 @@
safeObjectDelete(&pathConfig_);
}
- namespace DefaultLogLevels
+ namespace DefaultLevelLogFile
{
- struct List
- {
- OutputLevel::Value logFile;
- OutputLevel::Value ioConsole;
- OutputLevel::Value inGameConsole;
- };
-
- using namespace OutputLevel;
- static const List Dev = { Debug, Info, Info };
- static const List User = { Info, Error, Error };
+ const OutputLevel::Value Dev = OutputLevel::Debug;
+ const OutputLevel::Value User = OutputLevel::Info;
}
//! Function to collect the SetConfigValue-macro calls.
void Core::setConfigValues()
{
- // Choose the default levels according to the path Orxonox was started (build directory or not)
- DefaultLogLevels::List defaultLogLevels = (PathConfig::buildDirectoryRun() ? DefaultLogLevels::Dev : DefaultLogLevels::User);
+ // Choose the default level according to the path Orxonox was started (build directory or not)
+ OutputLevel::Value defaultLogLevel = (PathConfig::buildDirectoryRun() ? DefaultLevelLogFile::Dev : DefaultLevelLogFile::User);
- SetConfigValueExternal(debugLevelLogFile_, "OutputHandler", "debugLevelLogFile_", defaultLogLevels.logFile)
+ SetConfigValueExternal(debugLevelLogFile_, "OutputHandler", "debugLevelLogFile", defaultLogLevel)
.description("The maximum level of debug output written to the log file");
OutputHandler::getInstance().setSoftDebugLevel("LogFile", debugLevelLogFile_);
- SetConfigValueExternal(debugLevelIOConsole_, "OutputHandler", "debugLevelIOConsole_", defaultLogLevels.ioConsole)
- .description("The maximum level of debug output shown in the IO console");
- OutputHandler::getInstance().setSoftDebugLevel("IOConsole", debugLevelIOConsole_);
- // In case we don't start the IOConsole, also configure that simple listener
- OutputHandler::getInstance().setSoftDebugLevel("Console", debugLevelIOConsole_);
-
- SetConfigValueExternal(debugLevelIOConsole_, "OutputHandler", "debugLevelInGameConsole_", defaultLogLevels.inGameConsole)
- .description("The maximum level of debug output shown in the in-game console");
- OutputHandler::getInstance().setSoftDebugLevel("InGameConsole", debugLevelInGameConsole_);
-
SetConfigValue(bDevMode_, PathConfig::buildDirectoryRun())
.description("Developer mode. If not set, hides some things from the user to not confuse him.")
.callback(this, &Core::devModeChanged);
@@ -289,23 +272,27 @@
- Changing the development mode from 'normal' to the other state will
immediately change the debug levels to predefined values which can be
reconfigured with \c tconfig.
+ @note
+ The debug levels for the IOConsole and the InGameConsole can be found
+ in the Shell class. The same rules apply.
*/
void Core::devModeChanged()
{
bool isNormal = (bDevMode_ == PathConfig::buildDirectoryRun());
if (isNormal)
{
- ModifyConfigValue(debugLevelLogFile_, update);
- ModifyConfigValue(debugLevelIOConsole_, update);
- ModifyConfigValue(debugLevelInGameConsole_, update);
+ ModifyConfigValueExternal(debugLevelLogFile_, "debugLevelLogFile", update);
}
else
{
- DefaultLogLevels::List levels = (bDevMode_ ? DefaultLogLevels::Dev : DefaultLogLevels::User);
- ModifyConfigValue(debugLevelLogFile_, tset, levels.logFile);
- ModifyConfigValue(debugLevelIOConsole_, tset, levels.ioConsole);
- ModifyConfigValue(debugLevelInGameConsole_, tset, levels.inGameConsole);
+ OutputLevel::Value level = (bDevMode_ ? DefaultLevelLogFile::Dev : DefaultLevelLogFile::User);
+ ModifyConfigValueExternal(debugLevelLogFile_, "debugLevelLogFile", tset, level);
}
+
+ // Inform listeners
+ ObjectList<DevModeListener>::iterator it = ObjectList<DevModeListener>::begin();
+ for (; it != ObjectList<DevModeListener>::end(); ++it)
+ it->devModeChanged(bDevMode_);
}
//! Callback function if the language has changed.
@@ -490,4 +477,10 @@
{
ModifyConfigValue(ogreConfigTimestamp_, set, static_cast<long long>(time(NULL)));
}
+
+
+ DevModeListener::DevModeListener()
+ {
+ RegisterRootObject(DevModeListener);
+ }
}
Modified: code/branches/unity_build/src/libraries/core/Core.h
===================================================================
--- code/branches/unity_build/src/libraries/core/Core.h 2011-05-20 21:32:34 UTC (rev 8523)
+++ code/branches/unity_build/src/libraries/core/Core.h 2011-05-21 02:23:19 UTC (rev 8524)
@@ -52,6 +52,15 @@
namespace orxonox
{
+ //! Informs about changes in the Development Mode.
+ class DevModeListener : virtual public OrxonoxClass
+ {
+ public:
+ DevModeListener();
+ virtual ~DevModeListener() {}
+ virtual void devModeChanged(bool value) = 0;
+ };
+
/**
@brief
The Core class is a singleton used to configure the program basics.
@@ -129,8 +138,6 @@
bool bGraphicsLoaded_;
int debugLevelLogFile_; //!< The debug level for the log file (belongs to OutputHandler)
- int debugLevelIOConsole_; //!< The debug level for the IO console (belongs to OutputHandler)
- int debugLevelInGameConsole_; //!< The debug level for the in game console (belongs to OutputHandler)
std::string language_; //!< The language
bool bInitRandomNumberGenerator_; //!< If true, srand(time(0)) is called
bool bStartIOConsole_; //!< Set to false if you don't want to use the IOConsole
Modified: code/branches/unity_build/src/libraries/core/command/Shell.cc
===================================================================
--- code/branches/unity_build/src/libraries/core/command/Shell.cc 2011-05-20 21:32:34 UTC (rev 8523)
+++ code/branches/unity_build/src/libraries/core/command/Shell.cc 2011-05-21 02:23:19 UTC (rev 8524)
@@ -39,6 +39,7 @@
#include "core/CoreIncludes.h"
#include "core/ConfigFileManager.h"
#include "core/ConfigValueIncludes.h"
+#include "core/PathConfig.h"
#include "CommandExecutor.h"
#include "ConsoleCommand.h"
@@ -86,7 +87,7 @@
OutputHandler::OutputVector::const_iterator it = OutputHandler::getInstance().getOutput().begin();
for (;it != OutputHandler::getInstance().getOutput().end(); ++it)
{
- if (it->first <= this->getSoftDebugLevel())
+ if (it->first <= debugLevel_)
{
this->outputBuffer_ << it->second;
this->outputChanged(it->first);
@@ -95,6 +96,7 @@
// Register the shell as output listener
OutputHandler::getInstance().registerOutputListener(this);
+ OutputHandler::getInstance().setSoftDebugLevel(consoleName_, debugLevel_);
}
/**
@@ -106,6 +108,12 @@
this->inputBuffer_->destroy();
}
+ namespace DefaultLogLevel
+ {
+ const OutputLevel::Value Dev = OutputLevel::Info;
+ const OutputLevel::Value User = OutputLevel::Error;
+ }
+
/**
@brief Defines the config values.
*/
@@ -117,6 +125,12 @@
.callback(this, &Shell::commandHistoryOffsetChanged);
setConfigValueGeneric(this, &commandHistory_, ConfigFileType::CommandHistory, "Shell", "commandHistory_", std::vector<std::string>());
SetConfigValue(cacheSize_s, 32);
+
+ // Choose the default level according to the path Orxonox was started (build directory or not)
+ OutputLevel::Value defaultDebugLevel = (PathConfig::buildDirectoryRun() ? DefaultLogLevel::Dev : DefaultLogLevel::User);
+ SetConfigValueExternal(debugLevel_, "OutputHandler", "debugLevel" + consoleName_, defaultDebugLevel)
+ .description("The maximum level of debug output shown in the " + consoleName_);
+ OutputHandler::getInstance().setSoftDebugLevel(consoleName_, debugLevel_);
}
/**
@@ -143,6 +157,23 @@
}
}
+ /** Called upon changes in the development mode (by Core)
+ Behaviour details see Core::devModeChanged.
+ */
+ void Shell::devModeChanged(bool value)
+ {
+ bool isNormal = (value == PathConfig::buildDirectoryRun());
+ if (isNormal)
+ {
+ ModifyConfigValueExternal(debugLevel_, "debugLevel" + consoleName_, update);
+ }
+ else
+ {
+ OutputLevel::Value level = (value ? DefaultLogLevel::Dev : DefaultLogLevel::User);
+ ModifyConfigValueExternal(debugLevel_, "debugLevel" + consoleName_, tset, level);
+ }
+ }
+
/**
@brief Registers this object as listener for different key-events at the input buffer.
*/
Modified: code/branches/unity_build/src/libraries/core/command/Shell.h
===================================================================
--- code/branches/unity_build/src/libraries/core/command/Shell.h 2011-05-20 21:32:34 UTC (rev 8523)
+++ code/branches/unity_build/src/libraries/core/command/Shell.h 2011-05-21 02:23:19 UTC (rev 8524)
@@ -48,6 +48,7 @@
#include <vector>
#include "util/OutputHandler.h"
+#include "core/Core.h"
#include "core/OrxonoxClass.h"
#include "core/input/InputBuffer.h"
@@ -84,7 +85,7 @@
Different graphical consoles build upon a Shell, for example InGameConsole and IOConsole.
*/
- class _CoreExport Shell : virtual public OrxonoxClass, public OutputListener
+ class _CoreExport Shell : virtual public OrxonoxClass, public OutputListener, public DevModeListener
{
public:
/// Defines the type of a line of text in the Shell - some types depend on the output level, others are of internal use.
@@ -147,6 +148,9 @@
private:
Shell(const Shell& other);
+ // DevModeListener
+ void devModeChanged(bool value);
+
void addToHistory(const std::string& command);
const std::string& getFromHistory() const;
void clearInput();
@@ -197,6 +201,7 @@
unsigned int maxHistoryLength_; ///< The maximum number of saved commands
unsigned int historyOffset_; ///< The command history is a circular buffer, this variable defines the current write-offset
std::vector<std::string> commandHistory_; ///< The history of commands that were entered by the user
+ int debugLevel_; //!< The maximum level of output that is displayed in the shell (will be passed to OutputListener to filter output)
static unsigned int cacheSize_s; ///< The maximum cache size of the CommandExecutor - this is stored here for better readability of the config file and because CommandExecutor is no OrxonoxClass
};
}
Modified: code/branches/unity_build/src/libraries/util/OutputHandler.h
===================================================================
--- code/branches/unity_build/src/libraries/util/OutputHandler.h 2011-05-20 21:32:34 UTC (rev 8523)
+++ code/branches/unity_build/src/libraries/util/OutputHandler.h 2011-05-21 02:23:19 UTC (rev 8524)
@@ -255,8 +255,6 @@
virtual void outputChanged(int level) {}
//! Returns the name of this output listener
const std::string& getOutputListenerName() const { return this->name_; }
- //! Returns the soft debug level of the listener
- int getSoftDebugLevel() const { return this->softDebugLevel_; }
protected:
std::ostream* outputStream_; //!< Pointer to the associated output stream, can be NULL
More information about the Orxonox-commit
mailing list