Class Keyboard

Class Keyboard

Placement in the overall structure

Module
device
Base classes
Gate
Keyboard_Controller
Derived classes
Guarded_Keyboard
Time of creation
Task 2
Modified in
Task 3
Task 6
Files
keyboard.h keyboard.cc

Description

Class Keyboard represents the abstraction of the keyboard. It takes care of the correct initialization and especially the interrupt handling. In addition, class Keyboard allows the keyboard input to be retrieved by the application.

Public methods

void plugin ()
"Plugs in" the keyboard (driver). From now on, keypresses are handled. To do this, the keyboard object must register at the Plugbox object plugbox and tell the PIC object pic that interrupts of the keyboard should from now on be reported to the processor.
bool prologue ()
This method responds to interrupts from the keyboard. Since several interrupts are triggered with each keystroke, a usable ASCII code cannot be expected in every case. Only if the method key_hit of base class Keyboard_Controller returns a valid Key, a complete scan code could be determined. For "normal" keys then a non-zero ASCII code exists.

If a valid key code could be determined, it should be stored in a private variable of the class. When the user inputs Ctrl-Alt-Delete, the system should reboot. In case of other valid keyboard codes the handling shall be continued in the epilogue.

void epilogue ()
In this method, the occurrence of the keypress should be signaled to a possibly waiting process. For this purpose, use a semaphore whose counter indicates how many keyboard codes are available for fetching in the keyboard buffer. If a buffer entry has to be overwritten without the old value having been fetched by an application process, the semaphore must therefore not be incremented.
Key getkey ()
This method returns the last key pressed (as an object of the Key class). If no key was pressed at the moment, the calling application process is blocked until then. This is achieved by using a semaphore. Once the key code has been fetched, it should be noted that the buffer is now available for the next key code.

Implementation notes

The size of the keyboard buffer determines how often the user can "blindly" press keys. For our purposes, a one-element keyboard buffer is sufficient.