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 DISABLED_INIT = 4, ///< the console remains disabled during boot
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;
83 * Disables the stdout, stdin, and stderr console.
85 static void disable_all();
87 /// stdout for libc glue.
88 static Console *stdout;
89 /// stderr for libc glue.
90 static Console *stderr;
91 /// stdin for libc glue.
92 static Console *stdin;
98 void *operator new (size_t, void *p) throw() { return p; }
108 Console *Console::stdout;
109 Console *Console::stderr;
110 Console *Console::stdin;
112 IMPLEMENT Console::~Console()
116 * get current console state
120 Console::state() const
126 void Console::state(Mword new_state)
133 Console::failed() const
135 return _state & FAILED;
146 void Console::disable_all()
154 int Console::write(char const *, size_t len)
160 int Console::getchar(bool /* blocking */)
162 return -1; /* no input */
166 int Console::char_avail() const
168 return -1; /* unknown */
172 Mword Console::get_attributes() const
177 IMPLEMENTATION[debug]:
181 Console::str_mode() const
183 static char const * const mode_str[] =
184 { " ", "Output", "Input ", "InOut " };
185 return mode_str[get_attributes() & (OUT|IN)];
190 Console::str_state() const
192 static char const * const state_str[] =
193 { "Disabled ", "Output disabled",
194 "Input disabled ", "Enabled " };
195 return state_str[state() & (INENABLED|OUTENABLED)];
200 Console::str_attr(Mword bit) const
202 static char const * const attr_str[] =
203 { "Direct", "Uart", "UX", "Push", "Gzip", "Buffer", "Kdb", "FAILED!" };
205 return (bit < 2 || bit >= (sizeof(attr_str)/sizeof(attr_str[0]))+2)