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
The class Keyboard represents the abstraction of the keyboard. It takes care of the correct initialization and especially the interrupt handling. In addition, the 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 the interrupts from the keyboard.
Since several interrupts are triggered with each keystroke,
an usable ASCII code cannot be expected in every case.
Only if the method key_hit of the 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. If Ctrl-Alt-Delete was pressed, a reboot should be triggered. 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, a semaphore is used 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.