public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Dandan Bi <dandan.bi@intel.com>
To: edk2-devel@lists.01.org
Cc: Liming Gao <liming.gao@intel.com>, Eric Dong <eric.dong@intel.com>
Subject: [patch 2/2] MdeModulePkg/Browser: Share default if some default value are not specified
Date: Fri,  5 Aug 2016 10:13:16 +0800	[thread overview]
Message-ID: <1470363196-81536-3-git-send-email-dandan.bi@intel.com> (raw)
In-Reply-To: <1470363196-81536-1-git-send-email-dandan.bi@intel.com>

Add a new implementation policy of getting default in SetupBrowser.
The new policy is only for the situation that a question has default
value but doesn't have default value for all supported default type.
In this case, we will choose the smallest default id from the existing
defaults, and share its value to other default id which has no
default value.

Cc: Liming Gao <liming.gao@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Dandan Bi <dandan.bi@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
---
 MdeModulePkg/Universal/SetupBrowserDxe/Setup.c | 66 +++++++++++++++++++++++++-
 MdeModulePkg/Universal/SetupBrowserDxe/Setup.h |  5 ++
 2 files changed, 70 insertions(+), 1 deletion(-)

diff --git a/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c b/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c
index 6b38547..9473eb1 100644
--- a/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c
+++ b/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c
@@ -4016,10 +4016,50 @@ ValueToOption (
   }
 
   return NULL;
 }
 
+/**
+  This function is to get the default Id array, the default ids are in ascending order in the array.
+
+  @param  FormSet                    The form set.
+  @param  DefaultIdArray              Point to the default Id Array.
+
+  @retval DefaultIdCount             Return the default Id number in the array.
+
+**/
+UINT16
+GetDefaultIdArray (
+  IN FORM_BROWSER_FORMSET             *FormSet,
+  IN OUT UINT16                       *DefaultIdArray
+  )
+{
+  FORMSET_DEFAULTSTORE            *DefaultStore;
+  LIST_ENTRY                      *DefaultLink;
+  UINT16                          DefaultIdCount;
+  UINT16                          Index;
+
+  DefaultIdCount = 0;
+
+  DefaultLink = GetFirstNode (&FormSet->DefaultStoreListHead);
+  while (!IsNull (&FormSet->DefaultStoreListHead, DefaultLink)) {
+    DefaultStore = FORMSET_DEFAULTSTORE_FROM_LINK(DefaultLink);
+    Index = DefaultIdCount;
+    //
+    // Insert the DefaultId to the Array with ascending order.
+    //
+    while (Index > 0  && DefaultStore->DefaultId < DefaultIdArray[Index - 1]) {
+      DefaultIdArray[Index] = DefaultIdArray[Index -1];
+      Index--;
+    }
+    DefaultIdArray[Index] = DefaultStore->DefaultId;
+    DefaultLink = GetNextNode (&FormSet->DefaultStoreListHead, DefaultLink);
+    DefaultIdCount++;
+  }
+
+  return DefaultIdCount;
+}
 
 /**
   Reset Question to its default value.
 
   @param  FormSet                The form set.
@@ -4048,29 +4088,38 @@ GetQuestionDefault (
   EFI_HII_CONFIG_ACCESS_PROTOCOL  *ConfigAccess;
   EFI_BROWSER_ACTION_REQUEST      ActionRequest;
   INTN                            Action;
   CHAR16                          *NewString;
   EFI_IFR_TYPE_VALUE              *TypeValue;
+  UINT16                          DefaultIdNumber;
+  UINT16                          DefaultIdArray[EFI_HII_MAX_SUPPORT_DEFAULT_TYPE];
+  UINT16                          ReGetCount;
+  UINT16                          OriginalDefaultId;
 
   Status   = EFI_NOT_FOUND;
   StrValue = NULL;
+  ReGetCount  = 0;
+  OriginalDefaultId  = DefaultId;
 
   //
   // Statement don't have storage, skip them
   //
   if (Question->QuestionId == 0) {
     return Status;
   }
 
+  DefaultIdNumber = GetDefaultIdArray (FormSet, DefaultIdArray);
+
   //
   // There are Five ways to specify default value for a Question:
   //  1, use call back function (highest priority)
   //  2, use ExtractConfig function
   //  3, use nested EFI_IFR_DEFAULT 
   //  4, set flags of EFI_ONE_OF_OPTION (provide Standard and Manufacturing default)
   //  5, set flags of EFI_IFR_CHECKBOX (provide Standard and Manufacturing default) (lowest priority)
   //
+ReGetDefault:
   HiiValue = &Question->HiiValue;
   TypeValue = &HiiValue->Value;
   if (HiiValue->Type == EFI_IFR_TYPE_BUFFER) {
     //
     // For orderedlist, need to pass the BufferValue to Callback function.
@@ -4233,11 +4282,26 @@ GetQuestionDefault (
       return EFI_SUCCESS;
     }
   }
 
   //
-  // For Questions without default
+  // For question without default value for current default Id, we try to re-get the default value form other default id in the DefaultIdArray.
+  // If get, will exit the function, if not, will choose next default id in the DefaultIdArray.
+  // The default id in DefaultIdArray are in ascending order to make sure choose the smallest default id every time.
+  //
+  while (ReGetCount < DefaultIdNumber) {
+    DefaultId = DefaultIdArray[ReGetCount];
+    if (DefaultId == OriginalDefaultId) {
+      ReGetCount ++;
+      continue;
+    }
+    ReGetCount ++;
+    goto ReGetDefault;
+  }
+
+  //
+  // For Questions without default value for all the default id in the DefaultIdArray.
   //
   Status = EFI_NOT_FOUND;
   switch (Question->Operand) {
   case EFI_IFR_NUMERIC_OP:
     //
diff --git a/MdeModulePkg/Universal/SetupBrowserDxe/Setup.h b/MdeModulePkg/Universal/SetupBrowserDxe/Setup.h
index cbc5401..21f392c 100644
--- a/MdeModulePkg/Universal/SetupBrowserDxe/Setup.h
+++ b/MdeModulePkg/Universal/SetupBrowserDxe/Setup.h
@@ -61,10 +61,15 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #define UI_ACTION_REFRESH_FORM       1
 #define UI_ACTION_REFRESH_FORMSET    2
 #define UI_ACTION_EXIT               3
 
 //
+// The maximum number of default type
+//
+#define EFI_HII_MAX_SUPPORT_DEFAULT_TYPE  0x08
+
+//
 //
 // Time definitions
 //
 #define ONE_SECOND  10000000
 
-- 
1.9.5.msysgit.1



  parent reply	other threads:[~2016-08-05  2:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-05  2:13 [patch 0/2] Share default value if some default value are not specified Dandan Bi
2016-08-05  2:13 ` [patch 1/2] MdeModulePkg/HiiDB: Share default " Dandan Bi
2016-08-05  2:13 ` Dandan Bi [this message]
2016-08-08  4:57   ` [patch 2/2] MdeModulePkg/Browser: " Gao, Liming

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1470363196-81536-3-git-send-email-dandan.bi@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox