回复: [edk2-devel] [PATCH] MdeModulePkg/Library: Add HiiGetStringEx to UefiHiiLib for EDK2 Redfish

gaoliming gaoliming at byosoft.com.cn
Tue Jan 26 01:50:31 UTC 2021


Abner:
 I agree this request is reasonable. New API name HiiGetStringEx is OK to
me. I have some comments on the detail of this API. 

1. Please describe the behavior in function header when TryBestLanguage is
FASLE.
2. When TryBestLanguage is FALSE, the input Language can't be NULL. If
Language is NULL, the function should return the invalid parameter. 

Thanks
Liming
> -----邮件原件-----
> 发件人: bounce+27952+70661+4905953+8761045 at groups.io
> <bounce+27952+70661+4905953+8761045 at groups.io> 代表 Abner Chang
> 发送时间: 2021年1月22日 11:15
> 收件人: devel at edk2.groups.io
> 抄送: Dandan Bi <dandan.bi at intel.com>; Eric Dong <eric.dong at intel.com>;
> Nickle Wang <nickle.wang at hpe.com>
> 主题: [edk2-devel] [PATCH] MdeModulePkg/Library: Add HiiGetStringEx to
> UefiHiiLib for EDK2 Redfish
> 
> Add HiiGetStringEx and leveraged by HiiGetString function to support
> getting string with the best language in optionally. This avoids the
> string in x-uefi language is misled to the language defined by
> "PlatformLang" or the "Supported Languages". This change is introduced
> to support x-uefi keyword language for configuring BIOS setting.
> 
> Signed-off-by: Jiaxin Wu <jiaxin.wu at intel.com>
> Signed-off-by: Siyuan Fu <siyuan.fu at intel.com>
> Signed-off-by: Fan Wang <fan.wang at intel.com>
> Signed-off-by: Abner Chang <abner.chang at hpe.com>
> Cc: Dandan Bi <dandan.bi at intel.com>
> Cc: Eric Dong <eric.dong at intel.com>
> Cc: Nickle Wang <nickle.wang at hpe.com>
> ---
>  MdeModulePkg/Include/Library/HiiLib.h       | 41 +++++++++++-
>  MdeModulePkg/Library/UefiHiiLib/HiiString.c | 73 ++++++++++++++++-----
>  2 files changed, 96 insertions(+), 18 deletions(-)
> 
> diff --git a/MdeModulePkg/Include/Library/HiiLib.h
> b/MdeModulePkg/Include/Library/HiiLib.h
> index c475cb74a1..66c654dcd3 100644
> --- a/MdeModulePkg/Include/Library/HiiLib.h
> +++ b/MdeModulePkg/Include/Library/HiiLib.h
> @@ -1,7 +1,7 @@
>  /** @file
>    Public include file for the HII Library
> 
> -Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) 2007 - 2021, Intel Corporation. All rights reserved.<BR>
>  SPDX-License-Identifier: BSD-2-Clause-Patent
> 
>  **/
> @@ -152,8 +152,43 @@ HiiGetString (
>    IN EFI_HII_HANDLE  HiiHandle,
>    IN EFI_STRING_ID   StringId,
>    IN CONST CHAR8     *Language  OPTIONAL
> -  )
> -;
> +  );
> +
> +/**
> +  Retrieves a string from a string package in a specific language.  If
the
> language
> +  is not specified, then a string from a string package in the current
platform
> +  language is retrieved.  If the string can not be retrieved using the
> specified
> +  language or the current platform language, then the string is retrieved
> from
> +  the string package in the first language the string package supports.
The
> +  returned string is allocated using AllocatePool().  The caller is
responsible
> +  for freeing the allocated buffer using FreePool().
> +
> +  If HiiHandle is NULL, then ASSERT().
> +  If StringId is 0, then ASSET.
> +
> +  @param[in]  HiiHandle         A handle that was previously
> registered in the HII Database.
> +  @param[in]  StringId          The identifier of the string to retrieved
> from the string
> +                                package associated with HiiHandle.
> +  @param[in]  Language          The language of the string to retrieve.
> If this parameter
> +                                is NULL, then the current platform
> language is used.  The
> +                                format of Language must follow the
> language format assumed
> +                                the HII Database.
> +  @param[in]  TryBestLanguage   If TRUE, try to get the best matching
> language from all
> +                                supported languages.
> +
> +
> +  @retval NULL   The string specified by StringId is not present in the
> string package.
> +  @retval Other  The string was returned.
> +
> +**/
> +EFI_STRING
> +EFIAPI
> +HiiGetStringEx (
> +  IN EFI_HII_HANDLE  HiiHandle,
> +  IN EFI_STRING_ID   StringId,
> +  IN CONST CHAR8     *Language  OPTIONAL,
> +  IN BOOLEAN         TryBestLanguage
> +  );
> 
>  /**
>    Retrieves a string from a string package named by GUID, in the
specified
> language.
> diff --git a/MdeModulePkg/Library/UefiHiiLib/HiiString.c
> b/MdeModulePkg/Library/UefiHiiLib/HiiString.c
> index 95229f8a8c..f3c52ace56 100644
> --- a/MdeModulePkg/Library/UefiHiiLib/HiiString.c
> +++ b/MdeModulePkg/Library/UefiHiiLib/HiiString.c
> @@ -1,7 +1,7 @@
>  /** @file
>    HII Library implementation that uses DXE protocols and services.
> 
> -  Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.<BR>
>    SPDX-License-Identifier: BSD-2-Clause-Patent
> 
>  **/
> @@ -220,6 +220,44 @@ HiiGetString (
>    IN EFI_STRING_ID   StringId,
>    IN CONST CHAR8     *Language  OPTIONAL
>    )
> +{
> +  return HiiGetStringEx (HiiHandle, StringId, Language, TRUE);
> +}
> +
> +/**
> +  Retrieves a string from a string package in a specific language.  If
the
> language
> +  is not specified, then a string from a string package in the current
platform
> +  language is retrieved.  If the string can not be retrieved using the
> specified
> +  language or the current platform language, then the string is retrieved
> from
> +  the string package in the first language the string package supports.
The
> +  returned string is allocated using AllocatePool().  The caller is
responsible
> +  for freeing the allocated buffer using FreePool().
> +
> +  If HiiHandle is NULL, then ASSERT().
> +  If StringId is 0, then ASSET.
> +
> +  @param[in]  HiiHandle         A handle that was previously
> registered in the HII Database.
> +  @param[in]  StringId          The identifier of the string to retrieved
> from the string
> +                                package associated with HiiHandle.
> +  @param[in]  Language          The language of the string to retrieve.
> If this parameter
> +                                is NULL, then the current platform
> language is used.  The
> +                                format of Language must follow the
> language format assumed
> +                                the HII Database.
> +  @param[in]  TryBestLanguage   If TRUE, try to get the best matching
> language from all
> +                                supported languages.
> +
> +  @retval NULL   The string specified by StringId is not present in the
> string package.
> +  @retval Other  The string was returned.
> +
> +**/
> +EFI_STRING
> +EFIAPI
> +HiiGetStringEx (
> +  IN EFI_HII_HANDLE  HiiHandle,
> +  IN EFI_STRING_ID   StringId,
> +  IN CONST CHAR8     *Language  OPTIONAL,
> +  IN BOOLEAN         TryBestLanguage
> +  )
>  {
>    EFI_STATUS  Status;
>    UINTN       StringSize;
> @@ -261,21 +299,26 @@ HiiGetString (
>      Language = "";
>    }
> 
> -  //
> -  // Get the best matching language from SupportedLanguages
> -  //
> -  BestLanguage = GetBestLanguage (
> -                   SupportedLanguages,
> -                   FALSE,
> // RFC 4646 mode
> -                   Language,
> // Highest priority
> -                   PlatformLanguage != NULL ? PlatformLanguage : "",
> // Next highest priority
> -                   SupportedLanguages,
> // Lowest priority
> -                   NULL
> -                   );
> -  if (BestLanguage == NULL) {
> -    goto Error;
> +  if (TryBestLanguage) {
> +    //
> +    // Get the best matching language from SupportedLanguages
> +    //
> +    BestLanguage = GetBestLanguage (
> +                     SupportedLanguages,
> +                     FALSE,
> // RFC 4646 mode
> +                     Language,
> // Highest priority
> +                     PlatformLanguage != NULL ? PlatformLanguage :
> "",  // Next highest priority
> +                     SupportedLanguages,
> // Lowest priority
> +                     NULL
> +                     );
> +    if (BestLanguage == NULL) {
> +      goto Error;
> +    }
> +  } else {
> +    BestLanguage = (CHAR8 *) Language;
>    }
> 
> +
>    //
>    // Retrieve the size of the string in the string package for the
> BestLanguage
>    //
> @@ -337,7 +380,7 @@ Error:
>    if (PlatformLanguage != NULL) {
>      FreePool (PlatformLanguage);
>    }
> -  if (BestLanguage != NULL) {
> +  if (TryBestLanguage && BestLanguage != NULL) {
>      FreePool (BestLanguage);
>    }
> 
> --
> 2.17.1
> 
> 
> 
> 
> 





-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#70750): https://edk2.groups.io/g/devel/message/70750
Mute This Topic: https://groups.io/mt/80121535/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-






More information about the edk2-devel-archive mailing list