summaryrefslogtreecommitdiff
path: root/MdeModulePkg/Library/UefiHiiLib
diff options
context:
space:
mode:
authorrsun3 <rsun3@6f19259b-4bc3-4df7-8a09-765794883524>2009-04-14 10:47:19 +0000
committerrsun3 <rsun3@6f19259b-4bc3-4df7-8a09-765794883524>2009-04-14 10:47:19 +0000
commitcb7d01c0c9fd199742d0fed6aa69dab0c79c3338 (patch)
tree920a78778c9de452a58ee0d0df2893e7c4822bdb /MdeModulePkg/Library/UefiHiiLib
parent169a34619b6d583d9f2934a6a3e9caf6e5c6e355 (diff)
downloadedk2-cb7d01c0c9fd199742d0fed6aa69dab0c79c3338.zip
edk2-cb7d01c0c9fd199742d0fed6aa69dab0c79c3338.tar.gz
edk2-cb7d01c0c9fd199742d0fed6aa69dab0c79c3338.tar.bz2
HII Library Class interface refine.
The "HiiLib" prefix for all HII Library API function names changed to "Hii". Remove: HiiLibPreparePackageList(), replaced by HiiAddPackages() HiiLibNewString(), replaced by HiiSetString() HiiLibGetStringFromHandle(), replaced by HiiGetString() HiiLibGetStringFromToken(), replaced by HiiGetPackageString() HiiLibExtractGuidFromHiiHandle() HiiLibDevicePathToHiiHandle() HiiLibGetSupportedSecondaryLanguages() HiiLibGetSupportedLanguageNumber() HiiLibExportPackageLists() HiiLibListPackageLists() Interface change: HiiAddPackages() HiiSetString() HiiGetString() HiiGetHiiHandles() git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8083 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'MdeModulePkg/Library/UefiHiiLib')
-rw-r--r--MdeModulePkg/Library/UefiHiiLib/HiiLanguage.c178
-rw-r--r--MdeModulePkg/Library/UefiHiiLib/HiiLib.c735
-rw-r--r--MdeModulePkg/Library/UefiHiiLib/HiiString.c535
-rw-r--r--MdeModulePkg/Library/UefiHiiLib/InternalHiiLib.h24
4 files changed, 549 insertions, 923 deletions
diff --git a/MdeModulePkg/Library/UefiHiiLib/HiiLanguage.c b/MdeModulePkg/Library/UefiHiiLib/HiiLanguage.c
index 2117329..45e178c 100644
--- a/MdeModulePkg/Library/UefiHiiLib/HiiLanguage.c
+++ b/MdeModulePkg/Library/UefiHiiLib/HiiLanguage.c
@@ -58,155 +58,81 @@ HiiLibGetNextLanguage (
/**
- This function returns the list of supported languages, in the format specified
- in UEFI specification Appendix M.
-
- If HiiHandle is not a valid Handle in the default HII database, then ASSERT.
+ Retrieves a pointer to the a Null-terminated ASCII string containing the list
+ of languages that an HII handle in the HII Database supports. The returned
+ string is allocated using AllocatePool(). The caller is responsible for freeing
+ the returned string using FreePool(). The format of the returned string follows
+ the language format assumed the HII Database.
+
+ If HiiHandle is NULL, then ASSERT().
- @param HiiHandle The HII package list handle.
+ @param[in] HiiHandle A handle that was previously registered in the HII Database.
- @retval !NULL The supported languages.
- @retval NULL If Supported Languages can not be retrived.
+ @retval NULL HiiHandle is not registered in the HII database
+ @retval NULL There are not enough resources available to retrieve the suported
+ languages.
+ @retval NULL The list of suported languages could not be retrieved.
+ @retval Other A pointer to the Null-terminated ASCII string of supported languages.
**/
CHAR8 *
EFIAPI
-HiiLibGetSupportedLanguages (
+HiiGetSupportedLanguages (
IN EFI_HII_HANDLE HiiHandle
)
{
EFI_STATUS Status;
- UINTN BufferSize;
- CHAR8 *LanguageString;
+ UINTN LanguageSize;
+ CHAR8 TempSupportedLanguages;
+ CHAR8 *SupportedLanguages;
+
+ ASSERT (HiiHandle != NULL);
- ASSERT (IsHiiHandleRegistered (HiiHandle));
//
- // Collect current supported Languages for given HII handle
- // First try allocate 4K buffer to store the current supported languages.
+ // Retrieve the size required for the supported languages buffer.
//
- BufferSize = 0x1000;
- LanguageString = AllocateZeroPool (BufferSize);
- if (LanguageString == NULL) {
- return NULL;
- }
-
- Status = gHiiString->GetLanguages (gHiiString, HiiHandle, LanguageString, &BufferSize);
-
- if (Status == EFI_BUFFER_TOO_SMALL) {
- FreePool (LanguageString);
- LanguageString = AllocateZeroPool (BufferSize);
- if (LanguageString == NULL) {
- return NULL;
- }
-
- Status = gHiiString->GetLanguages (gHiiString, HiiHandle, LanguageString, &BufferSize);
- }
-
- if (EFI_ERROR (Status)) {
- LanguageString = NULL;
- }
-
- return LanguageString;
-}
-
-
-/**
- This function returns the number of supported languages on HiiHandle.
-
- If HiiHandle is not a valid Handle in the default HII database, then ASSERT.
- If not enough resource to complete the operation, then ASSERT.
-
- @param HiiHandle The HII package list handle.
-
- @return The number of supported languages.
-
-**/
-UINT16
-EFIAPI
-HiiLibGetSupportedLanguageNumber (
- IN EFI_HII_HANDLE HiiHandle
- )
-{
- CHAR8 *Languages;
- CHAR8 *LanguageString;
- UINT16 LangNumber;
- CHAR8 *Lang;
-
- Languages = HiiLibGetSupportedLanguages (HiiHandle);
- if (Languages == NULL) {
- return 0;
- }
-
- LangNumber = 0;
- Lang = AllocatePool (AsciiStrSize (Languages));
- if (Lang != NULL) {
- LanguageString = Languages;
- while (*LanguageString != 0) {
- HiiLibGetNextLanguage (&LanguageString, Lang);
- LangNumber++;
- }
+ LanguageSize = 0;
+ Status = gHiiString->GetLanguages (gHiiString, HiiHandle, &TempSupportedLanguages, &LanguageSize);
- FreePool (Lang);
- }
- FreePool (Languages);
-
- return LangNumber;
-}
-
-/**
- This function returns the list of supported 2nd languages, in the format specified
- in UEFI specification Appendix M.
-
- If HiiHandle is not a valid Handle in the default HII database, then ASSERT.
- If not enough resource to complete the operation, then ASSERT.
-
- @param HiiHandle The HII package list handle.
- @param FirstLanguage Pointer to language name buffer.
-
- @return The supported languages.
-
-**/
-CHAR8 *
-EFIAPI
-HiiLibGetSupportedSecondaryLanguages (
- IN EFI_HII_HANDLE HiiHandle,
- IN CONST CHAR8 *FirstLanguage
- )
-{
- EFI_STATUS Status;
- UINTN BufferSize;
- CHAR8 *LanguageString;
-
- ASSERT (HiiHandle != NULL);
- ASSERT (IsHiiHandleRegistered (HiiHandle));
//
- // Collect current supported 2nd Languages for given HII handle
- // First try allocate 4K buffer to store the current supported 2nd languages.
+ // If GetLanguages() returns EFI_SUCCESS for a zero size,
+ // then there are no supported languages registered for HiiHandle. If GetLanguages()
+ // returns an error other than EFI_BUFFER_TOO_SMALL, then HiiHandle is not present
+ // in the HII Database
//
- BufferSize = 0x1000;
- LanguageString = AllocateZeroPool (BufferSize);
- if (LanguageString == NULL) {
+ if (Status != EFI_BUFFER_TOO_SMALL) {
+ //
+ // Return NULL if the size can not be retrieved, or if HiiHandle is not in the HII Database
+ //
return NULL;
}
- Status = gHiiString->GetSecondaryLanguages (gHiiString, HiiHandle, FirstLanguage, LanguageString, &BufferSize);
-
- if (Status == EFI_BUFFER_TOO_SMALL) {
- FreePool (LanguageString);
- LanguageString = AllocateZeroPool (BufferSize);
- if (LanguageString == NULL) {
- return NULL;
- }
-
- Status = gHiiString->GetSecondaryLanguages (gHiiString, HiiHandle, FirstLanguage, LanguageString, &BufferSize);
+ //
+ // Allocate the supported languages buffer.
+ //
+ SupportedLanguages = AllocateZeroPool (LanguageSize);
+ if (SupportedLanguages == NULL) {
+ //
+ // Return NULL if allocation fails.
+ //
+ return NULL;
}
+ //
+ // Retrieve the supported languages string
+ //
+ Status = gHiiString->GetLanguages (gHiiString, HiiHandle, SupportedLanguages, &LanguageSize);
if (EFI_ERROR (Status)) {
- LanguageString = NULL;
+ //
+ // Free the buffer and return NULL if the supported languages can not be retrieved.
+ //
+ FreePool (SupportedLanguages);
+ return NULL;
}
- return LanguageString;
+ //
+ // Return the Null-terminated ASCII string of supported languages
+ //
+ return SupportedLanguages;
}
-
-
diff --git a/MdeModulePkg/Library/UefiHiiLib/HiiLib.c b/MdeModulePkg/Library/UefiHiiLib/HiiLib.c
index 384bab4..e337b23 100644
--- a/MdeModulePkg/Library/UefiHiiLib/HiiLib.c
+++ b/MdeModulePkg/Library/UefiHiiLib/HiiLib.c
@@ -19,16 +19,26 @@
//
GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR16 mConfigHdrTemplate[] = L"GUID=00000000000000000000000000000000&NAME=0000&PATH=00";
+EFI_FORM_BROWSER2_PROTOCOL *mUefiFormBrowser2 = NULL;
+
//
-// Form Browser2 Protocol
+// Template used to mark the end of a list of packages
//
-EFI_FORM_BROWSER2_PROTOCOL *mUefiFormBrowser2 = NULL;
+GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_HII_PACKAGE_HEADER mEndOfPakageList = {
+ sizeof (EFI_HII_PACKAGE_HEADER),
+ EFI_HII_PACKAGE_END
+};
/**
- This funciton build the package list based on the package number,
- the GUID of the package list and the list of pointer which point to
- package header that defined by UEFI VFR compiler and StringGather
- tool.
+ Registers a list of packages in the HII Database and returns the HII Handle
+ associated with that registration. If an HII Handle has already been registered
+ with the same PackageListGuid, then NULL is returned. If there are not enough
+ resources to perform the registration, then NULL is returned. If an empty list
+ of packages is passed in, then NULL is returned. If the size of the list of
+ package is 0, then NULL is returned.
+
+ The variable arguments are pointers which point to package header that defined
+ by UEFI VFR compiler and StringGather tool.
#pragma pack (push, 1)
typedef struct {
@@ -36,267 +46,269 @@ EFI_FORM_BROWSER2_PROTOCOL *mUefiFormBrowser2 = NULL;
EFI_HII_PACKAGE_HEADER PackageHeader;
} EDKII_AUTOGEN_PACKAGES_HEADER;
#pragma pack (pop)
-
- If there is not enough resource for the new package list,
- the function will ASSERT.
-
- @param NumberOfPackages The number of packages be
- @param GuidId The GUID for the package list to be generated.
- @param Marker The variable argument list. Each entry represent a specific package header that is
- generated by VFR compiler and StrGather tool. The first 4 bytes is a UINT32 value
- that indicate the overall length of the package.
-
- @return The pointer to the package list header.
+
+ @param[in] PackageListGuid The GUID of the package list.
+ @param[in] DeviceHandle If not NULL, the Device Handle on which
+ an instance of DEVICE_PATH_PROTOCOL is installed.
+ This Device Handle uniquely defines the device that
+ the added packages are associated with.
+ @param[in] ... The variable argument list that contains pointers
+ to packages terminated by a NULL.
+
+ @retval NULL A HII Handle has already been registered in the HII Database with
+ the same PackageListGuid.
+ @retval NULL The HII Handle could not be created.
+ @retval NULL An empty list of packages was passed in.
+ @retval NULL All packages are empty.
+ @retval Other The HII Handle associated with the newly registered package list.
**/
-EFI_HII_PACKAGE_LIST_HEADER *
-InternalHiiLibPreparePackages (
- IN UINTN NumberOfPackages,
- IN CONST EFI_GUID *GuidId,
- IN VA_LIST Marker
+EFI_HII_HANDLE
+EFIAPI
+HiiAddPackages (
+ IN CONST EFI_GUID *PackageListGuid,
+ IN EFI_HANDLE DeviceHandle OPTIONAL,
+ ...
)
{
- EFI_HII_PACKAGE_LIST_HEADER *PackageListHeader;
- UINT8 *PackageListData;
- UINT32 PackageListLength;
- UINT32 PackageLength;
- EFI_HII_PACKAGE_HEADER PackageHeader;
- UINT8 *PackageArray;
- UINTN Index;
- VA_LIST MarkerBackup;
-
- PackageListLength = sizeof (EFI_HII_PACKAGE_LIST_HEADER);
+ EFI_STATUS Status;
+ EFI_HII_HANDLE *HiiHandleBuffer;
+ VA_LIST Args;
+ UINT32 *Package;
+ EFI_HII_PACKAGE_LIST_HEADER *PackageListHeader;
+ EFI_HII_HANDLE HiiHandle;
+ UINT32 Length;
+ UINT8 *Data;
- MarkerBackup = Marker;
+ ASSERT (PackageListGuid != NULL);
//
- // Count the length of the final package list.
+ // Check to see if an HII Handle has already been registered with the same
+ // PackageListGuid
//
- for (Index = 0; Index < NumberOfPackages; Index++) {
- CopyMem (&PackageLength, VA_ARG (Marker, VOID *), sizeof (UINT32));
- //
- // Do not count the BinaryLength field.
- //
- PackageListLength += (PackageLength - sizeof (UINT32));
+ HiiHandleBuffer = HiiGetHiiHandles (PackageListGuid);
+ if (HiiHandleBuffer != NULL) {
+ FreePool (HiiHandleBuffer);
+ return NULL;
}
//
- // Include the length of EFI_HII_PACKAGE_END
+ // Calculate the length of all the packages in the variable argument list
//
- PackageListLength += sizeof (EFI_HII_PACKAGE_HEADER);
- PackageListHeader = AllocateZeroPool (PackageListLength);
- ASSERT (PackageListHeader != NULL);
-
- CopyGuid (&PackageListHeader->PackageListGuid, GuidId);
- PackageListHeader->PackageLength = PackageListLength;
-
- PackageListData = ((UINT8 *) PackageListHeader) + sizeof (EFI_HII_PACKAGE_LIST_HEADER);
+ for (Length = 0, VA_START (Args, DeviceHandle); (Package = VA_ARG (Args, UINT32 *)) != NULL; ) {
+ Length += (ReadUnaligned32 (Package) - sizeof (UINT32));
+ }
+ VA_END (Args);
- Marker = MarkerBackup;
//
- // Prepare the final package list.
+ // If there are no packages in the variable argument list or all the packages
+ // are empty, then return a NULL HII Handle
//
- for (Index = 0; Index < NumberOfPackages; Index++) {
- PackageArray = (UINT8 *) VA_ARG (Marker, VOID *);
- //
- // CopyMem is used for UINT32 to cover the unaligned address access.
- //
- CopyMem (&PackageLength, PackageArray, sizeof (UINT32));
- PackageLength -= sizeof (UINT32);
- PackageArray += sizeof (UINT32);
- CopyMem (PackageListData, PackageArray, PackageLength);
- PackageListData += PackageLength;
+ if (Length == 0) {
+ return NULL;
}
//
- // Append EFI_HII_PACKAGE_END
+ // Add the length of the Package List Header and the terminating Package Header
//
- PackageHeader.Type = EFI_HII_PACKAGE_END;
- PackageHeader.Length = sizeof (EFI_HII_PACKAGE_HEADER);
- CopyMem (PackageListData, &PackageHeader, PackageHeader.Length);
-
- return PackageListHeader;
-}
-
-/**
- Assemble EFI_HII_PACKAGE_LIST according to the passed in packages.
-
- If GuidId is NULL, then ASSERT.
- If not enough resource to complete the operation, then ASSERT.
-
- @param NumberOfPackages Number of packages.
- @param GuidId Package GUID.
- @param ... Variable argument list for packages to be assembled.
+ Length += sizeof (EFI_HII_PACKAGE_LIST_HEADER) + sizeof (EFI_HII_PACKAGE_HEADER);
- @return Pointer of EFI_HII_PACKAGE_LIST_HEADER.
-
-**/
-EFI_HII_PACKAGE_LIST_HEADER *
-EFIAPI
-HiiLibPreparePackageList (
- IN UINTN NumberOfPackages,
- IN CONST EFI_GUID *GuidId,
- ...
- )
-{
- EFI_HII_PACKAGE_LIST_HEADER *PackageListHeader;
- VA_LIST Marker;
-
- ASSERT (GuidId != NULL);
-
- VA_START (Marker, GuidId);
- PackageListHeader = InternalHiiLibPreparePackages (NumberOfPackages, GuidId, Marker);
- VA_END (Marker);
-
- return PackageListHeader;
-}
-
-
-/**
- This function allocates pool for an EFI_HII_PACKAGE_LIST structure
- with additional space that is big enough to host all packages described by the variable
- argument list of package pointers. The allocated structure is initialized using NumberOfPackages,
- GuidId, and the variable length argument list of package pointers.
-
- Then, EFI_HII_PACKAGE_LIST will be register to the default System HII Database. The
- Handle to the newly registered Package List is returned through HiiHandle.
-
- If HiiHandle is NULL, then ASSERT.
+ //
+ // Allocate the storage for the entire Package List
+ //
+ PackageListHeader = AllocateZeroPool (Length);
- @param NumberOfPackages The number of HII packages to register.
- @param GuidId Package List GUID ID.
- @param DriverHandle Optional. If not NULL, the DriverHandle on which an instance of DEVICE_PATH_PROTOCOL is installed.
- This DriverHandle uniquely defines the device that the added packages are associated with.
- @param HiiHandle On output, the HiiHandle is update with the handle which can be used to retrieve the Package
- List later. If the functions failed to add the package to the default HII database, this value will
- be set to NULL.
- @param ... The variable argument list describing all HII Package.
+ //
+ // If the Packahge List can not be allocated, then return a NULL HII Handle
+ //
+ if (PackageListHeader == NULL) {
+ return NULL;
+ }
- @return EFI_SUCCESS If the packages are successfully added to the default HII database.
- @return EFI_OUT_OF_RESOURCE Not enough resource to complete the operation.
+ //
+ // Fill in the GUID and Length of the Package List Header
+ //
+ CopyGuid (&PackageListHeader->PackageListGuid, PackageListGuid);
+ PackageListHeader->PackageLength = Length;
-**/
-EFI_STATUS
-EFIAPI
-HiiLibAddPackages (
- IN UINTN NumberOfPackages,
- IN CONST EFI_GUID *GuidId,
- IN EFI_HANDLE DriverHandle, OPTIONAL
- OUT EFI_HII_HANDLE *HiiHandle,
- ...
- )
-{
- VA_LIST Args;
- EFI_HII_PACKAGE_LIST_HEADER *PackageListHeader;
- EFI_STATUS Status;
+ //
+ // Initialize a pointer to the beginning if the Package List data
+ //
+ Data = (UINT8 *)(PackageListHeader + 1);
- ASSERT (HiiHandle != NULL);
+ //
+ // Copy the data from each package in the variable argument list
+ //
+ for (VA_START (Args, DeviceHandle); (Package = VA_ARG (Args, UINT32 *)) != NULL; ) {
+ Length = ReadUnaligned32 (Package) - sizeof (UINT32);
+ CopyMem (Data, Package + 1, Length);
+ Data += Length;
+ }
+ VA_END (Args);
- VA_START (Args, HiiHandle);
- PackageListHeader = InternalHiiLibPreparePackages (NumberOfPackages, GuidId, Args);
+ //
+ // Append a package of type EFI_HII_PACKAGE_END to mark the end of the package list
+ //
+ CopyMem (Data, &mEndOfPakageList, sizeof (mEndOfPakageList));
- Status = gHiiDatabase->NewPackageList (gHiiDatabase, PackageListHeader, DriverHandle, HiiHandle);
- if (HiiHandle != NULL) {
- if (EFI_ERROR (Status)) {
- *HiiHandle = NULL;
- }
+ //
+ // Register the package list with the HII Database
+ //
+ Status = gHiiDatabase->NewPackageList (
+ gHiiDatabase,
+ PackageListHeader,
+ DeviceHandle,
+ &HiiHandle
+ );
+ if (EFI_ERROR (Status)) {
+ HiiHandle = NULL;
}
+ //
+ // Free the allocated package list
+ //
FreePool (PackageListHeader);
- VA_END (Args);
-
- return Status;
+
+ //
+ // Return the new HII Handle
+ //
+ return HiiHandle;
}
/**
- Removes a package list from the default HII database.
+ Removes a package list from the HII database.
If HiiHandle is NULL, then ASSERT.
- If HiiHandle is not a valid EFI_HII_HANDLE in the default HII database, then ASSERT.
+ If HiiHandle is not a valid EFI_HII_HANDLE in the HII database, then ASSERT.
- @param HiiHandle The handle that was previously registered to the data base that is requested for removal.
- List later.
+ @param[in] HiiHandle The handle that was previously registered in the HII database
**/
VOID
EFIAPI
-HiiLibRemovePackages (
+HiiRemovePackages (
IN EFI_HII_HANDLE HiiHandle
)
{
EFI_STATUS Status;
- ASSERT (IsHiiHandleRegistered (HiiHandle));
+ ASSERT (HiiHandle != NULL);
Status = gHiiDatabase->RemovePackageList (gHiiDatabase, HiiHandle);
ASSERT_EFI_ERROR (Status);
}
/**
- Determines the handles that are currently active in the database.
- It's the caller's responsibility to free handle buffer.
-
- If HandleBufferLength is NULL, then ASSERT.
- If HiiHandleBuffer is NULL, then ASSERT.
-
- @param HandleBufferLength On input, a pointer to the length of the handle
- buffer. On output, the length of the handle buffer
- that is required for the handles found.
- @param HiiHandleBuffer Pointer to an array of Hii Handles returned.
-
- @retval EFI_SUCCESS Get an array of Hii Handles successfully.
+ Retrieves the array of all the HII Handles or the HII handle of a specific
+ package list in the HII Database.
+ This array is terminated with a NULL HII Handle.
+ This function allocates the returned array using AllocatePool().
+ The caller is responsible for freeing the array with FreePool().
+
+ @param[in] PackageListGuid An optional parameter that is used to request
+ an HII Handle that is associatd with a specific
+ Package List GUID. If this parameter is NULL
+ then all the HII Handles in the HII Database
+ are returned. If this parameter is not NULL
+ then at most 1 HII Handle is returned.
+
+ @retval NULL No HII handles were found in the HII database
+ @retval NULL The array of HII Handles could not be retrieved
+ @retval Other A pointer to the NULL terminated array of HII Handles
**/
-EFI_STATUS
+EFI_HII_HANDLE *
EFIAPI
-HiiLibGetHiiHandles (
- IN OUT UINTN *HandleBufferLength,
- OUT EFI_HII_HANDLE **HiiHandleBuffer
+HiiGetHiiHandles (
+ IN CONST EFI_GUID *PackageListGuid OPTIONAL
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
+ UINTN HandleBufferLength;
+ EFI_HII_HANDLE TempHiiHandleBuffer;
+ EFI_HII_HANDLE *HiiHandleBuffer;
+ EFI_GUID Guid;
+ UINTN Index;
+
+ //
+ // Retrieve the size required for the buffer of all HII handles.
+ //
+ HandleBufferLength = 0;
+ Status = gHiiDatabase->ListPackageLists (
+ gHiiDatabase,
+ EFI_HII_PACKAGE_TYPE_ALL,
+ NULL,
+ &HandleBufferLength,
+ &TempHiiHandleBuffer
+ );
- ASSERT (HandleBufferLength != NULL);
- ASSERT (HiiHandleBuffer != NULL);
+ //
+ // If ListPackageLists() returns EFI_SUCCESS for a zero size,
+ // then there are no HII handles in the HII database. If ListPackageLists()
+ // returns an error other than EFI_BUFFER_TOO_SMALL, then there are no HII
+ // handles in the HII database.
+ //
+ if (Status != EFI_BUFFER_TOO_SMALL) {
+ //
+ // Return NULL if the size can not be retrieved, or if there are no HII
+ // handles in the HII Database
+ //
+ return NULL;
+ }
- *HandleBufferLength = 0;
- *HiiHandleBuffer = NULL;
+ //
+ // Allocate the array of HII handles to hold all the HII Handles and a NULL terminator
+ //
+ HiiHandleBuffer = AllocateZeroPool (HandleBufferLength + sizeof (EFI_HII_HANDLE));
+ if (HiiHandleBuffer == NULL) {
+ //
+ // Return NULL if allocation fails.
+ //
+ return NULL;
+ }
//
- // Try to find the actual buffer size for HiiHandle Buffer.
+ // Retrieve the array of HII Handles in the HII Database
//
Status = gHiiDatabase->ListPackageLists (
- gHiiDatabase,
- EFI_HII_PACKAGE_TYPE_ALL,
- NULL,
- HandleBufferLength,
- *HiiHandleBuffer
- );
-
- if (Status == EFI_BUFFER_TOO_SMALL) {
- *HiiHandleBuffer = AllocateZeroPool (*HandleBufferLength);
- ASSERT (*HiiHandleBuffer != NULL);
- Status = gHiiDatabase->ListPackageLists (
- gHiiDatabase,
- EFI_HII_PACKAGE_TYPE_ALL,
- NULL,
- HandleBufferLength,
- *HiiHandleBuffer
- );
-
- if (EFI_ERROR (Status)) {
- FreePool (*HiiHandleBuffer);
- *HiiHandleBuffer = NULL;
- }
+ gHiiDatabase,
+ EFI_HII_PACKAGE_TYPE_ALL,
+ NULL,
+ &HandleBufferLength,
+ HiiHandleBuffer
+ );
+ if (EFI_ERROR (Status)) {
+ //
+ // Free the buffer and return NULL if the HII handles can not be retrieved.
+ //
+ FreePool (HiiHandleBuffer);
+ return NULL;
}
- return Status;
+ if (PackageListGuid == NULL) {
+ //
+ // Return the NULL terminated array of HII handles in the HII Database
+ //
+ return HiiHandleBuffer;
+ } else {
+ for (Index = 0; HiiHandleBuffer[Index] != NULL; Index++) {
+ Status = InternalHiiExtractGuidFromHiiHandle (HiiHandleBuffer[Index], &Guid);
+ ASSERT_EFI_ERROR (Status);
+ if (CompareGuid (&Guid, PackageListGuid)) {
+ HiiHandleBuffer[0] = HiiHandleBuffer[Index];
+ HiiHandleBuffer[1] = NULL;
+ return HiiHandleBuffer;
+ }
+ }
+ FreePool (HiiHandleBuffer);
+ return NULL;
+ }
}
/**
Extract Hii package list GUID for given HII handle.
- If HiiHandle could not be found in the default HII database, then ASSERT.
+ If HiiHandle could not be found in the HII database, then ASSERT.
If Guid is NULL, then ASSERT.
@param Handle Hii handle
@@ -307,7 +319,7 @@ HiiLibGetHiiHandles (
**/
EFI_STATUS
EFIAPI
-HiiLibExtractGuidFromHiiHandle (
+InternalHiiExtractGuidFromHiiHandle (
IN EFI_HII_HANDLE Handle,
OUT EFI_GUID *Guid
)
@@ -317,7 +329,7 @@ HiiLibExtractGuidFromHiiHandle (
EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList;
ASSERT (Guid != NULL);
- ASSERT (IsHiiHandleRegistered (Handle));
+ ASSERT (Handle != NULL);
//
// Get HII PackageList
@@ -350,326 +362,6 @@ HiiLibExtractGuidFromHiiHandle (
}
/**
- Find HII Handle in the default HII database associated with given Device Path.
-
- If DevicePath is NULL, then ASSERT.
-
- @param DevicePath Device Path associated with the HII package list
- handle.
-
- @retval Handle HII package list Handle associated with the Device
- Path.
- @retval NULL Hii Package list handle is not found.
-
-**/
-EFI_HII_HANDLE
-EFIAPI
-HiiLibDevicePathToHiiHandle (
- IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
- )
-{
- EFI_STATUS Status;
- EFI_DEVICE_PATH_PROTOCOL *TmpDevicePath;
- UINTN BufferSize;
- UINTN HandleCount;
- UINTN Index;
- EFI_HANDLE *Handles;
- EFI_HANDLE Handle;
- UINTN Size;
- EFI_HANDLE DriverHandle;
- EFI_HII_HANDLE *HiiHandles;
- EFI_HII_HANDLE HiiHandle;
-
- ASSERT (DevicePath != NULL);
-
- //
- // Locate Device Path Protocol handle buffer
- //
- Status = gBS->LocateHandleBuffer (
- ByProtocol,
- &gEfiDevicePathProtocolGuid,
- NULL,
- &HandleCount,
- &Handles
- );
- if (EFI_ERROR (Status)) {
- return NULL;
- }
-
- //
- // Search Driver Handle by Device Path
- //
- DriverHandle = NULL;
- BufferSize = GetDevicePathSize (DevicePath);
- for(Index = 0; Index < HandleCount; Index++) {
- Handle = Handles[Index];
- gBS->HandleProtocol (Handle, &gEfiDevicePathProtocolGuid, (VOID **) &TmpDevicePath);
-
- //
- // Check whether DevicePath match
- //
- Size = GetDevicePathSize (TmpDevicePath);
- if ((Size == BufferSize) && CompareMem (DevicePath, TmpDevicePath, Size) == 0) {
- DriverHandle = Handle;
- break;
- }
- }
- FreePool (Handles);
-
- if (DriverHandle == NULL) {
- return NULL;
- }
-
- //
- // Retrieve all Hii Handles from HII database
- //
- BufferSize = 0x1000;
- HiiHandles = AllocatePool (BufferSize);
- ASSERT (HiiHandles != NULL);
- Status = gHiiDatabase->ListPackageLists (
- gHiiDatabase,
- EFI_HII_PACKAGE_TYPE_ALL,
- NULL,
- &BufferSize,
- HiiHandles
- );
- if (Status == EFI_BUFFER_TOO_SMALL) {
- FreePool (HiiHandles);
- HiiHandles = AllocatePool (BufferSize);
- ASSERT (HiiHandles != NULL);
-
- Status = gHiiDatabase->ListPackageLists (
- gHiiDatabase,
- EFI_HII_PACKAGE_TYPE_ALL,
- NULL,
- &BufferSize,
- HiiHandles
- );
- }
-
- if (EFI_ERROR (Status)) {
- FreePool (HiiHandles);
- return NULL;
- }
-
- //
- // Search Hii Handle by Driver Handle
- //
- HiiHandle = NULL;
- HandleCount = BufferSize / sizeof (EFI_HII_HANDLE);
- for (Index = 0; Index < HandleCount; Index++) {
- Status = gHiiDatabase->GetPackageListHandle (
- gHiiDatabase,
- HiiHandles[Index],
- &Handle
- );
- if (!EFI_ERROR (Status) && (Handle == DriverHandle)) {
- HiiHandle = HiiHandles[Index];
- break;
- }
- }
-
- FreePool (HiiHandles);
- return HiiHandle;
-}
-
-/**
- Exports the contents of one or all package lists in the HII database into a buffer.
-
- If Handle is not NULL and not a valid EFI_HII_HANDLE registered in the database,
- then ASSERT.
- If PackageListHeader is NULL, then ASSERT.
- If PackageListSize is NULL, then ASSERT.
-
- @param Handle The HII Handle.
- @param PackageListHeader A pointer to a buffer that will contain the results of
- the export function.
- @param PackageListSize On output, the length of the buffer that is required for the exported data.
-
- @retval EFI_SUCCESS Package exported.
-
- @retval EFI_OUT_OF_RESOURCES Not enought memory to complete the operations.
-
-**/
-EFI_STATUS
-EFIAPI
-HiiLibExportPackageLists (
- IN EFI_HII_HANDLE Handle,
- OUT EFI_HII_PACKAGE_LIST_HEADER **PackageListHeader,
- OUT UINTN *PackageListSize
- )
-{
- EFI_STATUS Status;
- UINTN Size;
- EFI_HII_PACKAGE_LIST_HEADER *PackageListHdr;
-
- ASSERT (PackageListSize != NULL);
- ASSERT (PackageListHeader != NULL);
-
- if (Handle != NULL) {
- ASSERT (IsHiiHandleRegistered (Handle));
- }
-
- Size = 0;
- PackageListHdr = NULL;
- Status = gHiiDatabase->ExportPackageLists (
- gHiiDatabase,
- Handle,
- &Size,
- PackageListHdr
- );
- ASSERT_EFI_ERROR (Status != EFI_BUFFER_TOO_SMALL);
-
- if (Status == EFI_BUFFER_TOO_SMALL) {
- PackageListHdr = AllocateZeroPool (Size);
-
- if (PackageListHeader == NULL) {
- return EFI_OUT_OF_RESOURCES;
- } else {
- Status = gHiiDatabase->ExportPackageLists (
- gHiiDatabase,
- Handle,
- &Size,
- PackageListHdr
- );
- }
- }
-
- if (!EFI_ERROR (Status)) {
- *PackageListHeader = PackageListHdr;
- *PackageListSize = Size;
- } else {
- FreePool (PackageListHdr);
- }
-
- return Status;
-}
-
-/**
-
- This function returns a list of the package handles of the
- specified type that are currently active in the HII database. The
- pseudo-type EFI_HII_PACKAGE_TYPE_ALL will cause all package
- handles to be listed.
-
- If HandleBufferLength is NULL, then ASSERT.
- If HandleBuffer is NULL, the ASSERT.
- If PackageType is EFI_HII_PACKAGE_TYPE_GUID and PackageGuid is
- NULL, then ASSERT.
- If PackageType is not EFI_HII_PACKAGE_TYPE_GUID and PackageGuid is not
- NULL, then ASSERT.
-
-
- @param PackageType Specifies the package type of the packages
- to list or EFI_HII_PACKAGE_TYPE_ALL for
- all packages to be listed.
-
- @param PackageGuid If PackageType is
- EFI_HII_PACKAGE_TYPE_GUID, then this is
- the pointer to the GUID which must match
- the Guid field of
- EFI_HII_PACKAGE_GUID_HEADER. Otherwise, it
- must be NULL.
-
- @param HandleBufferLength On output, the length of the handle buffer
- that is required for the handles found.
-
- @param HandleBuffer On output, an array of EFI_HII_HANDLE instances returned.
- The caller is responcible to free this pointer allocated.
-
- @retval EFI_SUCCESS The matching handles are outputed successfully.
- HandleBufferLength is updated with the actual length.
- @retval EFI_OUT_OF_RESOURCES Not enough resource to complete the operation.
- @retval EFI_NOT_FOUND No matching handle could not be found in database.
-**/
-EFI_STATUS
-EFIAPI
-HiiLibListPackageLists (
- IN UINT8 PackageType,
- IN CONST EFI_GUID *PackageGuid,
- IN OUT UINTN *HandleBufferLength,
- OUT EFI_HII_HANDLE **HandleBuffer
- )
-{
- EFI_STATUS Status;
-
- ASSERT (HandleBufferLength != NULL);
- ASSERT (HandleBuffer != NULL);
-
- *HandleBufferLength = 0;
- *HandleBuffer = NULL;
-
- if (PackageType == EFI_HII_PACKAGE_TYPE_GUID) {
- ASSERT (PackageGuid != NULL);
- } else {
- ASSERT (PackageGuid == NULL);
- }
-
- Status = gHiiDatabase->ListPackageLists (
- gHiiDatabase,
- PackageType,
- PackageGuid,
- HandleBufferLength,
- *HandleBuffer
- );
- if (EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL)) {
- //
- // No packages is registered to UEFI HII Database, just return.
- //
- //
- return Status;
- }
-
- *HandleBuffer = AllocateZeroPool (*HandleBufferLength);
-
- if (*HandleBuffer == NULL) {
- return EFI_OUT_OF_RESOURCES;
- }
-
- return gHiiDatabase->ListPackageLists (
- gHiiDatabase,
- PackageType,
- PackageGuid,
- HandleBufferLength,
- *HandleBuffer
- );
-
-}
-/**
- This function check if the Hii Handle is a valid handle registered
- in the HII database.
-
- @param HiiHandle The HII Handle.
-
- @retval TRUE If it is a valid HII handle.
- @retval FALSE If it is a invalid HII handle.
-**/
-BOOLEAN
-IsHiiHandleRegistered (
- EFI_HII_HANDLE HiiHandle
- )
-{
- EFI_STATUS Status;
- UINTN BufferSize;
- EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList;
-
- ASSERT (HiiHandle != NULL);
-
- HiiPackageList = NULL;
- BufferSize = 0;
-
- Status = gHiiDatabase->ExportPackageLists (
- gHiiDatabase,
- HiiHandle,
- &BufferSize,
- HiiPackageList
- );
-
- return (BOOLEAN) (Status == EFI_BUFFER_TOO_SMALL);
-}
-
-
-/**
Converts all hex dtring characters in range ['A'..'F'] to ['a'..'f'] for
hex digits that appear between a '=' and a '&' in a config string.
@@ -2916,3 +2608,4 @@ HiiIfrLibExtractDefault(
return EFI_SUCCESS;
}
+
diff --git a/MdeModulePkg/Library/UefiHiiLib/HiiString.c b/MdeModulePkg/Library/UefiHiiLib/HiiString.c
index 7d8ca5e..2c317e5 100644
--- a/MdeModulePkg/Library/UefiHiiLib/HiiString.c
+++ b/MdeModulePkg/Library/UefiHiiLib/HiiString.c
@@ -163,339 +163,340 @@ zulzu\
/**
- This function adds the string into String Package of each language
- supported by the package list.
-
- If String is NULL, then ASSERT.
- If StringId is NULL, the ASSERT.
- If PackageList could not be found in the default HII database, then ASSERT.
-
- @param PackageList Handle of the package list where this string will
- be added.
- @param StringId On return, contains the new strings id, which is
- unique within PackageList.
- @param String Points to the new null-terminated string.
-
- @retval EFI_SUCCESS The new string was added successfully.
- @retval EFI_OUT_OF_RESOURCES Could not add the string due to lack of resources.
+ This function create a new string in String Package or updates an existing
+ string in a String Package. If StringId is 0, then a new string is added to
+ a String Package. If StringId is not zero, then a string in String Package is
+ updated. If SupportedLanguages is NULL, then the string is added or updated
+ for all the languages that the String Package supports. If SupportedLanguages
+ is not NULL, then the string is added or updated for the set of languages
+ specified by SupportedLanguages.
+
+ If HiiHandle is NULL, then ASSERT().
+ If String is NULL, then ASSERT().
+
+ @param[in] HiiHandle A handle that was previously registered in the
+ HII Database.
+ @param[in] StringId If zero, then a new string is created in the
+ String Package associated with HiiHandle. If
+ non-zero, then the string specified by StringId
+ is updated in the String Package associated
+ with HiiHandle.
+ @param[in] String A pointer to the Null-terminated Unicode string
+ to add or update in the String Package associated
+ with HiiHandle.
+ @param[in] SupportedLanguages A pointer to a Null-terminated ASCII string of
+ language codes. If this parameter is NULL, then
+ String is added or updated in the String Package
+ associated with HiiHandle for all the languages
+ that the String Package supports. If this
+ parameter is not NULL, then then String is added
+ or updated in the String Package associated with
+ HiiHandle for the set oflanguages specified by
+ SupportedLanguages. The format of
+ SupportedLanguages must follow the language
+ format assumed the HII Database.
+
+ @retval 0 The string could not be added or updated in the String Package.
+ @retval Other The EFI_STRING_ID of the newly added or updated string.
**/
-EFI_STATUS
+EFI_STRING_ID
EFIAPI
-HiiLibNewString (
- IN EFI_HII_HANDLE PackageList,
- OUT EFI_STRING_ID *StringId,
- IN CONST EFI_STRING String
+HiiSetString (
+ IN EFI_HII_HANDLE HiiHandle,
+ IN EFI_STRING_ID StringId, OPTIONAL
+ IN CONST EFI_STRING String,
+ IN CONST CHAR8 *SupportedLanguages OPTIONAL
)
{
- EFI_STATUS Status;
- CHAR8 *Languages;
- CHAR8 *LangStrings;
- CHAR8 *Lang;
+ EFI_STATUS Status;
+ CHAR8 *AllocatedLanguages;
+ CHAR8 *Supported;
+ CHAR8 *Language;
+ EFI_STRING_ID NewStringId;
+ ASSERT (HiiHandle != NULL);
ASSERT (String != NULL);
- ASSERT (StringId != NULL);
- Status = EFI_SUCCESS;
+ if (SupportedLanguages == NULL) {
+ //
+ // Retrieve the languages that the package specified by HiiHandle supports
+ //
+ AllocatedLanguages = HiiGetSupportedLanguages (HiiHandle);
+ } else {
+ //
+ // Allocate a copy of the SupportLanguages string that passed in
+ //
+ AllocatedLanguages = AllocateCopyPool (AsciiStrLen (SupportedLanguages), SupportedLanguages);
+ }
- Languages = HiiLibGetSupportedLanguages (PackageList);
- ASSERT (Languages != NULL);
//
- // Allocate working buffer to contain substring of Languages.
+ // If there are not enough resources for the supported languages string, then return a StringId of 0
//
- Lang = AllocatePool (AsciiStrSize (Languages));
- ASSERT (Lang != NULL);
+ if (AllocatedLanguages == NULL) {
+ return (EFI_STRING_ID)(0);
+ }
- LangStrings = Languages;
- while (*LangStrings != 0) {
- HiiLibGetNextLanguage (&LangStrings, Lang);
+ NewStringId = 0;
+ Status = EFI_INVALID_PARAMETER;
+ //
+ // Loop through each language that the string supports
+ //
+ for (Supported = AllocatedLanguages; *Supported != '\0'; ) {
+ //
+ // Cache a pointer to the beginning of the current language in the list of languages
+ //
+ Language = Supported;
//
- // For each language supported by the package,
- // a string token is created.
+ // Search for the next language seperator and replace it with a Null-terminator
//
- Status = gHiiString->NewString (
- gHiiString,
- PackageList,
- StringId,
- Lang,
- NULL,
- String,
- NULL
- );
- if (EFI_ERROR (Status)) {
- break;
+ for (; *Supported != 0 && *Supported != ';'; Supported++);
+ if (*Supported != 0) {
+ *(Supported++) = '\0';
}
- }
-
- FreePool (Lang);
- FreePool (Languages);
-
- return Status;
-
-}
-
-/**
- This function update the specified string in String Package of each language
- supported by the package list.
-
- If String is NULL, then ASSERT.
- If PackageList could not be found in the default HII database, then ASSERT.
- If StringId is not found in PackageList, then ASSERT.
-
- @param PackageList Handle of the package list where this string will
- be added.
- @param StringId Ths String Id to be updated.
- @param String Points to the new null-terminated string.
-
- @retval EFI_SUCCESS The new string was added successfully.
- @retval EFI_OUT_OF_RESOURCES Could not add the string due to lack of resources.
-
-**/
-EFI_STATUS
-EFIAPI
-HiiLibSetString (
- IN EFI_HII_HANDLE PackageList,
- IN EFI_STRING_ID StringId,
- IN CONST EFI_STRING String
- )
-{
- EFI_STATUS Status;
- CHAR8 *Languages;
- CHAR8 *LangStrings;
- CHAR8 *Lang;
-
- ASSERT (IsHiiHandleRegistered (PackageList));
-
- Status = EFI_SUCCESS;
-
- Languages = HiiLibGetSupportedLanguages (PackageList);
- ASSERT (Languages != NULL);
-
- //
- // Allocate working buffer to contain substring of Languages.
- //
- Lang = AllocatePool (AsciiStrSize (Languages));
- ASSERT (Lang != NULL);
-
- LangStrings = Languages;
- while (*LangStrings != 0) {
- HiiLibGetNextLanguage (&LangStrings, Lang);
+ //
+ // If StringId is 0, then call NewString(). Otherwise, call SetString()
+ //
+ if (StringId == (EFI_STRING_ID)(0)) {
+ Status = gHiiString->NewString (gHiiString, HiiHandle, &NewStringId, Language, NULL, String, NULL);
+ } else {
+ Status = gHiiString->SetString (gHiiString, HiiHandle, StringId, Language, String, NULL);
+ }
//
- // For each language supported by the package,
- // the string is updated.
+ // If there was an error, then break out of the loop and return a StringId of 0
//
- Status = gHiiString->SetString (
- gHiiString,
- PackageList,
- StringId,
- Lang,
- String,
- NULL
- );
if (EFI_ERROR (Status)) {
break;
}
}
- FreePool (Lang);
- FreePool (Languages);
-
- return Status;
+ //
+ // Free the buffer of supported languages
+ //
+ FreePool (AllocatedLanguages);
+
+ if (EFI_ERROR (Status)) {
+ return (EFI_STRING_ID)(0);
+ } else if (StringId == (EFI_STRING_ID)(0)) {
+ return NewStringId;
+ } else {
+ return StringId;
+ }
}
/**
- Get the string given the StringId and String package Producer's Guid. The caller
- is responsible to free the *String.
-
- If PackageList with the matching ProducerGuid is not found, then ASSERT.
- If PackageList with the matching ProducerGuid is found but no String is
- specified by StringId is found, then ASSERT.
-
- @param ProducerGuid The Guid of String package list.
- @param StringId The String ID.
- @param String The output string.
-
- @retval EFI_SUCCESS Operation is successful.
- @retval EFI_OUT_OF_RESOURCES There is not enought memory in the system.
+ Retrieves a string from a string package names by GUID 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 PackageListGuid is NULL, then ASSERT().
+ If StringId is 0, then ASSERT.
+
+ @param[in] PackageListGuid The GUID of a package list that was previously
+ registered in the HII Database.
+ @param[in] StringId The identifier of the string to retrieved from the
+ string package associated with PackageListGuid.
+ @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.
+
+ @retval NULL The package list specified by PackageListGuid is not present in the
+ HII Database.
+ @retval NULL The string specified by StringId is not present in the string package.
+ @retval Other The string was returned.
**/
-EFI_STATUS
+EFI_STRING
EFIAPI
-HiiLibGetStringFromToken (
- IN EFI_GUID *ProducerGuid,
- IN EFI_STRING_ID StringId,
- OUT EFI_STRING *String
+HiiGetPackageString (
+ IN CONST EFI_GUID *PackageListGuid,
+ IN EFI_STRING_ID StringId,
+ IN CONST CHAR8 *Language OPTIONAL
)
{
- EFI_STATUS Status;
- UINTN Index;
- UINTN HandleBufferLen;
- EFI_HII_HANDLE *HiiHandleBuffer;
- EFI_GUID Guid;
+ EFI_HANDLE *HiiHandleBuffer;
+ EFI_HANDLE HiiHandle;
- Status = HiiLibGetHiiHandles (&HandleBufferLen, &HiiHandleBuffer);
- if (HiiHandleBuffer == NULL) {
- return EFI_NOT_FOUND;
- }
- for (Index = 0; Index < (HandleBufferLen / sizeof (EFI_HII_HANDLE)); Index++) {
- Status = HiiLibExtractGuidFromHiiHandle (HiiHandleBuffer[Index], &Guid);
- if (EFI_ERROR(Status)) {
- return Status;
- }
- if (CompareGuid (&Guid, ProducerGuid)) {
- break;
- }
- }
+ ASSERT (PackageListGuid != NULL);
- if (Index >= (HandleBufferLen / sizeof (EFI_HII_HANDLE))) {
- //
- // If PackageList with the matching ProducerGuid is not found, then ASSERT.
- //
- ASSERT (FALSE);
- Status = EFI_NOT_FOUND;
- goto Out;
+ HiiHandleBuffer = HiiGetHiiHandles (PackageListGuid);
+ if (HiiHandleBuffer == NULL) {
+ return NULL;
}
- Status = HiiLibGetStringFromHandle (HiiHandleBuffer[Index], StringId, String);
-
-Out:
+ HiiHandle = HiiHandleBuffer[0];
FreePool (HiiHandleBuffer);
- return Status;
+ return HiiGetString (HiiHandle, StringId, Language);
}
/**
- This function try to retrieve string from String package of current language.
- If fails, it try to retrieve string from String package of first language it support.
-
- If StringSize is NULL, then ASSERT.
- If String is NULL and *StringSize is not 0, then ASSERT.
- If PackageList could not be found in the default HII database, then ASSERT.
- If StringId is not found in PackageList, then ASSERT.
-
- @param PackageList The package list in the HII database to search for
- the specified string.
- @param StringId The string's id, which is unique within
- PackageList.
- @param String Points to the new null-terminated string.
- @param StringSize On entry, points to the size of the buffer pointed
- to by String, in bytes. On return, points to the
- length of the string, in bytes.
-
- @retval EFI_SUCCESS The string was returned successfully.
- @retval EFI_NOT_FOUND The string specified by StringId is not available.
- @retval EFI_BUFFER_TOO_SMALL The buffer specified by StringLength is too small
- to hold the string.
+ 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.
+
+ @retval NULL The string specified by StringId is not present in the string package.
+ @retval Other The string was returned.
**/
-EFI_STATUS
+EFI_STRING
EFIAPI
-HiiLibGetString (
- IN EFI_HII_HANDLE PackageList,
- IN EFI_STRING_ID StringId,
- OUT EFI_STRING String,
- IN OUT UINTN *StringSize
+HiiGetString (
+ IN EFI_HII_HANDLE HiiHandle,
+ IN EFI_STRING_ID StringId,
+ IN CONST CHAR8 *Language OPTIONAL
)
{
EFI_STATUS Status;
- CHAR8 *Languages;
- CHAR8 *CurrentLang;
+ UINTN StringSize;
+ CHAR16 TempString;
+ EFI_STRING String;
+ CHAR8 *SupportedLanguages;
+ CHAR8 *PlatformLanguage;
CHAR8 *BestLanguage;
- ASSERT (StringSize != NULL);
- ASSERT (!(*StringSize != 0 && String == NULL));
- ASSERT (IsHiiHandleRegistered (PackageList));
+ ASSERT (HiiHandle != NULL);
+ ASSERT (StringId != 0);
- Languages = HiiLibGetSupportedLanguages (PackageList);
- ASSERT (Languages != NULL);
+ //
+ // Initialize all allocated buffers to NULL
+ //
+ SupportedLanguages = NULL;
+ PlatformLanguage = NULL;
+ BestLanguage = NULL;
+ String = NULL;
- CurrentLang = GetEfiGlobalVariable (L"PlatformLang");
-
- Status = EFI_NOT_FOUND;
- BestLanguage = GetBestLanguage (
- Languages,
- FALSE,
- (CurrentLang != NULL) ? CurrentLang : "",
- (CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLang),
- Languages,
- NULL
- );
- if (BestLanguage != NULL ) {
- Status = gHiiString->GetString (
- gHiiString,
- BestLanguage,
- PackageList,
- StringId,
- String,
- StringSize,
- NULL
- );
- FreePool (BestLanguage);
- }
- if (CurrentLang != NULL) {
- FreePool (CurrentLang);
+ //
+ // Get the languages that the package specified by HiiHandle supports
+ //
+ SupportedLanguages = HiiGetSupportedLanguages (HiiHandle);
+ if (SupportedLanguages == NULL) {
+ goto Error;
}
- FreePool (Languages);
-
- return Status;
-}
+ //
+ // Get the current platform language setting
+ //
+ PlatformLanguage = GetEfiGlobalVariable (L"PlatformLang");
-/**
- Get string specified by StringId form the HiiHandle. The caller
- is responsible to free the *String.
-
- If String is NULL, then ASSERT.
- If HiiHandle could not be found in the default HII database, then ASSERT.
- If StringId is not found in PackageList, then ASSERT.
-
- @param HiiHandle The HII handle of package list.
- @param StringId The String ID.
- @param String The output string.
+ //
+ // If Languag is NULL, then set it to an empty string, so it will be
+ // skipped by GetBestLanguage()
+ //
+ if (Language == NULL) {
+ Language = "";
+ }
- @retval EFI_NOT_FOUND String is not found.
- @retval EFI_SUCCESS Operation is successful.
- @retval EFI_OUT_OF_RESOURCES There is not enought memory in the system.
+ //
+ // 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;
+ }
-**/
-EFI_STATUS
-EFIAPI
-HiiLibGetStringFromHandle (
- IN EFI_HII_HANDLE HiiHandle,
- IN EFI_STRING_ID StringId,
- OUT EFI_STRING *String
- )
-{
- EFI_STATUS Status;
- UINTN StringSize;
+ //
+ // Retrieve the size of the string in the string package for the BestLanguage
+ //
+ StringSize = 0;
+ Status = gHiiString->GetString (
+ gHiiString,
+ BestLanguage,
+ HiiHandle,
+ StringId,
+ &TempString,
+ &StringSize,
+ NULL
+ );
+ //
+ // If GetString() returns EFI_SUCCESS for a zero size,
+ // then there are no supported languages registered for HiiHandle. If GetString()
+ // returns an error other than EFI_BUFFER_TOO_SMALL, then HiiHandle is not present
+ // in the HII Database
+ //
+ if (Status != EFI_BUFFER_TOO_SMALL) {
+ goto Error;
+ }
- ASSERT (String != NULL);
+ //
+ // Allocate a buffer for the return string
+ //
+ String = AllocateZeroPool (StringSize);
+ if (String == NULL) {
+ goto Error;
+ }
- StringSize = HII_LIB_DEFAULT_STRING_SIZE;
- *String = AllocateZeroPool (StringSize);
- if (*String == NULL) {
- return EFI_OUT_OF_RESOURCES;
+ //
+ // Retrieve the string from the string package
+ //
+ Status = gHiiString->GetString (
+ gHiiString,
+ BestLanguage,
+ HiiHandle,
+ StringId,
+ String,
+ &StringSize,
+ NULL
+ );
+ if (EFI_ERROR (Status)) {
+ //
+ // Free the buffer and return NULL if the supported languages can not be retrieved.
+ //
+ FreePool (String);
+ String = NULL;
}
- Status = HiiLibGetString (HiiHandle, StringId, *String, &StringSize);
- if (Status == EFI_BUFFER_TOO_SMALL) {
- FreePool (*String);
- *String = AllocateZeroPool (StringSize);
- if (*String == NULL) {
- return EFI_OUT_OF_RESOURCES;
- }
- Status = HiiLibGetString (HiiHandle, StringId, *String, &StringSize);
+Error:
+ //
+ // Free allocated buffers
+ //
+ if (SupportedLanguages != NULL) {
+ FreePool (SupportedLanguages);
+ }
+ if (PlatformLanguage != NULL) {
+ FreePool (PlatformLanguage);
+ }
+ if (BestLanguage != NULL) {
+ FreePool (BestLanguage);
}
- return Status;
+ //
+ // Return the Null-terminated Unicode string
+ //
+ return String;
}
-
-
/**
Convert language code from RFC3066 to ISO639-2.
diff --git a/MdeModulePkg/Library/UefiHiiLib/InternalHiiLib.h b/MdeModulePkg/Library/UefiHiiLib/InternalHiiLib.h
index e144635..c3fd834 100644
--- a/MdeModulePkg/Library/UefiHiiLib/InternalHiiLib.h
+++ b/MdeModulePkg/Library/UefiHiiLib/InternalHiiLib.h
@@ -48,17 +48,23 @@ extern CONST EFI_HII_DATABASE_PROTOCOL *mHiiDatabaseProt;
extern CONST EFI_HII_STRING_PROTOCOL *mHiiStringProt;
/**
- This function check if the Hii Handle is a valid handle registered
- in the HII database.
+ Extract Hii package list GUID for given HII handle.
- @param HiiHandle The HII Handle.
+ If HiiHandle could not be found in the HII database, then ASSERT.
+ If Guid is NULL, then ASSERT.
+
+ @param Handle Hii handle
+ @param Guid Package list GUID
+
+ @retval EFI_SUCCESS Successfully extract GUID from Hii database.
- @retval TRUE If it is a valid HII handle.
- @retval FALSE If it is a invalid HII handle.
**/
-BOOLEAN
-IsHiiHandleRegistered (
- EFI_HII_HANDLE HiiHandle
- );
+EFI_STATUS
+EFIAPI
+InternalHiiExtractGuidFromHiiHandle (
+ IN EFI_HII_HANDLE Handle,
+ OUT EFI_GUID *Guid
+ )
+;
#endif