]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg: Add sample code for keyword handler protocol.
authorEric Dong <eric.dong@intel.com>
Wed, 13 May 2015 08:45:21 +0000 (08:45 +0000)
committerydong10 <ydong10@Edk2>
Wed, 13 May 2015 08:45:21 +0000 (08:45 +0000)
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Eric Dong <eric.dong@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
Reviewed-by: Samer El-Haj-Mahmoud <samer.el-haj-mahmoud@hp.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17431 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c
MdeModulePkg/Universal/DriverSampleDxe/DriverSample.h
MdeModulePkg/Universal/DriverSampleDxe/DriverSampleDxe.inf
MdeModulePkg/Universal/DriverSampleDxe/Inventory.vfr
MdeModulePkg/Universal/DriverSampleDxe/Vfr.vfr
MdeModulePkg/Universal/DriverSampleDxe/VfrStrings.uni

index 204c043ff45e9617935f68aadb8ef9f9e1f72079..22b6b265ee9c3d83e2ccb47ddf648675496f9d2b 100644 (file)
@@ -2,7 +2,7 @@
 This is an example of how a driver might export data to the HII protocol to be\r
 later utilized by the Setup Protocol\r
 \r
-Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -1279,6 +1279,10 @@ DriverCallback (
   DRIVER_SAMPLE_CONFIGURATION     *Configuration;\r
   MY_EFI_VARSTORE_DATA            *EfiData;\r
   EFI_FORM_ID                     FormId;\r
+  EFI_STRING                      Progress;\r
+  EFI_STRING                      Results;\r
+  UINT32                          ProgressErr;\r
+  CHAR16                          *TmpStr;\r
   \r
   if (((Value == NULL) && (Action != EFI_BROWSER_ACTION_FORM_OPEN) && (Action != EFI_BROWSER_ACTION_FORM_CLOSE))||\r
     (ActionRequest == NULL)) {\r
@@ -1287,6 +1291,7 @@ DriverCallback (
 \r
 \r
   FormId = 0;\r
+  ProgressErr = 0;\r
   Status = EFI_SUCCESS;\r
   PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This);\r
 \r
@@ -1753,7 +1758,78 @@ DriverCallback (
         //\r
         *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT;\r
         break;\r
+\r
+      case 0x1231:\r
+        //\r
+        // 1. Check to see whether system support keyword.\r
+        //\r
+        Status = PrivateData->HiiKeywordHandler->GetData (PrivateData->HiiKeywordHandler,\r
+                                                          L"NAMESPACE=x-UEFI-ns",\r
+                                                          L"KEYWORD=iSCSIBootEnable",\r
+                                                          &Progress,\r
+                                                          &ProgressErr,\r
+                                                          &Results\r
+                                                         );\r
+        if (EFI_ERROR (Status)) {\r
+          do {\r
+            CreatePopUp (\r
+              EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
+              &Key,\r
+              L"",\r
+              L"This system not support this keyword!",\r
+              L"Press ENTER to continue ...",\r
+              L"",\r
+              NULL\r
+              );\r
+          } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
+\r
+          Status = EFI_SUCCESS;\r
+          break;\r
+        }\r
+\r
+        //\r
+        // 2. If system support this keyword, just try to change value.\r
+        //\r
         \r
+        //\r
+        // Change value from '0' to '1' or from '1' to '0'\r
+        //\r
+        TmpStr = StrStr (Results, L"&VALUE=");\r
+        ASSERT (TmpStr != NULL);\r
+        TmpStr += StrLen (L"&VALUE=");\r
+        TmpStr++;\r
+        if (*TmpStr == L'0') {\r
+          *TmpStr = L'1';\r
+        } else {\r
+          *TmpStr = L'0';\r
+        }\r
+\r
+        //\r
+        // 3. Call the keyword handler protocol to change the value.\r
+        //\r
+        Status = PrivateData->HiiKeywordHandler->SetData (PrivateData->HiiKeywordHandler,\r
+                                                          Results,\r
+                                                          &Progress,\r
+                                                          &ProgressErr\r
+                                                         );\r
+        if (EFI_ERROR (Status)) {\r
+          do {\r
+            CreatePopUp (\r
+              EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
+              &Key,\r
+              L"",\r
+              L"Set keyword to the system failed!",\r
+              L"Press ENTER to continue ...",\r
+              L"",\r
+              NULL\r
+              );\r
+          } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
+\r
+          Status = EFI_SUCCESS;\r
+          break;\r
+        }\r
+        break;\r
+\r
       default:\r
       break;\r
     }\r
@@ -1790,6 +1866,7 @@ DriverSampleInit (
   EFI_HII_STRING_PROTOCOL         *HiiString;\r
   EFI_FORM_BROWSER2_PROTOCOL      *FormBrowser2;\r
   EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting;\r
+  EFI_CONFIG_KEYWORD_HANDLER_PROTOCOL *HiiKeywordHandler;\r
   CHAR16                          *NewString;\r
   UINTN                           BufferSize;\r
   DRIVER_SAMPLE_CONFIGURATION     *Configuration;\r
@@ -1867,6 +1944,15 @@ DriverSampleInit (
   }\r
   PrivateData->HiiConfigRouting = HiiConfigRouting;\r
 \r
+  //\r
+  // Locate keyword handler protocol\r
+  //\r
+  Status = gBS->LocateProtocol (&gEfiConfigKeywordHandlerProtocolGuid, NULL, (VOID **) &HiiKeywordHandler);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  PrivateData->HiiKeywordHandler = HiiKeywordHandler;\r
+\r
   Status = gBS->InstallMultipleProtocolInterfaces (\r
                   &DriverHandle[0],\r
                   &gEfiDevicePathProtocolGuid,\r
@@ -1902,6 +1988,8 @@ DriverSampleInit (
                   &DriverHandle[1],\r
                   &gEfiDevicePathProtocolGuid,\r
                   &mHiiVendorDevicePath1,\r
+                  &gEfiHiiConfigAccessProtocolGuid,\r
+                  &PrivateData->ConfigAccess,\r
                   NULL\r
                   );\r
   ASSERT_EFI_ERROR (Status);\r
index 29870c0f1f1e2b8ec5663df5c15063589dbf5610..97dee9c79a31c6bd3e6701e0dc7323b8559bb888 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-Copyright (c) 2007 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -32,6 +32,7 @@ Revision History
 #include <Protocol/HiiDatabase.h>\r
 #include <Protocol/HiiString.h>\r
 #include <Protocol/FormBrowserEx.h>\r
+#include <Protocol/HiiConfigKeyword.h>\r
 \r
 #include <Guid/MdeModuleHii.h>\r
 #include <Library/DebugLib.h>\r
@@ -97,6 +98,8 @@ typedef struct {
   EFI_HII_DATABASE_PROTOCOL        *HiiDatabase;\r
   EFI_HII_STRING_PROTOCOL          *HiiString;\r
   EFI_HII_CONFIG_ROUTING_PROTOCOL  *HiiConfigRouting;\r
+  EFI_CONFIG_KEYWORD_HANDLER_PROTOCOL *HiiKeywordHandler;\r
+\r
   EFI_FORM_BROWSER2_PROTOCOL       *FormBrowser2;\r
 \r
   //\r
index 307c4c3dde8c425d1a6b264a069638200a19ec3d..f5c0b4670b30246682d2145b931182ce3364f9f1 100644 (file)
@@ -4,7 +4,7 @@
 # This driver shows how HII protocol, VFR and UNI files are used to create a HII \r
 # driver which can be dipslayed and configured by a UEFI HII Form Browser.\r
 #\r
-# Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>\r
 #\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -92,6 +92,7 @@
   gEfiHiiDatabaseProtocolGuid                   ## CONSUMES\r
   gEfiSimpleTextInputExProtocolGuid             ## SOMETIMES_CONSUMES\r
   gEfiFormBrowserExProtocolGuid                 ## CONSUMES\r
+  gEfiConfigKeywordHandlerProtocolGuid          ## CONSUMES\r
 \r
 [Depex]\r
   gEfiSimpleTextOutProtocolGuid AND gEfiHiiDatabaseProtocolGuid AND gEfiVariableArchProtocolGuid AND gEfiVariableWriteArchProtocolGuid\r
index b835dfc3929125e70dbb1abcdbe05399434befb3..b5b93d4c86fdf5d4650865231c732b141452c121 100644 (file)
@@ -2,7 +2,7 @@
 //\r
 //    Sample Inventory Data\r
 //\r
-//  Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>\r
+//  Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>\r
 //  This program and the accompanying materials\r
 //  are licensed and made available under the terms and conditions of the BSD License\r
 //  which accompanies this distribution.  The full text of the license may be found at\r
@@ -104,6 +104,12 @@ formset
       flags  = 0,\r
       key    = 0;\r
 \r
+    text\r
+      help   = STRING_TOKEN(STR_CHECK_KEYWORD_SUPPORT),\r
+      text   = STRING_TOKEN(STR_CHECK_KEYWORD_SUPPORT),\r
+      flags  = INTERACTIVE,\r
+      key    = 0x1231;\r
+\r
     subtitle text = STRING_TOKEN(STR_INV_EMPTY_STRING);\r
 \r
     subtitle text = STRING_TOKEN(STR_INV_VERSION_TEXT12);\r
index bd90fcd9c35966728457c9773733953ab9a39b31..68f34623a51e2d36822c34e5ea2b16fdbaa80afe 100644 (file)
@@ -2,7 +2,7 @@
 //\r
 //    Sample Setup formset.\r
 //\r
-//  Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>\r
+//  Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>\r
 //  This program and the accompanying materials\r
 //  are licensed and made available under the terms and conditions of the BSD License\r
 //  which accompanies this distribution.  The full text of the license may be found at\r
@@ -280,7 +280,7 @@ formset
     endoneof;\r
 \r
     oneof varid  = MyIfrNVData.QuestionAboutTreeHugging,\r
-      prompt      = STRING_TOKEN(STR_ONE_OF_PROMPT),\r
+      prompt      = STRING_TOKEN(STR_ONE_OF_PROMPT_KEYWORD),\r
       help        = STRING_TOKEN(STR_ONE_OF_HELP),\r
       flags       = RESET_REQUIRED,\r
       option text = STRING_TOKEN(STR_ONE_OF_TEXT1), value = 0, flags = 0;\r
index 7053b7cc364630d9950fc9cf3103ad55adf34e18..a3fbaed8a431621dd0b9338364a80d66f7313b88 100644 (file)
Binary files a/MdeModulePkg/Universal/DriverSampleDxe/VfrStrings.uni and b/MdeModulePkg/Universal/DriverSampleDxe/VfrStrings.uni differ