7 * The abstract interface for a text I/O console.
9 * This abstract interface can be implemented for virtually every
10 * text input or output device.
18 INENABLED = 1, ///< output channel of console enabled
19 OUTENABLED = 2, ///< input channel of console enabled
20 ENABLED = INENABLED | OUTENABLED ///< console fully enabled
25 // universal attributes
27 OUT = 0x1, ///< output to console is possible
28 IN = 0x2, ///< input from console is possible
29 // attributes to identify a specific console
30 DIRECT = 0x4, ///< output to screen or input from keyboard
31 UART = 0x8, ///< output to/input from serial serial line
32 UX = 0x10, ///< filtered input console for UX
33 PUSH = 0x20, ///< input console
34 GZIP = 0x40, ///< gzip+uuencode output and sent to uart console
35 BUFFER = 0x80, ///< ring buffer
36 DEBUG = 0x100, ///< kdb interface
37 FAILED = 0x200, ///< initialization failed
41 * modify console state
43 virtual void state(Mword new_state);
46 * Write a string of len chacters to the output.
47 * @param str the string to write (no zero termination is needed)
48 * @param len the number of chacters to write.
50 * This method must be implemented in every implementation, but
51 * can simply do nothing for input only consoles.
53 virtual int write(char const *str, size_t len);
56 * read a charcater from the input.
57 * @param blocking if true getchar blocks til a charcater is available.
59 * This method must be implemented in every implementation, but
60 * can simply return -1 for output only consoles.
62 virtual int getchar(bool blocking = true);
67 * This method can be implemented.
68 * It must return -1 if no information is available,
69 * 1 if at least one character is avialable, and 0 if
70 * no charachter is available.
72 virtual int char_avail() const;
77 virtual Mword get_attributes() const;
81 explicit Console(Console_state state) : _state(state) {}
83 void add_state(Console_state state)
86 void del_state(Console_state state)
91 * Disables the stdout, stdin, and stderr console.
93 static void disable_all();
95 /// stdout for libc glue.
96 static Console *stdout;
97 /// stderr for libc glue.
98 static Console *stderr;
99 /// stdin for libc glue.
100 static Console *stdin;
113 Console *Console::stdout;
114 Console *Console::stderr;
115 Console *Console::stdin;
117 IMPLEMENT Console::~Console()
121 * get current console state
125 Console::state() const
131 void Console::state(Mword new_state)
138 Console::failed() const
140 return _state & FAILED;
151 void Console::disable_all()
159 int Console::write(char const *, size_t len)
165 int Console::getchar(bool /* blocking */)
167 return -1; /* no input */
171 int Console::char_avail() const
173 return -1; /* unknown */
177 Mword Console::get_attributes() const
182 IMPLEMENTATION[debug]:
186 Console::str_mode() const
188 static char const * const mode_str[] =
189 { " ", "Output", "Input ", "InOut " };
190 return mode_str[get_attributes() & (OUT|IN)];
195 Console::str_state() const
197 static char const * const state_str[] =
198 { "Disabled ", "Output disabled",
199 "Input disabled ", "Enabled " };
200 return state_str[state() & ENABLED];
205 Console::str_attr(Mword bit) const
207 static char const * const attr_str[] =
208 { "Direct", "Uart", "UX", "Push", "Gzip", "Buffer", "Kdb", "FAILED!" };
210 return (bit < 2 || bit >= (sizeof(attr_str)/sizeof(attr_str[0]))+2)