[4838] | 1 | /*! |
---|
[5173] | 2 | * @file shell_buffer.h |
---|
| 3 | * @brief The Shell buffer Tasks |
---|
[5246] | 4 | * @see debug.h |
---|
[3245] | 5 | */ |
---|
[1853] | 6 | |
---|
[5173] | 7 | #ifndef _SHELL_BUFFER_H |
---|
| 8 | #define _SHELL_BUFFER_H |
---|
[1853] | 9 | |
---|
[5173] | 10 | #include <stdarg.h> |
---|
[5781] | 11 | #include <list> |
---|
[7329] | 12 | #include "threading.h" |
---|
[5173] | 13 | |
---|
| 14 | #define SHELL_BUFFER_SIZE 16384 //!< The Size of the input-buffers (should be large enough to carry any kind of input) |
---|
| 15 | |
---|
[7374] | 16 | namespace OrxShell |
---|
| 17 | { |
---|
| 18 | // FORWARD DECLARATION |
---|
| 19 | class Shell; |
---|
[5784] | 20 | |
---|
[7374] | 21 | //! A class handling output from orxonox via debug.h |
---|
| 22 | class ShellBuffer |
---|
| 23 | { |
---|
[3543] | 24 | |
---|
[7374] | 25 | public: |
---|
| 26 | virtual ~ShellBuffer(); |
---|
| 27 | /** @returns a Pointer to the only object of this Class */ |
---|
| 28 | inline static ShellBuffer* getInstance() { if (!ShellBuffer::singletonRef) ShellBuffer::singletonRef = new ShellBuffer(); return ShellBuffer::singletonRef; }; |
---|
| 29 | /** @returns true if this class is instanciated, false otherwise */ |
---|
| 30 | inline static bool isInstanciated() { return (ShellBuffer::singletonRef == NULL)?false:true; }; |
---|
[1853] | 31 | |
---|
[7374] | 32 | void registerShell(Shell* shell); |
---|
| 33 | void unregisterShell(Shell* shell); |
---|
[1853] | 34 | |
---|
[7374] | 35 | // BUFFER // |
---|
| 36 | /** @param bufferSize the new Buffer-Size */ |
---|
| 37 | void setBufferSize(unsigned int bufferSize) { this->bufferSize = bufferSize; }; |
---|
| 38 | void flush(); |
---|
| 39 | static bool addBufferLineStatic(const char* line, ...); |
---|
| 40 | void addBufferLine(const char* line, va_list arg); |
---|
| 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 long getLineCount() const { return this->lineCount; }; |
---|
[5206] | 45 | |
---|
[7374] | 46 | void debug() const; |
---|
[5173] | 47 | |
---|
[5174] | 48 | private: |
---|
| 49 | ShellBuffer(); |
---|
[5173] | 50 | |
---|
[5174] | 51 | private: |
---|
[5781] | 52 | static ShellBuffer* singletonRef; //!< The singleton-reference to the only memeber of this class. |
---|
| 53 | unsigned int bufferSize; //!< The Size of the buffer |
---|
[7315] | 54 | std::list<std::string> buffer; //!< A list of stored char-arrays(strings) to store the history |
---|
[5174] | 55 | |
---|
[5781] | 56 | Shell* shell; //!< the Registered Shell. |
---|
| 57 | char bufferArray[SHELL_BUFFER_SIZE]; //!< a BUFFER for fast writing |
---|
| 58 | char keepBufferArray[SHELL_BUFFER_SIZE]; //!< a BUFFER to have multi-non-newLine commands be copied into the shell. |
---|
| 59 | bool keepBuffer; //!< if the keepbuffer contains unfinished lines. |
---|
[5173] | 60 | |
---|
[5781] | 61 | unsigned long lineCount; //!< how many Lines have been written out so far. |
---|
[7314] | 62 | |
---|
| 63 | static SDL_mutex* bufferMutex; //!< Only one thread may write into the ShellBuffer at a time. |
---|
[7374] | 64 | }; |
---|
[1853] | 65 | |
---|
[7374] | 66 | } |
---|
| 67 | |
---|
[5173] | 68 | #endif /* _SHELL_BUFFER_H */ |
---|