mirror of
https://github.com/ipxe/ipxe
synced 2025-12-19 19:49:45 +03:00
[console] Allow console input and output to be disabled independently
Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -11,15 +11,12 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
||||
int console_usage = CONSOLE_USAGE_STDOUT;
|
||||
|
||||
/**
|
||||
* Write a single character to each console device.
|
||||
* Write a single character to each console device
|
||||
*
|
||||
* @v character Character to be written
|
||||
* @ret None -
|
||||
* @err None -
|
||||
*
|
||||
* The character is written out to all enabled console devices, using
|
||||
* each device's console_driver::putchar() method.
|
||||
*
|
||||
*/
|
||||
void putchar ( int character ) {
|
||||
struct console_driver *console;
|
||||
@@ -29,7 +26,7 @@ void putchar ( int character ) {
|
||||
putchar ( '\r' );
|
||||
|
||||
for_each_table_entry ( console, CONSOLES ) {
|
||||
if ( ( ! console->disabled ) &&
|
||||
if ( ( ! ( console->disabled & CONSOLE_DISABLED_OUTPUT ) ) &&
|
||||
( console_usage & console->usage ) &&
|
||||
console->putchar )
|
||||
console->putchar ( character );
|
||||
@@ -37,23 +34,20 @@ void putchar ( int character ) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if any input is available on any console.
|
||||
* Check to see if any input is available on any console
|
||||
*
|
||||
* @v None -
|
||||
* @ret console Console device that has input available, if any.
|
||||
* @ret NULL No console device has input available.
|
||||
* @err None -
|
||||
* @ret console Console device that has input available, or NULL
|
||||
*
|
||||
* All enabled console devices are checked once for available input
|
||||
* using each device's console_driver::iskey() method. The first
|
||||
* console device that has available input will be returned, if any.
|
||||
*
|
||||
*/
|
||||
static struct console_driver * has_input ( void ) {
|
||||
struct console_driver *console;
|
||||
|
||||
for_each_table_entry ( console, CONSOLES ) {
|
||||
if ( ( ! console->disabled ) && console->iskey ) {
|
||||
if ( ( ! ( console->disabled & CONSOLE_DISABLED_INPUT ) ) &&
|
||||
console->iskey ) {
|
||||
if ( console->iskey () )
|
||||
return console;
|
||||
}
|
||||
@@ -62,11 +56,9 @@ static struct console_driver * has_input ( void ) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a single character from any console.
|
||||
* Read a single character from any console
|
||||
*
|
||||
* @v None -
|
||||
* @ret character Character read from a console.
|
||||
* @err None -
|
||||
*
|
||||
* A character will be read from the first enabled console device that
|
||||
* has input available using that console's console_driver::getchar()
|
||||
@@ -80,7 +72,6 @@ static struct console_driver * has_input ( void ) {
|
||||
* @endcode
|
||||
*
|
||||
* The character read will not be echoed back to any console.
|
||||
*
|
||||
*/
|
||||
int getchar ( void ) {
|
||||
struct console_driver *console;
|
||||
@@ -116,19 +107,16 @@ int getchar ( void ) {
|
||||
return character;
|
||||
}
|
||||
|
||||
/** Check for available input on any console.
|
||||
/**
|
||||
* Check for available input on any console
|
||||
*
|
||||
* @v None -
|
||||
* @ret True Input is available on a console
|
||||
* @ret False Input is not available on any console
|
||||
* @err None -
|
||||
* @ret is_available Input is available on a console
|
||||
*
|
||||
* All enabled console devices are checked once for available input
|
||||
* using each device's console_driver::iskey() method. If any console
|
||||
* device has input available, this call will return True. If this
|
||||
* call returns True, you can then safely call getchar() without
|
||||
* device has input available, this call will return true. If this
|
||||
* call returns true, you can then safely call getchar() without
|
||||
* blocking.
|
||||
*
|
||||
*/
|
||||
int iskey ( void ) {
|
||||
return has_input() ? 1 : 0;
|
||||
|
||||
@@ -30,7 +30,7 @@ struct console_driver serial_console __console_driver = {
|
||||
.putchar = serial_putc,
|
||||
.getchar = serial_getc,
|
||||
.iskey = serial_ischar,
|
||||
.disabled = 1,
|
||||
.disabled = CONSOLE_DISABLED,
|
||||
.usage = CONSOLE_SERIAL,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user