Add new "Refresh guid" opcode, also add sample code to use it.

Signed-off-by: ydong10
Reviewed-by: lgao4


git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11767 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
ydong10 2011-06-08 08:09:47 +00:00
parent 5b127d7565
commit 211cc6e5cd
8 changed files with 363 additions and 66 deletions

View File

@ -20,10 +20,12 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
EFI_GUID mFormSetGuid = FORMSET_GUID;
EFI_GUID mInventoryGuid = INVENTORY_GUID;
EFI_GUID MyEventGroupGuid = EFI_IFR_REFRESH_ID_OP_GUID;
CHAR16 VariableName[] = L"MyIfrNVData";
EFI_HANDLE DriverHandle[2] = {NULL, NULL};
DRIVER_SAMPLE_PRIVATE_DATA *PrivateData = NULL;
EFI_EVENT mEvent;
HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath0 = {
{
@ -75,6 +77,158 @@ HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath1 = {
}
};
/**
Add empty function for event process function.
@param Event The Event need to be process
@param Context The context of the event.
**/
VOID
EFIAPI
DriverSampleInternalEmptyFunction (
IN EFI_EVENT Event,
IN VOID *Context
)
{
}
/**
Notification function for keystrokes.
@param[in] KeyData The key that was pressed.
@retval EFI_SUCCESS The operation was successful.
**/
EFI_STATUS
EFIAPI
NotificationFunction(
IN EFI_KEY_DATA *KeyData
)
{
gBS->SignalEvent (mEvent);
return EFI_SUCCESS;
}
/**
Function to start monitoring for CTRL-C using SimpleTextInputEx.
@retval EFI_SUCCESS The feature is enabled.
@retval EFI_OUT_OF_RESOURCES There is not enough mnemory available.
**/
EFI_STATUS
EFIAPI
InternalStartMonitor(
VOID
)
{
EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *SimpleEx;
EFI_KEY_DATA KeyData;
EFI_STATUS Status;
EFI_HANDLE *Handles;
UINTN HandleCount;
UINTN HandleIndex;
EFI_HANDLE NotifyHandle;
Status = gBS->LocateHandleBuffer (
ByProtocol,
&gEfiSimpleTextInputExProtocolGuid,
NULL,
&HandleCount,
&Handles
);
for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
Status = gBS->HandleProtocol (Handles[HandleIndex], &gEfiSimpleTextInputExProtocolGuid, (VOID **) &SimpleEx);
ASSERT_EFI_ERROR (Status);
KeyData.KeyState.KeyToggleState = 0;
KeyData.Key.ScanCode = 0;
KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_LEFT_CONTROL_PRESSED;
KeyData.Key.UnicodeChar = L'c';
Status = SimpleEx->RegisterKeyNotify(
SimpleEx,
&KeyData,
NotificationFunction,
&NotifyHandle);
if (EFI_ERROR (Status)) {
break;
}
KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_RIGHT_CONTROL_PRESSED;
Status = SimpleEx->RegisterKeyNotify(
SimpleEx,
&KeyData,
NotificationFunction,
&NotifyHandle);
if (EFI_ERROR (Status)) {
break;
}
}
return EFI_SUCCESS;
}
/**
Function to stop monitoring for CTRL-C using SimpleTextInputEx.
@retval EFI_SUCCESS The feature is enabled.
@retval EFI_OUT_OF_RESOURCES There is not enough mnemory available.
**/
EFI_STATUS
EFIAPI
InternalStopMonitor(
VOID
)
{
EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *SimpleEx;
EFI_STATUS Status;
EFI_HANDLE *Handles;
EFI_KEY_DATA KeyData;
UINTN HandleCount;
UINTN HandleIndex;
EFI_HANDLE NotifyHandle;
Status = gBS->LocateHandleBuffer (
ByProtocol,
&gEfiSimpleTextInputExProtocolGuid,
NULL,
&HandleCount,
&Handles
);
for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
Status = gBS->HandleProtocol (Handles[HandleIndex], &gEfiSimpleTextInputExProtocolGuid, (VOID **) &SimpleEx);
ASSERT_EFI_ERROR (Status);
KeyData.KeyState.KeyToggleState = 0;
KeyData.Key.ScanCode = 0;
KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_LEFT_CONTROL_PRESSED;
KeyData.Key.UnicodeChar = L'c';
Status = SimpleEx->RegisterKeyNotify(
SimpleEx,
&KeyData,
NotificationFunction,
&NotifyHandle);
if (!EFI_ERROR (Status)) {
Status = SimpleEx->UnregisterKeyNotify (SimpleEx, NotifyHandle);
}
KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_RIGHT_CONTROL_PRESSED;
Status = SimpleEx->RegisterKeyNotify(
SimpleEx,
&KeyData,
NotificationFunction,
&NotifyHandle);
if (!EFI_ERROR (Status)) {
Status = SimpleEx->UnregisterKeyNotify (SimpleEx, NotifyHandle);
}
}
return EFI_SUCCESS;
}
/**
Encode the password using a simple algorithm.
@ -1124,6 +1278,7 @@ DriverCallback (
EFI_INPUT_KEY Key;
DRIVER_SAMPLE_CONFIGURATION *Configuration;
UINTN MyVarSize;
EFI_FORM_ID FormId;
if (((Value == NULL) && (Action != EFI_BROWSER_ACTION_FORM_OPEN) && (Action != EFI_BROWSER_ACTION_FORM_CLOSE))||
(ActionRequest == NULL)) {
@ -1131,6 +1286,7 @@ DriverCallback (
}
FormId = 0;
Status = EFI_SUCCESS;
PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This);
@ -1177,6 +1333,11 @@ DriverCallback (
HiiFreeOpCodeHandle (StartOpCodeHandle);
}
if (QuestionId == 0x1247) {
Status = InternalStartMonitor ();
ASSERT_EFI_ERROR (Status);
}
}
break;
@ -1199,6 +1360,11 @@ DriverCallback (
);
} while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));
}
if (QuestionId == 0x1247) {
Status = InternalStopMonitor ();
ASSERT_EFI_ERROR (Status);
}
}
break;
@ -1424,6 +1590,7 @@ DriverCallback (
break;
case 0x5678:
case 0x1247:
//
// We will reach here once the Question is refreshed
//
@ -1439,7 +1606,15 @@ DriverCallback (
//
StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
if (QuestionId == 0x5678) {
StartLabel->Number = LABEL_UPDATE2;
FormId = 0x03;
PrivateData->Configuration.DynamicRefresh++;
} else if (QuestionId == 0x1247 ) {
StartLabel->Number = LABEL_UPDATE3;
FormId = 0x05;
PrivateData->Configuration.RefreshGuidCount++;
}
HiiCreateActionOpCode (
StartOpCodeHandle, // Container for dynamic created opcodes
@ -1453,7 +1628,7 @@ DriverCallback (
HiiUpdateForm (
PrivateData->HiiHandle[0], // HII handle
&mFormSetGuid, // Formset GUID
0x3, // Form ID
FormId, // Form ID
StartOpCodeHandle, // Label for where to insert opcodes
NULL // Insert data
);
@ -1463,7 +1638,6 @@ DriverCallback (
//
// Refresh the Question value
//
PrivateData->Configuration.DynamicRefresh++;
Status = gRT->SetVariable(
VariableName,
&mFormSetGuid,
@ -1472,6 +1646,7 @@ DriverCallback (
&PrivateData->Configuration
);
if (QuestionId == 0x5678) {
//
// Change an EFI Variable storage (MyEfiVar) asynchronous, this will cause
// the first statement in Form 3 be suppressed
@ -1485,6 +1660,7 @@ DriverCallback (
MyVarSize,
&MyVar
);
}
break;
case 0x1237:
@ -1805,7 +1981,15 @@ DriverSampleInit (
FreePool (ConfigRequestHdr);
Status = gBS->CreateEventEx (
EVT_NOTIFY_SIGNAL,
TPL_NOTIFY,
DriverSampleInternalEmptyFunction,
NULL,
&MyEventGroupGuid,
&mEvent
);
ASSERT_EFI_ERROR (Status);
//
// In default, this driver is built into Flash device image,
// the following code doesn't run.
@ -1893,5 +2077,7 @@ DriverSampleUnload (
FreePool (PrivateData);
PrivateData = NULL;
gBS->CloseEvent (mEvent);
return EFI_SUCCESS;
}

View File

@ -65,6 +65,7 @@
gEfiHiiConfigAccessProtocolGuid ## PRODUCES
gEfiFormBrowser2ProtocolGuid ## CONSUMES
gEfiHiiDatabaseProtocolGuid ## CONSUMES
gEfiSimpleTextInputExProtocolGuid ## CONSUMES
[Depex]

View File

@ -41,6 +41,11 @@ Revision History:
#define EFI_USER_INFO_ACCESS_SETUP_ADMIN_GUID \
{ 0x85b75607, 0xf7ce, 0x471e, { 0xb7, 0xe4, 0x2a, 0xea, 0x5f, 0x72, 0x32, 0xee } }
#define EFI_IFR_REFRESH_ID_OP_GUID \
{ \
0xF5E655D9, 0x02A6, 0x46f2, {0x9E, 0x76, 0xB8, 0xBE, 0x8E, 0x60, 0xAB, 0x22} \
}
#define CONFIGURATION_VARSTORE_ID 0x1234
#pragma pack(1)
@ -77,6 +82,7 @@ typedef struct {
UINT8 GetDefaultValueFromCallBack;
UINT8 GetDefaultValueFromAccess;
EFI_HII_TIME Time;
UINT8 RefreshGuidCount;
} DRIVER_SAMPLE_CONFIGURATION;
//
@ -93,6 +99,7 @@ typedef struct {
//
#define LABEL_UPDATE1 0x1234
#define LABEL_UPDATE2 0x2234
#define LABEL_UPDATE3 0x3234
#define LABEL_END 0x2223
#pragma pack()

View File

@ -2068,6 +2068,14 @@ ParseOpCodes (
CurrentStatement->RefreshInterval = ((EFI_IFR_REFRESH *) OpCodeData)->RefreshInterval;
break;
//
// Refresh guid.
//
case EFI_IFR_REFRESH_ID_OP:
ASSERT (CurrentStatement != NULL);
CopyMem (&CurrentStatement->RefreshGuid, &((EFI_IFR_REFRESH_ID *) OpCodeData)->RefreshEventGroupId, sizeof (EFI_GUID));
break;
//
// Modal tag
//

View File

@ -376,6 +376,7 @@ typedef struct {
EFI_QUESTION_ID RefQuestionId; // for EFI_IFR_REF2
EFI_GUID RefFormSetId; // for EFI_IFR_REF3
EFI_STRING_ID RefDevicePath; // for EFI_IFR_REF4
EFI_GUID RefreshGuid; // for EFI_IFR_REFRESH_ID
//
// Get from IFR parsing

View File

@ -16,7 +16,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
LIST_ENTRY gMenuOption;
LIST_ENTRY gMenuList = INITIALIZE_LIST_HEAD_VARIABLE (gMenuList);
MENU_REFRESH_ENTRY *gMenuRefreshHead;
MENU_REFRESH_ENTRY *gMenuRefreshHead; // Menu list used for refresh timer opcode.
MENU_REFRESH_ENTRY *gMenuEventGuidRefreshHead; // Menu list used for refresh event guid opcode.
//
// Search table for UiDisplayMenu()
@ -320,37 +321,34 @@ UiFreeRefreshList (
gMenuRefreshHead = OldMenuRefreshEntry;
}
gMenuRefreshHead = NULL;
while (gMenuEventGuidRefreshHead != NULL) {
OldMenuRefreshEntry = gMenuEventGuidRefreshHead->Next;
if (gMenuEventGuidRefreshHead != NULL) {
gBS->CloseEvent(gMenuEventGuidRefreshHead->Event);
}
FreePool (gMenuEventGuidRefreshHead);
gMenuEventGuidRefreshHead = OldMenuRefreshEntry;
}
}
/**
Refresh screen.
Refresh question.
@param MenuRefreshEntry Menu refresh structure which has info about the refresh question.
**/
EFI_STATUS
RefreshForm (
VOID
RefreshQuestion (
IN MENU_REFRESH_ENTRY *MenuRefreshEntry
)
{
CHAR16 *OptionString;
MENU_REFRESH_ENTRY *MenuRefreshEntry;
UINTN Index;
EFI_STATUS Status;
UI_MENU_SELECTION *Selection;
FORM_BROWSER_STATEMENT *Question;
if (gMenuRefreshHead != NULL) {
MenuRefreshEntry = gMenuRefreshHead;
//
// Reset FormPackage update flag
//
mHiiPackageListUpdated = FALSE;
do {
Selection = MenuRefreshEntry->Selection;
Question = MenuRefreshEntry->MenuOption->ThisTag;
@ -392,7 +390,73 @@ RefreshForm (
//
// Question value may be changed, need invoke its Callback()
//
Status = ProcessCallBackFunction(Selection, Question, EFI_BROWSER_ACTION_CHANGING, FALSE);
Status = ProcessCallBackFunction (Selection, Question, EFI_BROWSER_ACTION_CHANGING, FALSE);
return Status;
}
/**
Refresh the question which has refresh guid event attribute.
@param Event The event which has this function related.
@param Context The input context info related to this event or the status code return to the caller.
**/
VOID
RefreshQuestionNotify(
IN EFI_EVENT Event,
IN VOID *Context
)
{
MENU_REFRESH_ENTRY *MenuRefreshEntry;
UI_MENU_SELECTION *Selection;
//
// Reset FormPackage update flag
//
mHiiPackageListUpdated = FALSE;
MenuRefreshEntry = (MENU_REFRESH_ENTRY *)Context;
ASSERT (MenuRefreshEntry != NULL);
Selection = MenuRefreshEntry->Selection;
RefreshQuestion (MenuRefreshEntry);
if (mHiiPackageListUpdated) {
//
// Package list is updated, force to reparse IFR binary of target Formset
//
mHiiPackageListUpdated = FALSE;
Selection->Action = UI_ACTION_REFRESH_FORMSET;
}
}
/**
Refresh screen.
**/
EFI_STATUS
RefreshForm (
VOID
)
{
MENU_REFRESH_ENTRY *MenuRefreshEntry;
EFI_STATUS Status;
UI_MENU_SELECTION *Selection;
if (gMenuRefreshHead != NULL) {
//
// call from refresh interval process.
//
MenuRefreshEntry = gMenuRefreshHead;
Selection = MenuRefreshEntry->Selection;
//
// Reset FormPackage update flag
//
mHiiPackageListUpdated = FALSE;
do {
Status = RefreshQuestion (MenuRefreshEntry);
if (EFI_ERROR (Status)) {
return Status;
}
@ -1636,6 +1700,7 @@ UiDisplayMenu (
UI_CONTROL_FLAG ControlFlag;
EFI_SCREEN_DESCRIPTOR LocalScreen;
MENU_REFRESH_ENTRY *MenuRefreshEntry;
MENU_REFRESH_ENTRY *MenuUpdateEntry;
UI_SCREEN_OPERATION ScreenOperation;
UINT8 MinRefreshInterval;
UINTN BufferSize;
@ -1872,6 +1937,34 @@ UiDisplayMenu (
OptionString[Count] = CHAR_NULL;
}
//
// If Question has refresh guid, register the op-code.
//
if (!CompareGuid (&Statement->RefreshGuid, &gZeroGuid)) {
if (gMenuEventGuidRefreshHead == NULL) {
MenuUpdateEntry = AllocateZeroPool (sizeof (MENU_REFRESH_ENTRY));
gMenuEventGuidRefreshHead = MenuUpdateEntry;
} else {
MenuUpdateEntry = gMenuEventGuidRefreshHead;
while (MenuUpdateEntry->Next != NULL) {
MenuUpdateEntry = MenuUpdateEntry->Next;
}
MenuUpdateEntry->Next = AllocateZeroPool (sizeof (MENU_REFRESH_ENTRY));
}
ASSERT (MenuUpdateEntry != NULL);
Status = gBS->CreateEventEx (EVT_NOTIFY_SIGNAL, TPL_NOTIFY, RefreshQuestionNotify, MenuUpdateEntry, &Statement->RefreshGuid, &MenuUpdateEntry->Event);
ASSERT (!EFI_ERROR (Status));
MenuUpdateEntry->MenuOption = MenuOption;
MenuUpdateEntry->Selection = Selection;
MenuUpdateEntry->CurrentColumn = MenuOption->OptCol;
MenuUpdateEntry->CurrentRow = MenuOption->Row;
if (MenuOption->GrayOut) {
MenuUpdateEntry->CurrentAttribute = FIELD_TEXT_GRAYED | FIELD_BACKGROUND;
} else {
MenuUpdateEntry->CurrentAttribute = PcdGet8 (PcdBrowserFieldTextColor) | FIELD_BACKGROUND;
}
}
//
// If Question request refresh, register the op-code
//

View File

@ -178,6 +178,7 @@ struct _MENU_REFRESH_ENTRY {
UINTN CurrentColumn;
UINTN CurrentRow;
UINTN CurrentAttribute;
EFI_EVENT Event;
};
typedef struct {