Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8524


Ignore:
Timestamp:
May 21, 2011, 4:23:19 AM (14 years ago)
Author:
rgrieder
Message:

Fixed a serious problem with the debug levels for the Shells by introducing DevModeListener and moving the debug levels to the Shell again..

Location:
code/branches/unity_build/src/libraries
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/branches/unity_build/src/libraries/core/ConfigValueIncludes.h

    r7401 r8524  
    255255    ModifyConfigValueGeneric(this, &varname, #varname, modifier, __VA_ARGS__)
    256256
     257/** Modifies a runtime configurable value by using a modifier and some arguments.
     258    If the container for the value doesn't yet exist, a warning is displayed.
     259    Also, the @a variable argument will be modified and set to the current value.
     260@param variable
     261    Pointer to the variable where the value should be written to
     262@param entryName
     263    Name of the entry in the ini file (e.g. [MySection] myValue)
     264@param modifier
     265    On of these functions: set, tset, add, remove, reset, update
     266@param ...
     267    Arguments for the modifier function
     268*/
     269#define ModifyConfigValueExternal(variable, entryName, modifier, ...) \
     270    ModifyConfigValueGeneric(this, &variable, entryName, modifier, __VA_ARGS__)
     271
    257272#endif /* _ConfigValueIncludes_H__ */
  • code/branches/unity_build/src/libraries/core/Core.cc

    r8520 r8524  
    6969#include "Language.h"
    7070#include "LuaState.h"
     71#include "ObjectList.h"
    7172#include "command/ConsoleCommand.h"
    7273#include "command/IOConsole.h"
     
    229230    }
    230231
    231     namespace DefaultLogLevels
    232     {
    233         struct List
    234         {
    235             OutputLevel::Value logFile;
    236             OutputLevel::Value ioConsole;
    237             OutputLevel::Value inGameConsole;
    238         };
    239 
    240         using namespace OutputLevel;
    241         static const List Dev  = { Debug, Info,  Info  };
    242         static const List User = { Info,  Error, Error };
     232    namespace DefaultLevelLogFile
     233    {
     234        const OutputLevel::Value Dev  = OutputLevel::Debug;
     235        const OutputLevel::Value User = OutputLevel::Info;
    243236    }
    244237
     
    246239    void Core::setConfigValues()
    247240    {
    248         // Choose the default levels according to the path Orxonox was started (build directory or not)
    249         DefaultLogLevels::List defaultLogLevels = (PathConfig::buildDirectoryRun() ? DefaultLogLevels::Dev : DefaultLogLevels::User);
    250 
    251         SetConfigValueExternal(debugLevelLogFile_, "OutputHandler", "debugLevelLogFile_", defaultLogLevels.logFile)
     241        // Choose the default level according to the path Orxonox was started (build directory or not)
     242        OutputLevel::Value defaultLogLevel = (PathConfig::buildDirectoryRun() ? DefaultLevelLogFile::Dev : DefaultLevelLogFile::User);
     243
     244        SetConfigValueExternal(debugLevelLogFile_, "OutputHandler", "debugLevelLogFile", defaultLogLevel)
    252245            .description("The maximum level of debug output written to the log file");
    253246        OutputHandler::getInstance().setSoftDebugLevel("LogFile", debugLevelLogFile_);
    254 
    255         SetConfigValueExternal(debugLevelIOConsole_, "OutputHandler", "debugLevelIOConsole_", defaultLogLevels.ioConsole)
    256             .description("The maximum level of debug output shown in the IO console");
    257         OutputHandler::getInstance().setSoftDebugLevel("IOConsole", debugLevelIOConsole_);
    258         // In case we don't start the IOConsole, also configure that simple listener
    259         OutputHandler::getInstance().setSoftDebugLevel("Console", debugLevelIOConsole_);
    260 
    261         SetConfigValueExternal(debugLevelIOConsole_, "OutputHandler", "debugLevelInGameConsole_", defaultLogLevels.inGameConsole)
    262             .description("The maximum level of debug output shown in the in-game console");
    263         OutputHandler::getInstance().setSoftDebugLevel("InGameConsole", debugLevelInGameConsole_);
    264247
    265248        SetConfigValue(bDevMode_, PathConfig::buildDirectoryRun())
     
    290273          immediately change the debug levels to predefined values which can be
    291274          reconfigured with \c tconfig.
     275    @note
     276        The debug levels for the IOConsole and the InGameConsole can be found
     277        in the Shell class. The same rules apply.
    292278    */
    293279    void Core::devModeChanged()
     
    296282        if (isNormal)
    297283        {
    298             ModifyConfigValue(debugLevelLogFile_,       update);
    299             ModifyConfigValue(debugLevelIOConsole_,     update);
    300             ModifyConfigValue(debugLevelInGameConsole_, update);
     284            ModifyConfigValueExternal(debugLevelLogFile_, "debugLevelLogFile", update);
    301285        }
    302286        else
    303287        {
    304             DefaultLogLevels::List levels = (bDevMode_ ? DefaultLogLevels::Dev : DefaultLogLevels::User);
    305             ModifyConfigValue(debugLevelLogFile_,       tset, levels.logFile);
    306             ModifyConfigValue(debugLevelIOConsole_,     tset, levels.ioConsole);
    307             ModifyConfigValue(debugLevelInGameConsole_, tset, levels.inGameConsole);
    308         }
     288            OutputLevel::Value level = (bDevMode_ ? DefaultLevelLogFile::Dev : DefaultLevelLogFile::User);
     289            ModifyConfigValueExternal(debugLevelLogFile_, "debugLevelLogFile", tset, level);
     290        }
     291
     292        // Inform listeners
     293        ObjectList<DevModeListener>::iterator it = ObjectList<DevModeListener>::begin();
     294        for (; it != ObjectList<DevModeListener>::end(); ++it)
     295            it->devModeChanged(bDevMode_);
    309296    }
    310297
     
    491478        ModifyConfigValue(ogreConfigTimestamp_, set, static_cast<long long>(time(NULL)));
    492479    }
     480
     481
     482    DevModeListener::DevModeListener()
     483    {
     484        RegisterRootObject(DevModeListener);
     485    }
    493486}
  • code/branches/unity_build/src/libraries/core/Core.h

    r8519 r8524  
    5353namespace orxonox
    5454{
     55    //! Informs about changes in the Development Mode.
     56    class DevModeListener : virtual public OrxonoxClass
     57    {
     58    public:
     59        DevModeListener();
     60        virtual ~DevModeListener() {}
     61        virtual void devModeChanged(bool value) = 0;
     62    };
     63
    5564    /**
    5665    @brief
     
    130139            bool                      bGraphicsLoaded_;
    131140            int                       debugLevelLogFile_;          //!< The debug level for the log file (belongs to OutputHandler)
    132             int                       debugLevelIOConsole_;        //!< The debug level for the IO console (belongs to OutputHandler)
    133             int                       debugLevelInGameConsole_;    //!< The debug level for the in game console (belongs to OutputHandler)
    134141            std::string               language_;                   //!< The language
    135142            bool                      bInitRandomNumberGenerator_; //!< If true, srand(time(0)) is called
  • code/branches/unity_build/src/libraries/core/command/Shell.cc

    r8518 r8524  
    4040#include "core/ConfigFileManager.h"
    4141#include "core/ConfigValueIncludes.h"
     42#include "core/PathConfig.h"
    4243#include "CommandExecutor.h"
    4344#include "ConsoleCommand.h"
     
    8788        for (;it != OutputHandler::getInstance().getOutput().end(); ++it)
    8889        {
    89             if (it->first <= this->getSoftDebugLevel())
     90            if (it->first <= debugLevel_)
    9091            {
    9192                this->outputBuffer_ << it->second;
     
    9697        // Register the shell as output listener
    9798        OutputHandler::getInstance().registerOutputListener(this);
     99        OutputHandler::getInstance().setSoftDebugLevel(consoleName_, debugLevel_);
    98100    }
    99101
     
    105107        OutputHandler::getInstance().unregisterOutputListener(this);
    106108        this->inputBuffer_->destroy();
     109    }
     110
     111    namespace DefaultLogLevel
     112    {
     113        const OutputLevel::Value Dev  = OutputLevel::Info;
     114        const OutputLevel::Value User = OutputLevel::Error;
    107115    }
    108116
     
    118126        setConfigValueGeneric(this, &commandHistory_, ConfigFileType::CommandHistory, "Shell", "commandHistory_", std::vector<std::string>());
    119127        SetConfigValue(cacheSize_s, 32);
     128
     129        // Choose the default level according to the path Orxonox was started (build directory or not)
     130        OutputLevel::Value defaultDebugLevel = (PathConfig::buildDirectoryRun() ? DefaultLogLevel::Dev : DefaultLogLevel::User);
     131        SetConfigValueExternal(debugLevel_, "OutputHandler", "debugLevel" + consoleName_, defaultDebugLevel)
     132            .description("The maximum level of debug output shown in the " + consoleName_);
     133        OutputHandler::getInstance().setSoftDebugLevel(consoleName_, debugLevel_);
    120134    }
    121135
     
    141155            this->commandHistory_.erase(this->commandHistory_.begin() + index);
    142156            ModifyConfigValue(commandHistory_, remove, index);
     157        }
     158    }
     159
     160    /** Called upon changes in the development mode (by Core)
     161        Behaviour details see Core::devModeChanged.
     162    */
     163    void Shell::devModeChanged(bool value)
     164    {
     165        bool isNormal = (value == PathConfig::buildDirectoryRun());
     166        if (isNormal)
     167        {
     168            ModifyConfigValueExternal(debugLevel_, "debugLevel" + consoleName_, update);
     169        }
     170        else
     171        {
     172            OutputLevel::Value level = (value ? DefaultLogLevel::Dev : DefaultLogLevel::User);
     173            ModifyConfigValueExternal(debugLevel_, "debugLevel" + consoleName_, tset, level);
    143174        }
    144175    }
  • code/branches/unity_build/src/libraries/core/command/Shell.h

    r8522 r8524  
    4949
    5050#include "util/OutputHandler.h"
     51#include "core/Core.h"
    5152#include "core/OrxonoxClass.h"
    5253#include "core/input/InputBuffer.h"
     
    8586        Different graphical consoles build upon a Shell, for example InGameConsole and IOConsole.
    8687    */
    87     class _CoreExport Shell : virtual public OrxonoxClass, public OutputListener
     88    class _CoreExport Shell : virtual public OrxonoxClass, public OutputListener, public DevModeListener
    8889    {
    8990        public:
     
    148149            Shell(const Shell& other);
    149150
     151            // DevModeListener
     152            void devModeChanged(bool value);
     153
    150154            void addToHistory(const std::string& command);
    151155            const std::string& getFromHistory() const;
     
    198202            unsigned int              historyOffset_;       ///< The command history is a circular buffer, this variable defines the current write-offset
    199203            std::vector<std::string>  commandHistory_;      ///< The history of commands that were entered by the user
     204            int                       debugLevel_;          //!< The maximum level of output that is displayed in the shell (will be passed to OutputListener to filter output)
    200205            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
    201206    };
  • code/branches/unity_build/src/libraries/util/OutputHandler.h

    r8522 r8524  
    256256        //! Returns the name of this output listener
    257257        const std::string& getOutputListenerName() const { return this->name_; }
    258         //! Returns the soft debug level of the listener
    259         int getSoftDebugLevel() const { return this->softDebugLevel_; }
    260258
    261259    protected:
Note: See TracChangeset for help on using the changeset viewer.