Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/shell/shell_buffer.h @ 7487

Last change on this file since 7487 was 7374, checked in by bensch, 19 years ago

orxonox/trunk: added new Files shell_completion_plugin for the new Plugin Structure.
Also created the first namespace: OrxShell

File size: 2.6 KB
Line 
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 "threading.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
16namespace OrxShell
17{
18  // FORWARD DECLARATION
19  class Shell;
20
21  //! A class handling output from orxonox via debug.h
22  class ShellBuffer
23  {
24
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 */
30inline static bool isInstanciated() { return (ShellBuffer::singletonRef == NULL)?false:true; };
31
32    void registerShell(Shell* shell);
33    void unregisterShell(Shell* shell);
34
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; };
45
46    void debug() const;
47
48  private:
49    ShellBuffer();
50
51  private:
52    static ShellBuffer*      singletonRef;                       //!< The singleton-reference to the only memeber of this class.
53    unsigned int             bufferSize;                         //!< The Size of the buffer
54    std::list<std::string>   buffer;                             //!< A list of stored char-arrays(strings) to store the history
55
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.
60
61    unsigned long            lineCount;                          //!< how many Lines have been written out so far.
62
63    static SDL_mutex*        bufferMutex;                        //!< Only one thread may write into the ShellBuffer at a time.
64  };
65
66}
67
68#endif /* _SHELL_BUFFER_H */
Note: See TracBrowser for help on using the repository browser.