StuBS
Loading...
Searching...
No Matches
Keyboard Class Reference

Handles keystrokes. More...

#include <keyboard.h>

Inheritance diagram for Keyboard:
Collaboration diagram for Keyboard:

Public Member Functions

 Keyboard ()
 Constructor.
 
void plugin ()
 Initialization of the keyboard.
 
bool prologue () override
 Prologue of keyboard interrupts.
 
void epilogue () override
 Epilogue of keyboard interrupts.
 
Key getKey ()
 Application interface to retrieve a Key.
 
- Public Member Functions inherited from Gate
 Gate ()
 Constructor.
 
virtual ~Gate ()
 Destructor.
 

Private Attributes

Key current_key
 Buffer (with length = 1) for pressed keys.
 
Semaphore key_available
 Semaphore to signal an available key.
 

Detailed Description

Handles keystrokes.

This class ensures correct initialization of the keyboard and, above all, its interrupt handling. It also allows an application to query it for key strokes.

Member Function Documentation

◆ epilogue()

void Keyboard::epilogue ( )
overridevirtual

Epilogue of keyboard interrupts.

The occurrence of a keystroke is signaled to a possibly waiting thread. For this purpose, a semaphore is used whose counter indicates how many keys are available in the keyboard buffer for retrieval.

Reimplemented from Gate.

◆ getKey()

Key Keyboard::getKey ( )

Application interface to retrieve a Key.

This method returns the last pressed key (as an Key object). If no key has been pressed, the calling application thread is blocked until a key is available – this is achieved by using a Semaphore.

Returns
Pressed key

◆ plugin()

void Keyboard::plugin ( )

Initialization of the keyboard.

Initialization of the keyboard and activation of the specific interrupt handling: The object will register itself at the Plugbox and configure the IOAPIC to receive the corresponding interrupts.

Note
The keyboard interrupts should be configured as level triggered. According to the standard we would have to check the corresponding entry in ACPI::MADS::Interrupt_Source_Override and use these values. Most likely this would suggest an edge-triggered mode – which would work as well. However, using a level-triggered mode is more forgiving because it resends the interrupt request even if an interrupt was lost (e.g. the required handling, retrieving the buffer entry, was not performed).

◆ prologue()

bool Keyboard::prologue ( )
overridevirtual

Prologue of keyboard interrupts.

This method directly handles interrupts caused by the keyboard. Since multiple interrupts are triggered on a keystroke (press & release) it produces not always a printable ASCII character – therefore only valid keys are handled in the Keyboard::epilogue.

Since the buffer is limited, it also ensures that a valid key is not overwritten by a subsequent prologue before it was handled in the Keyboard::epilogue.

Note
If a keystroke would exceed the buffer, the new key is dropped – previous keystrokes have a higher priority in the buffer.
Returns
true if a new Key was stored in the buffer and has to be processed in the Keyboard::epilogue.

Implements Gate.


The documentation for this class was generated from the following files: