Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8799


Ignore:
Timestamp:
Jul 30, 2011, 7:51:08 PM (13 years ago)
Author:
landauf
Message:

Code related to config values for output is now implemented in BaseWriter.
There's a config value for the normal output level, a vector with additional contexts, and a config value for the level of these additional contexts.
ioconsole and standard console use the same values.

Location:
code/branches/output/src/libraries
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • code/branches/output/src/libraries/core/Core.cc

    r8796 r8799  
    5050#  undef max
    5151#endif
    52 
    53 #include <boost/preprocessor/stringize.hpp>
    5452
    5553#include "util/Clock.h"
     
    231229    }
    232230
    233     namespace DefaultLevelLogFile
    234     {
    235 #pragma message(__FILE__ "("BOOST_PP_STRINGIZE(__LINE__)") : Warning: TODO: inspect this (and remove boost include)")
    236         const OutputLevel Dev  = level::internal_info;
    237         const OutputLevel User = level::internal_info;
    238     }
    239 
    240231    //! Function to collect the SetConfigValue-macro calls.
    241232    void Core::setConfigValues()
    242233    {
    243         // Choose the default level according to the path Orxonox was started (build directory or not)
    244         OutputLevel defaultLogLevel = (PathConfig::buildDirectoryRun() ? DefaultLevelLogFile::Dev : DefaultLevelLogFile::User);
    245 
    246         SetConfigValueExternal(debugLevelLogFile_, "OutputHandler", "debugLevelLogFile", defaultLogLevel)
    247             .description("The maximum level of debug output written to the log file");
    248         LogWriter::getInstance().setLevelMax(this->debugLevelLogFile_);
     234        SetConfigValueExternal(LogWriter::getInstance().configurableMaxLevel_,
     235                               LogWriter::getInstance().getConfigurableSectionName(),
     236                               LogWriter::getInstance().getConfigurableMaxLevelName(),
     237                               LogWriter::getInstance().configurableMaxLevel_)
     238            .description("The maximum level of output shown in the log file")
     239            .callback(static_cast<BaseWriter*>(&LogWriter::getInstance()), &BaseWriter::changedConfigurableLevels);
     240        SetConfigValueExternal(LogWriter::getInstance().configurableContextsMaxLevel_,
     241                               LogWriter::getInstance().getConfigurableSectionName(),
     242                               LogWriter::getInstance().getConfigurableContextsMaxLevelName(),
     243                               LogWriter::getInstance().configurableContextsMaxLevel_)
     244            .description("The maximum level of output shown in the log file for additional contexts")
     245            .callback(static_cast<BaseWriter*>(&LogWriter::getInstance()), &BaseWriter::changedConfigurableLevels);
     246        SetConfigValueExternal(LogWriter::getInstance().configurableContexts_,
     247                               LogWriter::getInstance().getConfigurableSectionName(),
     248                               LogWriter::getInstance().getConfigurableContextsName(),
     249                               LogWriter::getInstance().configurableContexts_)
     250            .description("Additional output contexts shown in the log file")
     251            .callback(static_cast<BaseWriter*>(&LogWriter::getInstance()), &BaseWriter::changedConfigurableContexts);
    249252
    250253        SetConfigValue(bDevMode_, PathConfig::buildDirectoryRun())
     
    281284    void Core::devModeChanged()
    282285    {
    283         bool isNormal = (bDevMode_ == PathConfig::buildDirectoryRun());
    284         if (isNormal)
    285         {
    286             ModifyConfigValueExternal(debugLevelLogFile_, "debugLevelLogFile", update);
    287         }
    288         else
    289         {
    290             OutputLevel level = (bDevMode_ ? DefaultLevelLogFile::Dev : DefaultLevelLogFile::User);
    291             ModifyConfigValueExternal(debugLevelLogFile_, "debugLevelLogFile", tset, level);
    292         }
    293 
    294286        // Inform listeners
    295287        ObjectList<DevModeListener>::iterator it = ObjectList<DevModeListener>::begin();
  • code/branches/output/src/libraries/core/Core.h

    r8796 r8799  
    136136
    137137            bool                      bGraphicsLoaded_;
    138             OutputLevel               debugLevelLogFile_;          //!< The debug level for the log file (belongs to LogWriter)
    139138            std::string               language_;                   //!< The language
    140139            bool                      bInitRandomNumberGenerator_; //!< If true, srand(time(0)) is called
  • code/branches/output/src/libraries/core/GUIManager.cc

    r8798 r8799  
    7777#include "util/Math.h"
    7878#include "util/OrxAssert.h"
     79#include "util/output/BaseWriter.h"
    7980#include "ConfigValueIncludes.h"
    8081#include "Core.h"
     
    368369        SetConfigValue(guiScheme_, GUIManager::defaultScheme_).description("Changes the current GUI scheme.").callback(this, &GUIManager::changedGUIScheme);
    369370        SetConfigValue(numScrollLines_, 1).description("How many lines to scroll in a list if the scroll wheel is used");
    370         SetConfigValueExternal(outputLevelCeguiLog_, "OutputHandler", "outputLevelCeguiLog", CEGUI::Standard).description("The log level of the CEGUI log file").callback(this, &GUIManager::changedCeguiOutputLevel);
     371        SetConfigValueExternal(outputLevelCeguiLog_, BaseWriter::getConfigurableSectionName(), "outputLevelCeguiLog", CEGUI::Standard).description("The log level of the CEGUI log file").callback(this, &GUIManager::changedCeguiOutputLevel);
    371372    }
    372373
  • code/branches/output/src/libraries/core/command/IOConsolePOSIX.cc

    r8797 r8799  
    5656
    5757    IOConsole::IOConsole()
    58         : shell_(new Shell("IOConsole", false))
     58        : shell_(new Shell("Console", false))
    5959        , buffer_(shell_->getInputBuffer())
    6060        , cout_(std::cout.rdbuf())
  • code/branches/output/src/libraries/core/command/IOConsoleWindows.cc

    r8797 r8799  
    4444    //! Redirects std::cout, creates the corresponding Shell and changes the terminal mode
    4545    IOConsole::IOConsole()
    46         : shell_(new Shell("IOConsole", false))
     46        : shell_(new Shell("Console", false))
    4747        , buffer_(shell_->getInputBuffer())
    4848        , cout_(std::cout.rdbuf())
  • code/branches/output/src/libraries/core/command/Shell.cc

    r8795 r8799  
    5656    unsigned int Shell::cacheSize_s;
    5757
     58    namespace DefaultLogLevel
     59    {
     60        const OutputLevel Dev  = level::internal_warning;
     61        const OutputLevel User = level::user_info;
     62    }
     63
    5864    /**
    5965        @brief Constructor: Initializes the values.
     
    6268    */
    6369    Shell::Shell(const std::string& consoleName, bool bScrollable)
    64         : inputBuffer_(new InputBuffer())
    65         , consoleName_(consoleName)
     70        : BaseWriter(consoleName)
     71        , inputBuffer_(new InputBuffer())
    6672        , bScrollable_(bScrollable)
    6773    {
     
    7985        ConfigFileManager::getInstance().setFilename(ConfigFileType::CommandHistory, "commandHistory.ini");
    8086
     87        // Choose the default level according to the path Orxonox was started (build directory or not)
     88        OutputLevel defaultDebugLevel = (PathConfig::buildDirectoryRun() ? DefaultLogLevel::Dev : DefaultLogLevel::User);
     89        this->setLevelMax(defaultDebugLevel);
     90
    8191        this->setConfigValues();
    8292
     
    91101    {
    92102        this->inputBuffer_->destroy();
    93     }
    94 
    95     namespace DefaultLogLevel
    96     {
    97         const OutputLevel Dev  = level::internal_warning;
    98         const OutputLevel User = level::user_info;
    99103    }
    100104
     
    111115        SetConfigValue(cacheSize_s, 32);
    112116
    113         // Choose the default level according to the path Orxonox was started (build directory or not)
    114         OutputLevel defaultDebugLevel = (PathConfig::buildDirectoryRun() ? DefaultLogLevel::Dev : DefaultLogLevel::User);
    115         SetConfigValueExternal(debugLevel_, "OutputHandler", "debugLevel" + consoleName_, defaultDebugLevel)
    116             .description("The maximum level of debug output shown in the " + consoleName_);
    117         this->setLevelMax(this->debugLevel_);
     117        SetConfigValueExternal(this->configurableMaxLevel_,
     118                               this->getConfigurableSectionName(),
     119                               this->getConfigurableMaxLevelName(),
     120                               this->configurableMaxLevel_)
     121            .description("The maximum level of output shown in the " + this->getName())
     122            .callback(static_cast<BaseWriter*>(this), &BaseWriter::changedConfigurableLevels);
     123        SetConfigValueExternal(this->configurableContextsMaxLevel_,
     124                               this->getConfigurableSectionName(),
     125                               this->getConfigurableContextsMaxLevelName(),
     126                               this->configurableContextsMaxLevel_)
     127            .description("The maximum level of output shown in the " + this->getName() + " for additional contexts")
     128            .callback(static_cast<BaseWriter*>(this), &BaseWriter::changedConfigurableLevels);
     129        SetConfigValueExternal(this->configurableContexts_,
     130                               this->getConfigurableSectionName(),
     131                               this->getConfigurableContextsName(),
     132                               this->configurableContexts_)
     133            .description("Additional output contexts shown in the " + this->getName())
     134            .callback(static_cast<BaseWriter*>(this), &BaseWriter::changedConfigurableLevels);
    118135    }
    119136
     
    150167        if (isNormal)
    151168        {
    152             ModifyConfigValueExternal(debugLevel_, "debugLevel" + consoleName_, update);
     169            ModifyConfigValueExternal(debugLevel_, this->getConfigurableMaxLevelName(), update);
    153170        }
    154171        else
    155172        {
    156173            OutputLevel level = (value ? DefaultLogLevel::Dev : DefaultLogLevel::User);
    157             ModifyConfigValueExternal(debugLevel_, "debugLevel" + consoleName_, tset, level);
     174            ModifyConfigValueExternal(debugLevel_, this->getConfigurableMaxLevelName(), tset, level);
    158175        }
    159176    }
  • code/branches/output/src/libraries/core/command/Shell.h

    r8797 r8799  
    191191            unsigned int              scrollPosition_;      ///< The number of the line that is currently being referenced by scrollIterator_
    192192            unsigned int              historyPosition_;     ///< If the user scrolls through the history of entered commands (stored in commandHistory_), this contains the currently viewed history entry
    193 
    194             const std::string         consoleName_;         ///< The name of this shell - used to define the name of the soft-debug-level config-value
    195193            const bool                bScrollable_;         ///< If true, the user can scroll through the output-lines
    196194
  • code/branches/output/src/libraries/util/output/BaseWriter.cc

    r8795 r8799  
    3333namespace orxonox
    3434{
    35     BaseWriter::BaseWriter()
     35    BaseWriter::BaseWriter(const std::string& name)
    3636    {
     37        this->name_ = name;
     38
     39        this->configurableMaxLevel_ = level::none;
     40        this->configurableContextsMaxLevel_ = level::verbose;
    3741    }
    3842
     
    4347    void BaseWriter::output(OutputLevel level, OutputContext context, const std::vector<std::string>& lines)
    4448    {
    45         const std::string& prefix = OutputManager::getInstance().getDefaultPrefix(level, context);
    46         std::string blanks(prefix.length(), ' ');
     49        if (level <= this->configurableMaxLevel_ || (level <= this->configurableContextsMaxLevel_ && this->isAdditionalContext(context)))
     50        {
     51            const std::string& prefix = OutputManager::getInstance().getDefaultPrefix(level, context);
     52            std::string blanks(prefix.length(), ' ');
    4753
    48         for (size_t i = 0; i < lines.size(); ++i)
    49             this->printLine((i == 0 ? prefix : blanks) + lines[i], level);
     54            for (size_t i = 0; i < lines.size(); ++i)
     55                this->printLine((i == 0 ? prefix : blanks) + lines[i], level);
     56        }
     57    }
     58
     59    void BaseWriter::setLevelMax(OutputLevel max)
     60    {
     61        this->configurableMaxLevel_ = max;
     62        this->changedConfigurableLevels();
     63    }
     64
     65    void BaseWriter::changedConfigurableLevels()
     66    {
     67        OutputLevel max_level = std::max(this->configurableMaxLevel_, this->configurableContextsMaxLevel_);
     68        OutputListener::setLevelMax(max_level);
     69    }
     70
     71    void BaseWriter::changedConfigurableContexts()
     72    {
     73        this->configurableContextsSet_.clear();
     74        for (size_t i = 0; i < this->configurableContexts_.size(); ++i)
     75            this->configurableContextsSet_.insert(this->configurableContexts_[i]);
     76    }
     77
     78    bool BaseWriter::isAdditionalContext(OutputContext context) const
     79    {
     80        const std::string& name = OutputManager::getInstance().getContextName(context);
     81        std::set<std::string>::const_iterator it = this->configurableContextsSet_.find(name);
     82        return (it != this->configurableContextsSet_.end());
    5083    }
    5184}
  • code/branches/output/src/libraries/util/output/BaseWriter.h

    r8795 r8799  
    3131
    3232#include "util/UtilPrereqs.h"
     33
     34#include <set>
     35#include <vector>
     36
    3337#include "OutputListener.h"
    3438
     
    3842    {
    3943        public:
    40             BaseWriter();
     44            BaseWriter(const std::string& name);
    4145            virtual ~BaseWriter();
     46
     47            const std::string& getName() const
     48                { return this->name_; }
     49
     50            void setLevelMax(OutputLevel max);
     51
     52            OutputLevel configurableMaxLevel_;
     53            inline std::string getConfigurableMaxLevelName() const
     54                { return "outputLevel" + this->name_; }
     55
     56            OutputLevel configurableContextsMaxLevel_;
     57            inline std::string getConfigurableContextsMaxLevelName() const
     58                { return "outputContextsLevel" + this->name_; }
     59
     60            std::vector<std::string> configurableContexts_;
     61            inline std::string getConfigurableContextsName() const
     62                { return "outputContexts" + this->name_; }
     63
     64            void changedConfigurableLevels();
     65            void changedConfigurableContexts();
     66
     67            static inline std::string getConfigurableSectionName()
     68                { return "Output"; }
    4269
    4370        protected:
     
    4673        private:
    4774            virtual void printLine(const std::string& line, OutputLevel level) = 0;
     75
     76            void setLevelRange(OutputLevel min, OutputLevel max);
     77            void setLevelMask(OutputLevel mask);
     78
     79            bool isAdditionalContext(OutputContext context) const;
     80
     81            std::string name_;
     82            std::set<std::string> configurableContextsSet_;
    4883    };
    4984}
  • code/branches/output/src/libraries/util/output/ConsoleWriter.cc

    r8795 r8799  
    3535namespace orxonox
    3636{
    37     ConsoleWriter::ConsoleWriter()
     37    ConsoleWriter::ConsoleWriter() : BaseWriter("Console")
    3838    {
    3939#ifdef ORXONOX_RELEASE
  • code/branches/output/src/libraries/util/output/LogWriter.cc

    r8795 r8799  
    3636namespace orxonox
    3737{
    38     LogWriter::LogWriter()
     38    LogWriter::LogWriter() : BaseWriter("Log")
    3939    {
    4040        this->setLevelMax(level::internal_info);
    4141
    42         this->filename_ = "orxonox2.log";
     42        this->filename_ = "orxonox.log";
    4343
    4444        // Get path for a temporary file
  • code/branches/output/src/libraries/util/output/OutputDefinitions.h

    r8798 r8799  
    4444        static const OutputLevel all              = 0xFFFF;
    4545        static const OutputLevel none             = 0x0000;
     46
    4647        static const OutputLevel debug_output     = 0x0001;
    4748        static const OutputLevel user_error       = 0x0002;
  • code/branches/output/src/libraries/util/output/OutputManager.cc

    r8787 r8799  
    166166    }
    167167
     168    OutputContext OutputManager::getContextValue(const std::string& name) const
     169    {
     170        boost::bimap<OutputContext, std::string>::right_map::const_iterator it = this->contexts_.right.find(name);
     171        if (it != this->contexts_.right.end())
     172            return it->second;
     173        else
     174            return context::none;
     175    }
     176
    168177    std::string OutputManager::getComposedContextName(OutputContext context) const
    169178    {
  • code/branches/output/src/libraries/util/output/OutputManager.h

    r8787 r8799  
    6666            const std::string& getLevelName(OutputLevel level) const;
    6767            const std::string& getContextName(OutputContext context) const;
     68            OutputContext getContextValue(const std::string& name) const;
     69
    6870            std::string getComposedContextName(OutputContext context) const;
    6971            std::string getDefaultPrefix(OutputLevel level, OutputContext context) const;
Note: See TracChangeset for help on using the changeset viewer.