1 | /*! |
---|
2 | * @file shell_buffer.h |
---|
3 | * @brief The Shell buffer Tasks |
---|
4 | * @see debug.h |
---|
5 | */ |
---|
6 | |
---|
7 | #ifndef _SHELL_BUFFER_H |
---|
8 | #define _SHELL_BUFFER_H |
---|
9 | |
---|
10 | #include <string> |
---|
11 | #include <list> |
---|
12 | #include <stdarg.h> |
---|
13 | |
---|
14 | #define SHELL_BUFFER_SIZE 16384 //!< The Size of the input-buffers (should be large enough to carry any kind of input) |
---|
15 | |
---|
16 | namespace OrxShell |
---|
17 | { |
---|
18 | //! A class handling output from orxonox via debug.h |
---|
19 | /** |
---|
20 | * the ShellBuffer redirects output from PRINTF(x) to the Shell and STDOUT |
---|
21 | * the ShellBuffer is a front-filling queue of limited length, that has the |
---|
22 | * youngest added Entry at the beginning, and the oldest at the end. |
---|
23 | */ |
---|
24 | class ShellBuffer |
---|
25 | { |
---|
26 | public: |
---|
27 | virtual ~ShellBuffer(); |
---|
28 | /** @returns a Pointer to the only object of this Class */ |
---|
29 | inline static ShellBuffer* getInstance() { if (!ShellBuffer::singletonRef) ShellBuffer::singletonRef = new ShellBuffer(); return ShellBuffer::singletonRef; }; |
---|
30 | /** @returns true if this class is instanciated, false otherwise */ |
---|
31 | inline static bool isInstanciated() { return (ShellBuffer::singletonRef == NULL)?false:true; }; |
---|
32 | |
---|
33 | static void addBufferLineStatic(const char* line, ...); |
---|
34 | void addBufferLine(const char* line); |
---|
35 | |
---|
36 | /// BUFFER |
---|
37 | /** @param bufferSize the new Buffer-Size */ |
---|
38 | void setMaxBufferSize(unsigned int maxBufferSize) { this->maxBufferSize = maxBufferSize; }; |
---|
39 | void flush(); |
---|
40 | |
---|
41 | /** @returns the List of stings from the Buffer */ |
---|
42 | const std::list<std::string>& getBuffer() const { return this->buffer; }; |
---|
43 | /** @returns the Count of lines processed by the Shell. */ |
---|
44 | inline unsigned long getLineCount() const { return this->lineCount; }; |
---|
45 | /** @returns the Current Buffer Size. */ |
---|
46 | inline unsigned int getBufferSize() const { return this->buffer.size(); }; |
---|
47 | |
---|
48 | void debug() const; |
---|
49 | |
---|
50 | private: |
---|
51 | ShellBuffer(); |
---|
52 | |
---|
53 | private: |
---|
54 | static ShellBuffer* singletonRef; //!< The singleton-reference to the only memeber of this class. |
---|
55 | unsigned int maxBufferSize; //!< The Size of the buffer |
---|
56 | |
---|
57 | std::string keepBuffer; //!< a BUFFER to have multi-non-newLine commands be copied into the shell. |
---|
58 | |
---|
59 | unsigned long lineCount; //!< how many Lines have been written out so far. |
---|
60 | |
---|
61 | // The Beginning of buffer (buffer.front()) is the last added line. |
---|
62 | static char bufferArray[SHELL_BUFFER_SIZE]; //!< a BUFFER for fast writing |
---|
63 | static std::list<std::string> buffer; //!< A list of stored char-arrays(strings) to store the history |
---|
64 | }; |
---|
65 | |
---|
66 | } |
---|
67 | |
---|
68 | #endif /* _SHELL_BUFFER_H */ |
---|