Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 1, 2006, 1:37:36 PM (18 years ago)
Author:
bensch
Message:

Changed the ShellBuffer to DebugBuffer, as the dependency is only one way, and it makes no sense for the rest of Orxonox Modules to know the Shell

File:
1 moved

Legend:

Unmodified
Added
Removed
  • branches/new_class_id/src/lib/util/debug_buffer.cc

    r9859 r9861  
    1414*/
    1515
    16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_SHELL
    17 
    18 #include "shell_buffer.h"
     16#include "debug_buffer.h"
    1917
    2018#include <stdarg.h>
     
    2220#include "debug.h"
    2321#include "compiler.h"
    24 #include "lib/util/threading.h"
     22#include "threading.h"
    2523
    26 namespace OrxShell
     24/**
     25 * @brief standard constructor
     26 */
     27DebugBuffer::DebugBuffer ()
    2728{
    28   /**
    29    * @brief standard constructor
    30    */
    31   ShellBuffer::ShellBuffer ()
    32   {
    33     ShellBuffer::singletonRef = this;
     29  DebugBuffer::singletonRef = this;
    3430
    35     this->lineCount = 0;
    36     this->bufferArray[0] = '\0';
     31  this->lineCount = 0;
     32  this->bufferArray[0] = '\0';
    3733
    38     this->setMaxBufferSize(100);
    39   }
     34  this->setMaxBufferSize(100);
     35}
    4036
    41   ShellBuffer* ShellBuffer::singletonRef = NULL;
    42   std::list<std::string> ShellBuffer::buffer;
    43   char ShellBuffer::bufferArray[SHELL_BUFFER_SIZE] = "";
     37DebugBuffer* DebugBuffer::singletonRef = NULL;
     38std::list<std::string> DebugBuffer::buffer;
     39char DebugBuffer::bufferArray[DEBUG_BUFFER_SIZE] = "";
    4440
    4541
    46   /**
    47    * @brief standard deconstructor
    48    */
    49   ShellBuffer::~ShellBuffer ()
    50   {
    51     ShellBuffer::singletonRef = NULL;
    52   }
     42/**
     43 * @brief standard deconstructor
     44 */
     45DebugBuffer::~DebugBuffer ()
     46{
     47  DebugBuffer::singletonRef = NULL;
     48}
    5349
    54   /**
    55    * @brief deletes all the Buffers
    56    */
    57   void ShellBuffer::flush()
    58   {
    59     this->buffer.clear();
    60   }
     50/**
     51 * @brief deletes all the Buffers
     52 */
     53void DebugBuffer::flush()
     54{
     55  this->buffer.clear();
     56}
    6157
    62   /**
    63    * @brief adds a new Line to the List of Buffers
    64    * @param line the Line as in the first argument in printf
    65    */
    66   void ShellBuffer::addBufferLineStatic(const char* line, ...)
    67   {
    68     static OrxThread::Mutex ShellBuffer__bufferMutex;
     58/**
     59 * @brief adds a new Line to the List of Buffers
     60 * @param line the Line as in the first argument in printf
     61 */
     62void DebugBuffer::addBufferLineStatic(const char* line, ...)
     63{
     64  static OrxThread::Mutex DebugBuffer__bufferMutex;
    6965
    70     OrxThread::MutexLock bufferLock(&ShellBuffer__bufferMutex);
     66  OrxThread::MutexLock bufferLock(&DebugBuffer__bufferMutex);
    7167
    72     va_list arguments;
    73     va_start(arguments, line);
    74     vsnprintf(ShellBuffer::bufferArray, SHELL_BUFFER_SIZE, line, arguments);
    75     va_end(arguments);
     68  va_list arguments;
     69  va_start(arguments, line);
     70  vsnprintf(DebugBuffer::bufferArray, DEBUG_BUFFER_SIZE, line, arguments);
     71  va_end(arguments);
    7672
    7773#if DEBUG_LEVEL < 3
    78     if (ShellBuffer::singletonRef == NULL)
     74  if (DebugBuffer::singletonRef == NULL)
    7975#endif
    80       printf(ShellBuffer::bufferArray);
     76    printf(DebugBuffer::bufferArray);
    8177#if DEBUG_LEVEL < 3
    82     else
     78  else
    8379#else
    84     if (ShellBuffer::singletonRef != NULL)
     80  if (DebugBuffer::singletonRef != NULL)
    8581#endif
    86       ShellBuffer::singletonRef->addBufferLine(ShellBuffer::bufferArray);
     82    DebugBuffer::singletonRef->addBufferLine(DebugBuffer::bufferArray);
     83}
     84
     85/**
     86 * @brief add a Line to the List of Buffers
     87 * @param line
     88 * @param arguments
     89 *
     90 * This function Adds one line to the buffer.
     91 * and displays the line as the First Line of the display-buffer
     92 */
     93void DebugBuffer::addBufferLine(const char* line)
     94{
     95  std::string inputBuffer = this->keepBuffer + line;
     96
     97  unsigned int lineBegin = 0;
     98  unsigned int lineEnd = 0;
     99  // adding all the new Lines
     100  while (lineEnd < inputBuffer.size())
     101  {
     102    lineBegin = lineEnd;
     103    lineEnd = inputBuffer.find('\n', (lineBegin == 0) ? 0: ++lineBegin);
     104    if (likely(lineEnd != std::string::npos ))
     105    {
     106      this->lineCount++;
     107      this->buffer.push_front(inputBuffer.substr(lineBegin, lineEnd - lineBegin));
     108    }
     109    else      // No end of Line reached.
     110    {
     111      this->keepBuffer = inputBuffer.substr(lineBegin, inputBuffer.size() - lineBegin);
     112      break;
     113    }
     114
     115    if (inputBuffer[lineBegin] == '\n')
     116      lineBegin++, lineEnd++;
     117
     118    if (this->buffer.size() > this->maxBufferSize)
     119      this->buffer.pop_back();
    87120  }
     121}
    88122
    89   /**
    90    * @brief add a Line to the List of Buffers
    91    * @param line
    92    * @param arguments
    93    *
    94    * This function Adds one line to the buffer.
    95    * and displays the line as the First Line of the display-buffer
    96    */
    97   void ShellBuffer::addBufferLine(const char* line)
    98   {
    99     std::string inputBuffer = this->keepBuffer + line;
     123/**
     124 * @brief displays some nice output from the Debug
     125 */
     126void DebugBuffer::debug() const
     127{
     128  PRINT(3)("Debugging output to console (not this debug)\n");
    100129
    101     unsigned int lineBegin = 0;
    102     unsigned int lineEnd = 0;
    103     // adding all the new Lines
    104     while (lineEnd < inputBuffer.size())
    105     {
    106       lineBegin = lineEnd;
    107       lineEnd = inputBuffer.find('\n', (lineBegin == 0) ? 0: ++lineBegin);
    108       if (likely(lineEnd != std::string::npos ))
    109       {
    110         this->lineCount++;
    111         this->buffer.push_front(inputBuffer.substr(lineBegin, lineEnd - lineBegin));
    112       }
    113       else      // No end of Line reached.
    114       {
    115         this->keepBuffer = inputBuffer.substr(lineBegin, inputBuffer.size() - lineBegin);
    116         break;
    117       }
    118 
    119       if (inputBuffer[lineBegin] == '\n')
    120         lineBegin++, lineEnd++;
    121 
    122       if (this->buffer.size() > this->maxBufferSize)
    123         this->buffer.pop_back();
    124     }
    125   }
    126 
    127   /**
    128    * @brief displays some nice output from the Shell
    129    */
    130   void ShellBuffer::debug() const
    131   {
    132     PRINT(3)("Debugging output to console (not this shell)\n");
    133 
    134     std::list<std::string>::const_iterator bufferLine;
    135     for (bufferLine = --this->buffer.end(); bufferLine != this->buffer.begin(); --bufferLine)
    136       printf((*bufferLine).c_str());
    137   }
    138 
     130  std::list<std::string>::const_iterator bufferLine;
     131  for (bufferLine = --this->buffer.end(); bufferLine != this->buffer.begin(); --bufferLine)
     132    printf((*bufferLine).c_str());
    139133}
Note: See TracChangeset for help on using the changeset viewer.