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