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