/** Reads the next keystroke from the input device. The WaitForKey Event can be used to test for existence of a keystroke via WaitForEvent () call. @param TerminalDevice Terminal driver private structure @param KeyData A pointer to a buffer that is filled in with the keystroke state data for the key that was pressed. @retval EFI_SUCCESS The keystroke information was returned. @retval EFI_NOT_READY There was no keystroke data available. @retval EFI_DEVICE_ERROR The keystroke information was not returned due to hardware errors. @retval EFI_INVALID_PARAMETER KeyData is NULL. **/ EFI_STATUS ReadKeyStrokeWorker ( IN TERMINAL_DEV *TerminalDevice, OUT EFI_KEY_DATA *KeyData ) { EFI_STATUS Status; LIST_ENTRY *Link; LIST_ENTRY *NotifyList; TERMINAL_CONSOLE_IN_EX_NOTIFY *CurrentNotify; if (KeyData == NULL) { return EFI_INVALID_PARAMETER; } // // Initialize *Key to nonsense value. // KeyData->Key.ScanCode = SCAN_NULL; KeyData->Key.UnicodeChar = 0; Status = TerminalConInCheckForKey (&TerminalDevice->SimpleInput); if (EFI_ERROR (Status)) { return EFI_NOT_READY; } if (!EfiKeyFiFoRemoveOneKey (TerminalDevice, &KeyData->Key)) { return EFI_NOT_READY; } KeyData->KeyState.KeyShiftState = 0; KeyData->KeyState.KeyToggleState = 0; // // Invoke notification functions if exist // NotifyList = &TerminalDevice->NotifyList; for (Link = GetFirstNode (NotifyList); !IsNull (NotifyList,Link); Link = GetNextNode (NotifyList,Link)) { CurrentNotify = CR ( Link, TERMINAL_CONSOLE_IN_EX_NOTIFY, NotifyEntry, TERMINAL_CONSOLE_IN_EX_NOTIFY_SIGNATURE ); if (IsKeyRegistered (&CurrentNotify->KeyData, KeyData)) { CurrentNotify->KeyNotificationFn (KeyData); } } return EFI_SUCCESS; }
/** Insert one pre-fetched key into the FIFO buffer. @param TerminalDevice Terminal driver private structure. @param Key The key will be input. @retval TRUE If insert successfully. @retval FLASE If FIFO buffer is full before key insertion, and the key is lost. **/ BOOLEAN EfiKeyFiFoInsertOneKey ( TERMINAL_DEV *TerminalDevice, EFI_INPUT_KEY *Key ) { UINT8 Tail; LIST_ENTRY *Link; LIST_ENTRY *NotifyList; TERMINAL_CONSOLE_IN_EX_NOTIFY *CurrentNotify; EFI_KEY_DATA KeyData; Tail = TerminalDevice->EfiKeyFiFo->Tail; CopyMem (&KeyData.Key, Key, sizeof (EFI_INPUT_KEY)); KeyData.KeyState.KeyShiftState = 0; KeyData.KeyState.KeyToggleState = 0; // // Invoke notification functions if exist // NotifyList = &TerminalDevice->NotifyList; for (Link = GetFirstNode (NotifyList); !IsNull (NotifyList,Link); Link = GetNextNode (NotifyList,Link)) { CurrentNotify = CR ( Link, TERMINAL_CONSOLE_IN_EX_NOTIFY, NotifyEntry, TERMINAL_CONSOLE_IN_EX_NOTIFY_SIGNATURE ); if (IsKeyRegistered (&CurrentNotify->KeyData, &KeyData)) { CurrentNotify->KeyNotificationFn (&KeyData); } } if (IsEfiKeyFiFoFull (TerminalDevice)) { // // Efi Key FIFO is full // return FALSE; } CopyMem (&TerminalDevice->EfiKeyFiFo->Data[Tail], Key, sizeof (EFI_INPUT_KEY)); TerminalDevice->EfiKeyFiFo->Tail = (UINT8) ((Tail + 1) % (FIFO_MAX_NUMBER + 1)); return TRUE; }