[Orxonox-commit 4128] r8799 - in code/branches/output/src/libraries: core core/command util/output

landauf at orxonox.net landauf at orxonox.net
Sat Jul 30 19:51:08 CEST 2011


Author: landauf
Date: 2011-07-30 19:51:08 +0200 (Sat, 30 Jul 2011)
New Revision: 8799

Modified:
   code/branches/output/src/libraries/core/Core.cc
   code/branches/output/src/libraries/core/Core.h
   code/branches/output/src/libraries/core/GUIManager.cc
   code/branches/output/src/libraries/core/command/IOConsolePOSIX.cc
   code/branches/output/src/libraries/core/command/IOConsoleWindows.cc
   code/branches/output/src/libraries/core/command/Shell.cc
   code/branches/output/src/libraries/core/command/Shell.h
   code/branches/output/src/libraries/util/output/BaseWriter.cc
   code/branches/output/src/libraries/util/output/BaseWriter.h
   code/branches/output/src/libraries/util/output/ConsoleWriter.cc
   code/branches/output/src/libraries/util/output/LogWriter.cc
   code/branches/output/src/libraries/util/output/OutputDefinitions.h
   code/branches/output/src/libraries/util/output/OutputManager.cc
   code/branches/output/src/libraries/util/output/OutputManager.h
Log:
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.

Modified: code/branches/output/src/libraries/core/Core.cc
===================================================================
--- code/branches/output/src/libraries/core/Core.cc	2011-07-30 13:55:35 UTC (rev 8798)
+++ code/branches/output/src/libraries/core/Core.cc	2011-07-30 17:51:08 UTC (rev 8799)
@@ -50,8 +50,6 @@
 #  undef max
 #endif
 
-#include <boost/preprocessor/stringize.hpp>
-
 #include "util/Clock.h"
 #include "util/Output.h"
 #include "util/Exception.h"
@@ -230,23 +228,28 @@
         safeObjectDelete(&pathConfig_);
     }
 
-    namespace DefaultLevelLogFile
-    {
-#pragma message(__FILE__ "("BOOST_PP_STRINGIZE(__LINE__)") : Warning: TODO: inspect this (and remove boost include)")
-        const OutputLevel Dev  = level::internal_info;
-        const OutputLevel User = level::internal_info;
-    }
-
     //! Function to collect the SetConfigValue-macro calls.
     void Core::setConfigValues()
     {
-        // Choose the default level according to the path Orxonox was started (build directory or not)
-        OutputLevel defaultLogLevel = (PathConfig::buildDirectoryRun() ? DefaultLevelLogFile::Dev : DefaultLevelLogFile::User);
+        SetConfigValueExternal(LogWriter::getInstance().configurableMaxLevel_,
+                               LogWriter::getInstance().getConfigurableSectionName(),
+                               LogWriter::getInstance().getConfigurableMaxLevelName(),
+                               LogWriter::getInstance().configurableMaxLevel_)
+            .description("The maximum level of output shown in the log file")
+            .callback(static_cast<BaseWriter*>(&LogWriter::getInstance()), &BaseWriter::changedConfigurableLevels);
+        SetConfigValueExternal(LogWriter::getInstance().configurableContextsMaxLevel_,
+                               LogWriter::getInstance().getConfigurableSectionName(),
+                               LogWriter::getInstance().getConfigurableContextsMaxLevelName(),
+                               LogWriter::getInstance().configurableContextsMaxLevel_)
+            .description("The maximum level of output shown in the log file for additional contexts")
+            .callback(static_cast<BaseWriter*>(&LogWriter::getInstance()), &BaseWriter::changedConfigurableLevels);
+        SetConfigValueExternal(LogWriter::getInstance().configurableContexts_,
+                               LogWriter::getInstance().getConfigurableSectionName(),
+                               LogWriter::getInstance().getConfigurableContextsName(),
+                               LogWriter::getInstance().configurableContexts_)
+            .description("Additional output contexts shown in the log file")
+            .callback(static_cast<BaseWriter*>(&LogWriter::getInstance()), &BaseWriter::changedConfigurableContexts);
 
-        SetConfigValueExternal(debugLevelLogFile_, "OutputHandler", "debugLevelLogFile", defaultLogLevel)
-            .description("The maximum level of debug output written to the log file");
-        LogWriter::getInstance().setLevelMax(this->debugLevelLogFile_);
-
         SetConfigValue(bDevMode_, PathConfig::buildDirectoryRun())
             .description("Developer mode. If not set, hides some things from the user to not confuse him.")
             .callback(this, &Core::devModeChanged);
@@ -280,17 +283,6 @@
     */
     void Core::devModeChanged()
     {
-        bool isNormal = (bDevMode_ == PathConfig::buildDirectoryRun());
-        if (isNormal)
-        {
-            ModifyConfigValueExternal(debugLevelLogFile_, "debugLevelLogFile", update);
-        }
-        else
-        {
-            OutputLevel 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)

Modified: code/branches/output/src/libraries/core/Core.h
===================================================================
--- code/branches/output/src/libraries/core/Core.h	2011-07-30 13:55:35 UTC (rev 8798)
+++ code/branches/output/src/libraries/core/Core.h	2011-07-30 17:51:08 UTC (rev 8799)
@@ -135,7 +135,6 @@
             Scope<ScopeID::Graphics>* graphicsScope_;
 
             bool                      bGraphicsLoaded_;
-            OutputLevel               debugLevelLogFile_;          //!< The debug level for the log file (belongs to LogWriter)
             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/output/src/libraries/core/GUIManager.cc
===================================================================
--- code/branches/output/src/libraries/core/GUIManager.cc	2011-07-30 13:55:35 UTC (rev 8798)
+++ code/branches/output/src/libraries/core/GUIManager.cc	2011-07-30 17:51:08 UTC (rev 8799)
@@ -76,6 +76,7 @@
 #include "util/Exception.h"
 #include "util/Math.h"
 #include "util/OrxAssert.h"
+#include "util/output/BaseWriter.h"
 #include "ConfigValueIncludes.h"
 #include "Core.h"
 #include "CoreIncludes.h"
@@ -367,7 +368,7 @@
     {
         SetConfigValue(guiScheme_, GUIManager::defaultScheme_).description("Changes the current GUI scheme.").callback(this, &GUIManager::changedGUIScheme);
         SetConfigValue(numScrollLines_, 1).description("How many lines to scroll in a list if the scroll wheel is used");
-        SetConfigValueExternal(outputLevelCeguiLog_, "OutputHandler", "outputLevelCeguiLog", CEGUI::Standard).description("The log level of the CEGUI log file").callback(this, &GUIManager::changedCeguiOutputLevel);
+        SetConfigValueExternal(outputLevelCeguiLog_, BaseWriter::getConfigurableSectionName(), "outputLevelCeguiLog", CEGUI::Standard).description("The log level of the CEGUI log file").callback(this, &GUIManager::changedCeguiOutputLevel);
     }
 
     void GUIManager::changedGUIScheme(void)

Modified: code/branches/output/src/libraries/core/command/IOConsolePOSIX.cc
===================================================================
--- code/branches/output/src/libraries/core/command/IOConsolePOSIX.cc	2011-07-30 13:55:35 UTC (rev 8798)
+++ code/branches/output/src/libraries/core/command/IOConsolePOSIX.cc	2011-07-30 17:51:08 UTC (rev 8799)
@@ -55,7 +55,7 @@
     }
 
     IOConsole::IOConsole()
-        : shell_(new Shell("IOConsole", false))
+        : shell_(new Shell("Console", false))
         , buffer_(shell_->getInputBuffer())
         , cout_(std::cout.rdbuf())
         , promptString_("orxonox # ")

Modified: code/branches/output/src/libraries/core/command/IOConsoleWindows.cc
===================================================================
--- code/branches/output/src/libraries/core/command/IOConsoleWindows.cc	2011-07-30 13:55:35 UTC (rev 8798)
+++ code/branches/output/src/libraries/core/command/IOConsoleWindows.cc	2011-07-30 17:51:08 UTC (rev 8799)
@@ -43,7 +43,7 @@
 
     //! Redirects std::cout, creates the corresponding Shell and changes the terminal mode
     IOConsole::IOConsole()
-        : shell_(new Shell("IOConsole", false))
+        : shell_(new Shell("Console", false))
         , buffer_(shell_->getInputBuffer())
         , cout_(std::cout.rdbuf())
         , promptString_("orxonox # ")

Modified: code/branches/output/src/libraries/core/command/Shell.cc
===================================================================
--- code/branches/output/src/libraries/core/command/Shell.cc	2011-07-30 13:55:35 UTC (rev 8798)
+++ code/branches/output/src/libraries/core/command/Shell.cc	2011-07-30 17:51:08 UTC (rev 8799)
@@ -55,14 +55,20 @@
 
     unsigned int Shell::cacheSize_s;
 
+    namespace DefaultLogLevel
+    {
+        const OutputLevel Dev  = level::internal_warning;
+        const OutputLevel User = level::user_info;
+    }
+
     /**
         @brief Constructor: Initializes the values.
         @param consoleName The name of the shell - used to define the name of the soft-debug-level config-value
         @param bScrollable If true, the user is allowed to scroll through the output-lines
     */
     Shell::Shell(const std::string& consoleName, bool bScrollable)
-        : inputBuffer_(new InputBuffer())
-        , consoleName_(consoleName)
+        : BaseWriter(consoleName)
+        , inputBuffer_(new InputBuffer())
         , bScrollable_(bScrollable)
     {
         RegisterRootObject(Shell);
@@ -78,6 +84,10 @@
         // Specify file for the command history
         ConfigFileManager::getInstance().setFilename(ConfigFileType::CommandHistory, "commandHistory.ini");
 
+        // Choose the default level according to the path Orxonox was started (build directory or not)
+        OutputLevel defaultDebugLevel = (PathConfig::buildDirectoryRun() ? DefaultLogLevel::Dev : DefaultLogLevel::User);
+        this->setLevelMax(defaultDebugLevel);
+
         this->setConfigValues();
 
         // Get the previous output and add it to the Shell
@@ -92,12 +102,6 @@
         this->inputBuffer_->destroy();
     }
 
-    namespace DefaultLogLevel
-    {
-        const OutputLevel Dev  = level::internal_warning;
-        const OutputLevel User = level::user_info;
-    }
-
     /**
         @brief Defines the config values.
     */
@@ -110,11 +114,24 @@
         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 defaultDebugLevel = (PathConfig::buildDirectoryRun() ? DefaultLogLevel::Dev : DefaultLogLevel::User);
-        SetConfigValueExternal(debugLevel_, "OutputHandler", "debugLevel" + consoleName_, defaultDebugLevel)
-            .description("The maximum level of debug output shown in the " + consoleName_);
-        this->setLevelMax(this->debugLevel_);
+        SetConfigValueExternal(this->configurableMaxLevel_,
+                               this->getConfigurableSectionName(),
+                               this->getConfigurableMaxLevelName(),
+                               this->configurableMaxLevel_)
+            .description("The maximum level of output shown in the " + this->getName())
+            .callback(static_cast<BaseWriter*>(this), &BaseWriter::changedConfigurableLevels);
+        SetConfigValueExternal(this->configurableContextsMaxLevel_,
+                               this->getConfigurableSectionName(),
+                               this->getConfigurableContextsMaxLevelName(),
+                               this->configurableContextsMaxLevel_)
+            .description("The maximum level of output shown in the " + this->getName() + " for additional contexts")
+            .callback(static_cast<BaseWriter*>(this), &BaseWriter::changedConfigurableLevels);
+        SetConfigValueExternal(this->configurableContexts_,
+                               this->getConfigurableSectionName(),
+                               this->getConfigurableContextsName(),
+                               this->configurableContexts_)
+            .description("Additional output contexts shown in the " + this->getName())
+            .callback(static_cast<BaseWriter*>(this), &BaseWriter::changedConfigurableLevels);
     }
 
     /**
@@ -149,12 +166,12 @@
         bool isNormal = (value == PathConfig::buildDirectoryRun());
         if (isNormal)
         {
-            ModifyConfigValueExternal(debugLevel_, "debugLevel" + consoleName_, update);
+            ModifyConfigValueExternal(debugLevel_, this->getConfigurableMaxLevelName(), update);
         }
         else
         {
             OutputLevel level = (value ? DefaultLogLevel::Dev : DefaultLogLevel::User);
-            ModifyConfigValueExternal(debugLevel_, "debugLevel" + consoleName_, tset, level);
+            ModifyConfigValueExternal(debugLevel_, this->getConfigurableMaxLevelName(), tset, level);
         }
     }
 

Modified: code/branches/output/src/libraries/core/command/Shell.h
===================================================================
--- code/branches/output/src/libraries/core/command/Shell.h	2011-07-30 13:55:35 UTC (rev 8798)
+++ code/branches/output/src/libraries/core/command/Shell.h	2011-07-30 17:51:08 UTC (rev 8799)
@@ -190,8 +190,6 @@
             LineList::const_iterator  scrollIterator_;      ///< An iterator to an entry of the list of output-lines, changes if the user scrolls through the output in the shell
             unsigned int              scrollPosition_;      ///< The number of the line that is currently being referenced by scrollIterator_
             unsigned int              historyPosition_;     ///< If the user scrolls through the history of entered commands (stored in commandHistory_), this contains the currently viewed history entry
-
-            const std::string         consoleName_;         ///< The name of this shell - used to define the name of the soft-debug-level config-value
             const bool                bScrollable_;         ///< If true, the user can scroll through the output-lines
 
             // Config values

Modified: code/branches/output/src/libraries/util/output/BaseWriter.cc
===================================================================
--- code/branches/output/src/libraries/util/output/BaseWriter.cc	2011-07-30 13:55:35 UTC (rev 8798)
+++ code/branches/output/src/libraries/util/output/BaseWriter.cc	2011-07-30 17:51:08 UTC (rev 8799)
@@ -32,8 +32,12 @@
 
 namespace orxonox
 {
-    BaseWriter::BaseWriter()
+    BaseWriter::BaseWriter(const std::string& name)
     {
+        this->name_ = name;
+
+        this->configurableMaxLevel_ = level::none;
+        this->configurableContextsMaxLevel_ = level::verbose;
     }
 
     BaseWriter::~BaseWriter()
@@ -42,10 +46,39 @@
 
     void BaseWriter::output(OutputLevel level, OutputContext context, const std::vector<std::string>& lines)
     {
-        const std::string& prefix = OutputManager::getInstance().getDefaultPrefix(level, context);
-        std::string blanks(prefix.length(), ' ');
+        if (level <= this->configurableMaxLevel_ || (level <= this->configurableContextsMaxLevel_ && this->isAdditionalContext(context)))
+        {
+            const std::string& prefix = OutputManager::getInstance().getDefaultPrefix(level, context);
+            std::string blanks(prefix.length(), ' ');
 
-        for (size_t i = 0; i < lines.size(); ++i)
-            this->printLine((i == 0 ? prefix : blanks) + lines[i], level);
+            for (size_t i = 0; i < lines.size(); ++i)
+                this->printLine((i == 0 ? prefix : blanks) + lines[i], level);
+        }
     }
+
+    void BaseWriter::setLevelMax(OutputLevel max)
+    {
+        this->configurableMaxLevel_ = max;
+        this->changedConfigurableLevels();
+    }
+
+    void BaseWriter::changedConfigurableLevels()
+    {
+        OutputLevel max_level = std::max(this->configurableMaxLevel_, this->configurableContextsMaxLevel_);
+        OutputListener::setLevelMax(max_level);
+    }
+
+    void BaseWriter::changedConfigurableContexts()
+    {
+        this->configurableContextsSet_.clear();
+        for (size_t i = 0; i < this->configurableContexts_.size(); ++i)
+            this->configurableContextsSet_.insert(this->configurableContexts_[i]);
+    }
+
+    bool BaseWriter::isAdditionalContext(OutputContext context) const
+    {
+        const std::string& name = OutputManager::getInstance().getContextName(context);
+        std::set<std::string>::const_iterator it = this->configurableContextsSet_.find(name);
+        return (it != this->configurableContextsSet_.end());
+    }
 }

Modified: code/branches/output/src/libraries/util/output/BaseWriter.h
===================================================================
--- code/branches/output/src/libraries/util/output/BaseWriter.h	2011-07-30 13:55:35 UTC (rev 8798)
+++ code/branches/output/src/libraries/util/output/BaseWriter.h	2011-07-30 17:51:08 UTC (rev 8799)
@@ -30,6 +30,10 @@
 #define _BaseWriter_H__
 
 #include "util/UtilPrereqs.h"
+
+#include <set>
+#include <vector>
+
 #include "OutputListener.h"
 
 namespace orxonox
@@ -37,14 +41,45 @@
     class _UtilExport BaseWriter : public OutputListener
     {
         public:
-            BaseWriter();
+            BaseWriter(const std::string& name);
             virtual ~BaseWriter();
 
+            const std::string& getName() const
+                { return this->name_; }
+
+            void setLevelMax(OutputLevel max);
+
+            OutputLevel configurableMaxLevel_;
+            inline std::string getConfigurableMaxLevelName() const
+                { return "outputLevel" + this->name_; }
+
+            OutputLevel configurableContextsMaxLevel_;
+            inline std::string getConfigurableContextsMaxLevelName() const
+                { return "outputContextsLevel" + this->name_; }
+
+            std::vector<std::string> configurableContexts_;
+            inline std::string getConfigurableContextsName() const
+                { return "outputContexts" + this->name_; }
+
+            void changedConfigurableLevels();
+            void changedConfigurableContexts();
+
+            static inline std::string getConfigurableSectionName()
+                { return "Output"; }
+
         protected:
             virtual void output(OutputLevel level, OutputContext context, const std::vector<std::string>& lines);
 
         private:
             virtual void printLine(const std::string& line, OutputLevel level) = 0;
+
+            void setLevelRange(OutputLevel min, OutputLevel max);
+            void setLevelMask(OutputLevel mask);
+
+            bool isAdditionalContext(OutputContext context) const;
+
+            std::string name_;
+            std::set<std::string> configurableContextsSet_;
     };
 }
 

Modified: code/branches/output/src/libraries/util/output/ConsoleWriter.cc
===================================================================
--- code/branches/output/src/libraries/util/output/ConsoleWriter.cc	2011-07-30 13:55:35 UTC (rev 8798)
+++ code/branches/output/src/libraries/util/output/ConsoleWriter.cc	2011-07-30 17:51:08 UTC (rev 8799)
@@ -34,7 +34,7 @@
 
 namespace orxonox
 {
-    ConsoleWriter::ConsoleWriter()
+    ConsoleWriter::ConsoleWriter() : BaseWriter("Console")
     {
 #ifdef ORXONOX_RELEASE
         this->setLevelMax(level::user_info);

Modified: code/branches/output/src/libraries/util/output/LogWriter.cc
===================================================================
--- code/branches/output/src/libraries/util/output/LogWriter.cc	2011-07-30 13:55:35 UTC (rev 8798)
+++ code/branches/output/src/libraries/util/output/LogWriter.cc	2011-07-30 17:51:08 UTC (rev 8799)
@@ -35,11 +35,11 @@
 
 namespace orxonox
 {
-    LogWriter::LogWriter()
+    LogWriter::LogWriter() : BaseWriter("Log")
     {
         this->setLevelMax(level::internal_info);
 
-        this->filename_ = "orxonox2.log";
+        this->filename_ = "orxonox.log";
 
         // Get path for a temporary file
 #ifdef ORXONOX_PLATFORM_WINDOWS

Modified: code/branches/output/src/libraries/util/output/OutputDefinitions.h
===================================================================
--- code/branches/output/src/libraries/util/output/OutputDefinitions.h	2011-07-30 13:55:35 UTC (rev 8798)
+++ code/branches/output/src/libraries/util/output/OutputDefinitions.h	2011-07-30 17:51:08 UTC (rev 8799)
@@ -43,6 +43,7 @@
     {
         static const OutputLevel all              = 0xFFFF;
         static const OutputLevel none             = 0x0000;
+
         static const OutputLevel debug_output     = 0x0001;
         static const OutputLevel user_error       = 0x0002;
         static const OutputLevel user_warning     = 0x0004;

Modified: code/branches/output/src/libraries/util/output/OutputManager.cc
===================================================================
--- code/branches/output/src/libraries/util/output/OutputManager.cc	2011-07-30 13:55:35 UTC (rev 8798)
+++ code/branches/output/src/libraries/util/output/OutputManager.cc	2011-07-30 17:51:08 UTC (rev 8799)
@@ -165,6 +165,15 @@
         return BLANKSTRING;
     }
 
+    OutputContext OutputManager::getContextValue(const std::string& name) const
+    {
+        boost::bimap<OutputContext, std::string>::right_map::const_iterator it = this->contexts_.right.find(name);
+        if (it != this->contexts_.right.end())
+            return it->second;
+        else
+            return context::none;
+    }
+
     std::string OutputManager::getComposedContextName(OutputContext context) const
     {
         std::string name;

Modified: code/branches/output/src/libraries/util/output/OutputManager.h
===================================================================
--- code/branches/output/src/libraries/util/output/OutputManager.h	2011-07-30 13:55:35 UTC (rev 8798)
+++ code/branches/output/src/libraries/util/output/OutputManager.h	2011-07-30 17:51:08 UTC (rev 8799)
@@ -65,6 +65,8 @@
 
             const std::string& getLevelName(OutputLevel level) const;
             const std::string& getContextName(OutputContext context) const;
+            OutputContext getContextValue(const std::string& name) const;
+
             std::string getComposedContextName(OutputContext context) const;
             std::string getDefaultPrefix(OutputLevel level, OutputContext context) const;
 




More information about the Orxonox-commit mailing list