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 <stdarg.h> |
---|
11 | #include <list> |
---|
12 | #include <SDL_thread.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 | // FORWARD DECLARATION |
---|
17 | class Shell; |
---|
18 | |
---|
19 | #ifndef NULL |
---|
20 | #define NULL 0 //!< a pointer to NULL |
---|
21 | #endif |
---|
22 | |
---|
23 | //! A class handling output from orxonox via debug.h |
---|
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 | void registerShell(Shell* shell); |
---|
34 | void unregisterShell(Shell* shell); |
---|
35 | |
---|
36 | // BUFFER // |
---|
37 | /** @param bufferSize the new Buffer-Size */ |
---|
38 | void setBufferSize(unsigned int bufferSize) { this->bufferSize = bufferSize; }; |
---|
39 | void flush(); |
---|
40 | static bool addBufferLineStatic(const char* line, ...); |
---|
41 | void addBufferLine(const char* line, va_list arg); |
---|
42 | /** @returns the List of stings from the Buffer */ |
---|
43 | const std::list<std::string>& getBuffer() const { return this->buffer; }; |
---|
44 | /** @returns the Count of lines processed by the Shell. */ |
---|
45 | inline long getLineCount() const { return this->lineCount; }; |
---|
46 | |
---|
47 | void debug() const; |
---|
48 | |
---|
49 | private: |
---|
50 | ShellBuffer(); |
---|
51 | |
---|
52 | private: |
---|
53 | static ShellBuffer* singletonRef; //!< The singleton-reference to the only memeber of this class. |
---|
54 | unsigned int bufferSize; //!< The Size of the buffer |
---|
55 | std::list<std::string> buffer; //!< A list of stored char-arrays(strings) to store the history |
---|
56 | |
---|
57 | Shell* shell; //!< the Registered Shell. |
---|
58 | char bufferArray[SHELL_BUFFER_SIZE]; //!< a BUFFER for fast writing |
---|
59 | char keepBufferArray[SHELL_BUFFER_SIZE]; //!< a BUFFER to have multi-non-newLine commands be copied into the shell. |
---|
60 | bool keepBuffer; //!< if the keepbuffer contains unfinished lines. |
---|
61 | |
---|
62 | unsigned long lineCount; //!< how many Lines have been written out so far. |
---|
63 | |
---|
64 | static SDL_mutex* bufferMutex; //!< Only one thread may write into the ShellBuffer at a time. |
---|
65 | }; |
---|
66 | |
---|
67 | #endif /* _SHELL_BUFFER_H */ |
---|