Changeset 9861 in orxonox.OLD for branches/new_class_id/src/lib/util/debug_buffer.cc
- Timestamp:
- Oct 1, 2006, 1:37:36 PM (18 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/new_class_id/src/lib/util/debug_buffer.cc
r9859 r9861 14 14 */ 15 15 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_SHELL 17 18 #include "shell_buffer.h" 16 #include "debug_buffer.h" 19 17 20 18 #include <stdarg.h> … … 22 20 #include "debug.h" 23 21 #include "compiler.h" 24 #include " lib/util/threading.h"22 #include "threading.h" 25 23 26 namespace OrxShell 24 /** 25 * @brief standard constructor 26 */ 27 DebugBuffer::DebugBuffer () 27 28 { 28 /** 29 * @brief standard constructor 30 */ 31 ShellBuffer::ShellBuffer () 32 { 33 ShellBuffer::singletonRef = this; 29 DebugBuffer::singletonRef = this; 34 30 35 36 31 this->lineCount = 0; 32 this->bufferArray[0] = '\0'; 37 33 38 39 34 this->setMaxBufferSize(100); 35 } 40 36 41 ShellBuffer* ShellBuffer::singletonRef = NULL;42 std::list<std::string> ShellBuffer::buffer;43 char ShellBuffer::bufferArray[SHELL_BUFFER_SIZE] = "";37 DebugBuffer* DebugBuffer::singletonRef = NULL; 38 std::list<std::string> DebugBuffer::buffer; 39 char DebugBuffer::bufferArray[DEBUG_BUFFER_SIZE] = ""; 44 40 45 41 46 47 48 49 ShellBuffer::~ShellBuffer ()50 51 ShellBuffer::singletonRef = NULL;52 42 /** 43 * @brief standard deconstructor 44 */ 45 DebugBuffer::~DebugBuffer () 46 { 47 DebugBuffer::singletonRef = NULL; 48 } 53 49 54 55 56 57 void ShellBuffer::flush()58 59 60 50 /** 51 * @brief deletes all the Buffers 52 */ 53 void DebugBuffer::flush() 54 { 55 this->buffer.clear(); 56 } 61 57 62 63 64 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 */ 62 void DebugBuffer::addBufferLineStatic(const char* line, ...) 63 { 64 static OrxThread::Mutex DebugBuffer__bufferMutex; 69 65 70 OrxThread::MutexLock bufferLock(&ShellBuffer__bufferMutex);66 OrxThread::MutexLock bufferLock(&DebugBuffer__bufferMutex); 71 67 72 73 74 vsnprintf(ShellBuffer::bufferArray, SHELL_BUFFER_SIZE, line, arguments);75 68 va_list arguments; 69 va_start(arguments, line); 70 vsnprintf(DebugBuffer::bufferArray, DEBUG_BUFFER_SIZE, line, arguments); 71 va_end(arguments); 76 72 77 73 #if DEBUG_LEVEL < 3 78 if (ShellBuffer::singletonRef == NULL)74 if (DebugBuffer::singletonRef == NULL) 79 75 #endif 80 printf(ShellBuffer::bufferArray);76 printf(DebugBuffer::bufferArray); 81 77 #if DEBUG_LEVEL < 3 82 78 else 83 79 #else 84 if (ShellBuffer::singletonRef != NULL)80 if (DebugBuffer::singletonRef != NULL) 85 81 #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 */ 93 void 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(); 87 120 } 121 } 88 122 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 */ 126 void DebugBuffer::debug() const 127 { 128 PRINT(3)("Debugging output to console (not this debug)\n"); 100 129 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()); 139 133 }
Note: See TracChangeset
for help on using the changeset viewer.