Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 27, 2009, 2:47:14 PM (15 years ago)
Author:
rgrieder
Message:

Changed Output concept a little bit to allow for more general use.
Every output (log) target has to be implemented as OutputListener. There is already a LogFileWriter and a MemoryLogWriter (stores ALL the log in a vector and provides iterators).
The OutputListener has a unique and constant name, a stream pointer and a soft debug level (that can only be changed via OutputHandler::setSoftDebugLevel(name, level)).
This concept doesn't require the OutputBuffer anymore, so I deleted it.

The adjustments in the Shell are just preliminary for this commit.

Location:
code/branches/console/src/libraries/core
Files:
9 edited

Legend:

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

    r5738 r5994  
    4747    @param defvalue The default-value of the variable
    4848*/
    49 #define SetConfigValueGeneric(type, varname, defvalue) \
     49#define SetConfigValueGeneric(type, varname, entryname, sectionname, defvalue) \
    5050    static orxonox::Identifier* identifier##varname = this->getIdentifier(); \
    5151    orxonox::ConfigValueContainer* container##varname = identifier##varname->getConfigValueContainer(#varname); \
    5252    if (!container##varname) \
    5353    { \
    54         container##varname = new orxonox::ConfigValueContainer(type, identifier##varname, identifier##varname->getName(), #varname, defvalue, varname); \
     54        container##varname = new orxonox::ConfigValueContainer(type, identifier##varname, sectionname, entryname, defvalue, varname); \
    5555        identifier##varname->addConfigValueContainer(#varname, container##varname); \
    5656    } \
    5757    container##varname->getValue(&varname, this)
    5858
    59 #define SetConfigValue(varname, defvalue) SetConfigValueGeneric(ConfigFileType::Settings, varname, defvalue)
     59#define SetConfigValue(varname, defvalue) SetConfigValueGeneric(ConfigFileType::Settings, varname, identifier##varname->getName(), #varname, defvalue)
    6060
    6161
  • code/branches/console/src/libraries/core/Core.cc

    r5992 r5994  
    106106        void setConfigValues()
    107107        {
    108 #ifdef NDEBUG
    109             const unsigned int defaultLevelConsole = 1;
    110             const unsigned int defaultLevelLogfile = 3;
    111             const unsigned int defaultLevelShell   = 1;
     108#ifdef ORXONOX_RELEASE
     109            const unsigned int defaultLevelLogFile = 3;
    112110#else
    113             const unsigned int defaultLevelConsole = 3;
    114             const unsigned int defaultLevelLogfile = 4;
    115             const unsigned int defaultLevelShell   = 3;
    116 #endif
    117             SetConfigValue(softDebugLevelConsole_, defaultLevelConsole)
    118                 .description("The maximal level of debug output shown in the console")
    119                 .callback(this, &CoreConfiguration::debugLevelChanged);
    120             SetConfigValue(softDebugLevelLogfile_, defaultLevelLogfile)
    121                 .description("The maximal level of debug output shown in the logfile")
    122                 .callback(this, &CoreConfiguration::debugLevelChanged);
    123             SetConfigValue(softDebugLevelShell_, defaultLevelShell)
    124                 .description("The maximal level of debug output shown in the ingame shell")
    125                 .callback(this, &CoreConfiguration::debugLevelChanged);
     111            const unsigned int defaultLevelLogFile = 4;
     112#endif
     113            SetConfigValueGeneric(ConfigFileType::Settings, softDebugLevelLogFile_, "softDebugLevelLogFile", "OutputHandler", defaultLevelLogFile)
     114                .description("The maximum level of debug output shown in the log file");
     115            OutputHandler::getInstance().setSoftDebugLevel(OutputHandler::logFileOutputListenerName_s, this->softDebugLevelLogFile_);
    126116
    127117            SetConfigValue(language_, Language::getInstance().defaultLanguage_)
     
    131121                .description("If true, all random actions are different each time you start the game")
    132122                .callback(this, &CoreConfiguration::initializeRandomNumberGenerator);
    133         }
    134 
    135         /**
    136             @brief Callback function if the debug level has changed.
    137         */
    138         void debugLevelChanged()
    139         {
    140             // softDebugLevel_ is the maximum of the 3 variables
    141             this->softDebugLevel_ = this->softDebugLevelConsole_;
    142             if (this->softDebugLevelLogfile_ > this->softDebugLevel_)
    143                 this->softDebugLevel_ = this->softDebugLevelLogfile_;
    144             if (this->softDebugLevelShell_ > this->softDebugLevel_)
    145                 this->softDebugLevel_ = this->softDebugLevelShell_;
    146 
    147             OutputHandler::setSoftDebugLevel(OutputHandler::LD_All,     this->softDebugLevel_);
    148             OutputHandler::setSoftDebugLevel(OutputHandler::LD_Console, this->softDebugLevelConsole_);
    149             OutputHandler::setSoftDebugLevel(OutputHandler::LD_Logfile, this->softDebugLevelLogfile_);
    150             OutputHandler::setSoftDebugLevel(OutputHandler::LD_Shell,   this->softDebugLevelShell_);
    151123        }
    152124
     
    179151        }
    180152
    181         int softDebugLevel_;                            //!< The debug level
    182         int softDebugLevelConsole_;                     //!< The debug level for the console
    183         int softDebugLevelLogfile_;                     //!< The debug level for the logfile
    184         int softDebugLevelShell_;                       //!< The debug level for the ingame shell
     153        int softDebugLevelLogFile_;                     //!< The debug level for the log file (belongs to OutputHandler)
    185154        std::string language_;                          //!< The language
    186155        bool bInitializeRandomNumberGenerator_;         //!< If true, srand(time(0)) is called
     
    228197
    229198        // Set the correct log path. Before this call, /tmp (Unix) or %TEMP% (Windows) was used
    230         OutputHandler::getOutStream().setLogPath(PathConfig::getLogPathString());
     199        OutputHandler::getInstance().setLogPath(PathConfig::getLogPathString());
    231200
    232201        // Parse additional options file now that we know its path
     
    328297        bGraphicsLoaded_ = false;
    329298        GameMode::bShowsGraphics_s = false;
    330     }
    331 
    332     /**
    333         @brief Returns the softDebugLevel for the given device (returns a default-value if the class is right about to be created).
    334         @param device The device
    335         @return The softDebugLevel
    336     */
    337     /*static*/ int Core::getSoftDebugLevel(OutputHandler::OutputDevice device)
    338     {
    339         switch (device)
    340         {
    341         case OutputHandler::LD_All:
    342             return Core::getInstance().configuration_->softDebugLevel_;
    343         case OutputHandler::LD_Console:
    344             return Core::getInstance().configuration_->softDebugLevelConsole_;
    345         case OutputHandler::LD_Logfile:
    346             return Core::getInstance().configuration_->softDebugLevelLogfile_;
    347         case OutputHandler::LD_Shell:
    348             return Core::getInstance().configuration_->softDebugLevelShell_;
    349         default:
    350             assert(0);
    351             return 2;
    352         }
    353     }
    354 
    355      /**
    356         @brief Sets the softDebugLevel for the given device. Please use this only temporary and restore the value afterwards, as it overrides the configured value.
    357         @param device The device
    358         @param level The level
    359     */
    360     /*static*/ void Core::setSoftDebugLevel(OutputHandler::OutputDevice device, int level)
    361     {
    362         if (device == OutputHandler::LD_All)
    363             Core::getInstance().configuration_->softDebugLevel_ = level;
    364         else if (device == OutputHandler::LD_Console)
    365             Core::getInstance().configuration_->softDebugLevelConsole_ = level;
    366         else if (device == OutputHandler::LD_Logfile)
    367             Core::getInstance().configuration_->softDebugLevelLogfile_ = level;
    368         else if (device == OutputHandler::LD_Shell)
    369             Core::getInstance().configuration_->softDebugLevelShell_ = level;
    370 
    371         OutputHandler::setSoftDebugLevel(device, level);
    372299    }
    373300
  • code/branches/console/src/libraries/core/Core.h

    r5992 r5994  
    6969            void setConfigValues();
    7070
    71             static int   getSoftDebugLevel(OutputHandler::OutputDevice device = OutputHandler::LD_All);
    72             static void  setSoftDebugLevel(OutputHandler::OutputDevice device, int level);
    7371            static const std::string& getLanguage();
    7472            static void  resetLanguage();
  • code/branches/console/src/libraries/core/GUIManager.cc

    r5992 r5994  
    5353#include "util/Exception.h"
    5454#include "util/OrxAssert.h"
    55 #include "Core.h"
    5655#include "LuaState.h"
    5756#include "PathConfig.h"
     
    7574                default: OrxAssert(false, "CEGUI log level out of range, inpect immediately!");
    7675            }
    77             OutputHandler::getOutStream().setOutputLevel(orxonoxLevel)
     76            OutputHandler::getOutStream(orxonoxLevel)
    7877                << "CEGUI: " << message << std::endl;
    7978
     
    121120        // set the log level according to ours (translate by subtracting 1)
    122121        ceguiLogger->setLoggingLevel(
    123             static_cast<LoggingLevel>(Core::getSoftDebugLevel(OutputHandler::LD_Logfile) - 1));
     122            static_cast<LoggingLevel>(OutputHandler::getInstance().getSoftDebugLevel("logFile") - 1));
    124123        this->ceguiLogger_ = ceguiLogger.release();
    125124
  • code/branches/console/src/libraries/core/GraphicsManager.cc

    r5929 r5994  
    408408            orxonoxLevel = 0;
    409409        }
    410         OutputHandler::getOutStream().setOutputLevel(orxonoxLevel)
     410        OutputHandler::getOutStream(orxonoxLevel)
    411411            << "Ogre: " << message << std::endl;
    412412    }
  • code/branches/console/src/libraries/core/IOConsole.cc

    r5986 r5994  
    6262        this->originalTerminalSettings_ = new termios;
    6363        this->setTerminalMode();
    64                 this->shell_.registerListener(this);
     64        this->shell_.registerListener(this);
    6565    }
    6666
     
    234234    }
    235235
     236#elif defined(ORXONOX_PLATFORM_WINDOWS)
     237
     238    IOConsole::IOConsole()
     239        : shell_(Shell::getInstance())
     240        , buffer_(Shell::getInstance().getInputBuffer())
     241    {
     242        this->setTerminalMode();
     243    }
     244
     245    IOConsole::~IOConsole()
     246    {
     247    }
     248
     249    void IOConsole::setTerminalMode()
     250    {
     251    }
     252
     253    void IOConsole::resetTerminalMode()
     254    {
     255    }
     256
     257    void IOConsole::update(const Clock& time)
     258    {
     259    }
     260
     261    void IOConsole::print(const std::string& text)
     262    {
     263    }
     264
     265    void IOConsole::printInputLine()
     266    {
     267    }
     268
    236269#endif /* ORXONOX_PLATFORM_UNIX */
    237270
     
    256289    void IOConsole::onlyLastLineChanged()
    257290    {
    258                 // Save cursor position and move it the beginning of the second to last line
    259                 std::cout << "\033[s\033[1F";
    260                 // Erase the second to last line
    261                 std::cout << "\033[K";
    262                 this->print(*(this->shell_.getNewestLineIterator()));
    263                 // Restore cursor
    264                 std::cout << "\033[u";
    265                 std::cout.flush();
     291        // Save cursor position and move it the beginning of the second to last line
     292        std::cout << "\033[s\033[1F";
     293        // Erase the second to last line
     294        std::cout << "\033[K";
     295        this->print(*(this->shell_.getNewestLineIterator()));
     296        // Restore cursor
     297        std::cout << "\033[u";
     298        std::cout.flush();
    266299    }
    267300
     
    272305    void IOConsole::lineAdded()
    273306    {
    274                 // Move curosr the beginning of the line and erase it
    275                 std::cout << "\033[1G\033[K";
    276                 this->print(*(this->shell_.getNewestLineIterator()));
    277                 std::cout << std::endl;
    278                 this->printInputLine();
     307        // Move curosr the beginning of the line and erase it
     308        std::cout << "\033[1G\033[K";
     309        this->print(*(this->shell_.getNewestLineIterator()));
     310        std::cout << std::endl;
     311        this->printInputLine();
    279312    }
    280313
     
    303336    void IOConsole::executed()
    304337    {
    305                 // Move curosr the beginning of the line
    306                 std::cout << "\033[1G";
    307         // Print command so the user knows what he typed
     338        // Move cursor the beginning of the line
     339        std::cout << "\033[1G";
     340        // Print command so the user knows what he has typed
    308341        std::cout << "orxonox>" << this->shell_.getInput() << std::endl;
    309                 this->printInputLine();
     342        this->printInputLine();
    310343    }
    311344
  • code/branches/console/src/libraries/core/LuaState.cc

    r5929 r5994  
    182182    void LuaState::luaLog(unsigned int level, const std::string& message)
    183183    {
    184         OutputHandler::getOutStream().setOutputLevel(level) << message << std::endl;
     184        OutputHandler::getOutStream(level) << message << std::endl;
    185185    }
    186186
  • code/branches/console/src/libraries/core/Shell.cc

    r5986 r5994  
    5151
    5252    Shell::Shell()
    53     {
    54         int level = Core::getSoftDebugLevel(OutputHandler::LD_Shell);
    55         Core::setSoftDebugLevel(OutputHandler::LD_Shell, -1);
    56 
     53        : OutputListener("shell")
     54    {
    5755        RegisterRootObject(Shell);
    5856
     
    6967        this->configureInputBuffer();
    7068
    71         this->outputBuffer_.registerListener(this);
    72         OutputHandler::getOutStream().setOutputBuffer(&this->outputBuffer_);
    73 
    7469        // Get a config file for the command history
    7570        this->commandHistoryConfigFileType_ = ConfigFileManager::getInstance().getNewConfigFileType();
    7671        ConfigFileManager::getInstance().setFilename(this->commandHistoryConfigFileType_, "commandHistory.ini");
    7772
     73        // Use a stringstream object to buffer the output and get it line by line in update()
     74        this->outputStream_ = &this->outputBuffer_;
     75
    7876        this->setConfigValues();
    7977
    80         Core::setSoftDebugLevel(OutputHandler::LD_Shell, level);
     78        // Get the previous output and add it to the Shell
     79        for (OutputHandler::OutputVectorIterator it = OutputHandler::getInstance().getOutputVectorBegin();
     80            it != OutputHandler::getInstance().getOutputVectorEnd(); ++it)
     81            this->addLine(it->second, it->first);
     82
     83        // Register the shell as output listener
     84        OutputHandler::getInstance().registerOutputListener(this);
    8185    }
    8286
    8387    Shell::~Shell()
    8488    {
    85         OutputHandler::getOutStream().setOutputBuffer(0);
    86         if (this->inputBuffer_)
    87             this->inputBuffer_->destroy();
     89        OutputHandler::getInstance().unregisterOutputListener(this);
     90        this->inputBuffer_->destroy();
    8891    }
    8992
    9093    void Shell::setConfigValues()
    9194    {
    92         SetConfigValueGeneric(commandHistoryConfigFileType_, maxHistoryLength_, 100)
     95        SetConfigValueGeneric(commandHistoryConfigFileType_, maxHistoryLength_, "maxHistoryLength_", "Shell", 100)
    9396            .callback(this, &Shell::commandHistoryLengthChanged);
    94         SetConfigValueGeneric(commandHistoryConfigFileType_, historyOffset_, 0)
     97        SetConfigValueGeneric(commandHistoryConfigFileType_, historyOffset_, "historyOffset_", "Shell", 0)
    9598            .callback(this, &Shell::commandHistoryOffsetChanged);
    9699        SetConfigValueVectorGeneric(commandHistoryConfigFileType_, commandHistory_, std::vector<std::string>());
     100
     101#ifdef ORXONOX_RELEASE
     102        const unsigned int defaultLevel = 1;
     103#else
     104        const unsigned int defaultLevel = 3;
     105#endif
     106        SetConfigValueGeneric(ConfigFileType::Settings, softDebugLevel_, "softDebugLevelShell", "OutputHandler", defaultLevel)
     107            .description("The maximal level of debug output shown in the Shell");
     108        OutputHandler::getInstance().setSoftDebugLevel("shell", this->softDebugLevel_);
    97109    }
    98110
     
    182194    void Shell::addLine(const std::string& line, int level)
    183195    {
    184         int original_level = OutputHandler::getOutStream().getOutputLevel();
    185         OutputHandler::getOutStream().setOutputLevel(level);
    186 
    187         if (!this->finishedLastLine_)
    188             this->outputBuffer_ << std::endl;
    189 
    190         this->outputBuffer_ << line << std::endl;
    191         OutputHandler::getOutStream().setOutputLevel(original_level);
     196        if (level <= this->softDebugLevel_)
     197            this->lines_.push_front(line);
     198        this->updateListeners<&ShellListener::lineAdded>();
    192199    }
    193200
     
    238245        do
    239246        {
    240             newline = this->outputBuffer_.getLine(&output);
     247            std::getline(this->outputBuffer_, output);
     248
     249            bool eof = this->outputBuffer_.eof();
     250            bool fail = this->outputBuffer_.fail();
     251            if (eof)
     252                this->outputBuffer_.flush();
     253            if (eof || fail)
     254                this->outputBuffer_.clear();
     255            newline = (!eof && !fail);
    241256
    242257            if (!newline && output == "")
     
    246261            {
    247262                if (this->bAddOutputLevel_)
    248                     output.insert(0, 1, static_cast<char>(OutputHandler::getOutStream().getOutputLevel()));
    249 
    250                 this->lines_.insert(this->lines_.begin(), output);
     263                    output.insert(0, 1, static_cast<char>(OutputHandler::getInstance().getOutputLevel()));
     264
     265                this->lines_.push_front(output);
    251266
    252267                if (this->scrollPosition_)
     
    365380            return;
    366381        unsigned int cursorPosition = this->getCursorPosition();
    367         std::string input_str( this->getInput().substr(0,cursorPosition) ); //only search for the expression from the beginning of the inputline untill the cursor position
    368         for (unsigned int newPos = this->historyPosition_+1; newPos<=this->historyOffset_; newPos++)
    369         {
    370             if (getLowercase(this->commandHistory_[this->historyOffset_ - newPos]).find(getLowercase(input_str)) == 0) //search case insensitive
     382        std::string input_str(this->getInput().substr(0, cursorPosition)); // only search for the expression from the beginning of the inputline untill the cursor position
     383        for (unsigned int newPos = this->historyPosition_ + 1; newPos <= this->historyOffset_; newPos++)
     384        {
     385            if (getLowercase(this->commandHistory_[this->historyOffset_ - newPos]).find(getLowercase(input_str)) == 0) // search case insensitive
    371386            {
    372387                this->historyPosition_ = newPos;
    373388                this->inputBuffer_->set(this->getFromHistory());
    374                 this->setCursorPosition( cursorPosition );
     389                this->setCursorPosition(cursorPosition);
    375390                return;
    376391            }
     
    383398            return;
    384399        unsigned int cursorPosition = this->getCursorPosition();
    385         std::string input_str( this->getInput().substr(0,cursorPosition) ); //only search for the expression from the beginn$
    386         for (unsigned int newPos = this->historyPosition_-1; newPos>0; newPos--)
    387         {
    388             if (getLowercase(this->commandHistory_[this->historyOffset_ - newPos]).find(getLowercase(input_str)) == 0) //sear$
     400        std::string input_str(this->getInput().substr(0, cursorPosition)); // only search for the expression from the beginn$
     401        for (unsigned int newPos = this->historyPosition_ - 1; newPos > 0; newPos--)
     402        {
     403            if (getLowercase(this->commandHistory_[this->historyOffset_ - newPos]).find(getLowercase(input_str)) == 0) // sear$
    389404            {
    390405                this->historyPosition_ = newPos;
    391406                this->inputBuffer_->set(this->getFromHistory());
    392                 this->setCursorPosition( cursorPosition );
     407                this->setCursorPosition(cursorPosition);
    393408                return;
    394409            }
  • code/branches/console/src/libraries/core/Shell.h

    r5986 r5994  
    3434#include <cassert>
    3535#include <list>
     36#include <sstream>
    3637#include <string>
    3738#include <vector>
    3839
    39 #include "util/OutputBuffer.h"
     40#include "util/OutputHandler.h"
    4041#include "input/InputBuffer.h"
    4142#include "OrxonoxClass.h"
     
    6162    };
    6263
    63     class _CoreExport Shell : public Singleton<Shell>, virtual public OrxonoxClass, public OutputBufferListener
     64    class _CoreExport Shell : public Singleton<Shell>, virtual public OrxonoxClass, public OutputListener
    6465    {
    6566        friend class Singleton<Shell>;
     
    7172            static void history();
    7273
    73             virtual void setConfigValues();
     74            void setConfigValues();
    7475            void commandHistoryOffsetChanged();
    7576            void commandHistoryLengthChanged();
     
    8081            inline InputBuffer* getInputBuffer()
    8182                { return this->inputBuffer_; }
    82             inline OutputBuffer& getOutputBuffer()
    83                 { return this->outputBuffer_; }
    8483
    8584            void setCursorPosition(unsigned int cursor);
     
    117116
    118117            virtual void outputChanged();
     118
    119119            void inputChanged();
    120120            void execute();
     
    144144            std::list<ShellListener*> listeners_;
    145145            InputBuffer* inputBuffer_;
    146             OutputBuffer outputBuffer_;
     146            std::stringstream outputBuffer_;
    147147            bool finishedLastLine_;
    148148            std::list<std::string> lines_;
     
    154154            unsigned int historyOffset_;
    155155            bool bAddOutputLevel_;
     156            int softDebugLevel_;
    156157
    157158            ConfigFileType commandHistoryConfigFileType_;
Note: See TracChangeset for help on using the changeset viewer.