Clean up HiiLib.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@5481 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
qwang12 2008-07-16 01:22:51 +00:00
parent 631c199143
commit 29870c8d61
3 changed files with 39 additions and 19 deletions

View File

@ -124,7 +124,6 @@ HiiLibGetSupportedLanguages (
UINTN BufferSize; UINTN BufferSize;
CHAR8 *LanguageString; CHAR8 *LanguageString;
ASSERT (HiiHandle != NULL);
ASSERT (IsHiiHandleRegistered (HiiHandle)); ASSERT (IsHiiHandleRegistered (HiiHandle));
// //
// Collect current supported Languages for given HII handle // Collect current supported Languages for given HII handle
@ -140,7 +139,7 @@ HiiLibGetSupportedLanguages (
Status = mHiiStringProt->GetLanguages (mHiiStringProt, HiiHandle, LanguageString, &BufferSize); Status = mHiiStringProt->GetLanguages (mHiiStringProt, HiiHandle, LanguageString, &BufferSize);
if (Status == EFI_BUFFER_TOO_SMALL) { if (Status == EFI_BUFFER_TOO_SMALL) {
gBS->FreePool (LanguageString); FreePool (LanguageString);
LanguageString = AllocateZeroPool (BufferSize); LanguageString = AllocateZeroPool (BufferSize);
if (LanguageString == NULL) { if (LanguageString == NULL) {
return NULL; return NULL;
@ -190,7 +189,7 @@ HiiLibGetSupportedLanguageNumber (
HiiLibGetNextLanguage (&LanguageString, Lang); HiiLibGetNextLanguage (&LanguageString, Lang);
LangNumber++; LangNumber++;
} }
gBS->FreePool (Languages); FreePool (Languages);
return LangNumber; return LangNumber;
} }
@ -235,7 +234,7 @@ HiiLibGetSupportedSecondaryLanguages (
Status = mHiiStringProt->GetSecondaryLanguages (mHiiStringProt, HiiHandle, FirstLanguage, LanguageString, &BufferSize); Status = mHiiStringProt->GetSecondaryLanguages (mHiiStringProt, HiiHandle, FirstLanguage, LanguageString, &BufferSize);
if (Status == EFI_BUFFER_TOO_SMALL) { if (Status == EFI_BUFFER_TOO_SMALL) {
gBS->FreePool (LanguageString); FreePool (LanguageString);
LanguageString = AllocateZeroPool (BufferSize); LanguageString = AllocateZeroPool (BufferSize);
if (LanguageString == NULL) { if (LanguageString == NULL) {
return NULL; return NULL;

View File

@ -32,6 +32,9 @@ LocateHiiProtocols (
EFI_STATUS Status; EFI_STATUS Status;
if (mHiiProtocolsInitialized) { if (mHiiProtocolsInitialized) {
//
// Only need to initialize the protocol instance once.
//
return; return;
} }
@ -52,6 +55,13 @@ LocateHiiProtocols (
package header that defined by UEFI VFR compiler and StringGather package header that defined by UEFI VFR compiler and StringGather
tool. tool.
#pragma pack (push, 1)
typedef struct {
UINT32 BinaryLength;
EFI_HII_PACKAGE_HEADER PackageHeader;
} TIANO_AUTOGEN_PACKAGES_HEADER;
#pragma pack (pop)
If there is not enough resource for the new package list, If there is not enough resource for the new package list,
the function will ASSERT. the function will ASSERT.
@ -86,6 +96,9 @@ InternalHiiLibPreparePackages (
for (Index = 0; Index < NumberOfPackages; Index++) { for (Index = 0; Index < NumberOfPackages; Index++) {
CopyMem (&PackageLength, VA_ARG (Marker, VOID *), sizeof (UINT32)); CopyMem (&PackageLength, VA_ARG (Marker, VOID *), sizeof (UINT32));
//
// Do not count the BinaryLength field.
//
PackageListLength += (PackageLength - sizeof (UINT32)); PackageListLength += (PackageLength - sizeof (UINT32));
} }
@ -95,6 +108,7 @@ InternalHiiLibPreparePackages (
PackageListLength += sizeof (EFI_HII_PACKAGE_HEADER); PackageListLength += sizeof (EFI_HII_PACKAGE_HEADER);
PackageListHeader = AllocateZeroPool (PackageListLength); PackageListHeader = AllocateZeroPool (PackageListLength);
ASSERT (PackageListHeader != NULL); ASSERT (PackageListHeader != NULL);
CopyMem (&PackageListHeader->PackageListGuid, GuidId, sizeof (EFI_GUID)); CopyMem (&PackageListHeader->PackageListGuid, GuidId, sizeof (EFI_GUID));
PackageListHeader->PackageLength = PackageListLength; PackageListHeader->PackageLength = PackageListLength;
@ -222,8 +236,6 @@ HiiLibAddPackages (
@param HiiHandle The handle that was previously registered to the data base that is requested for removal. @param HiiHandle The handle that was previously registered to the data base that is requested for removal.
List later. List later.
@return VOID
**/ **/
VOID VOID
EFIAPI EFIAPI
@ -232,7 +244,7 @@ HiiLibRemovePackages (
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
ASSERT (HiiHandle != NULL); ASSERT (IsHiiHandleRegistered (HiiHandle));
LocateHiiProtocols (); LocateHiiProtocols ();
@ -328,6 +340,7 @@ HiiLibExtractGuidFromHiiHandle (
EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList; EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList;
ASSERT (Guid != NULL); ASSERT (Guid != NULL);
ASSERT (IsHiiHandleRegistered (Handle));
// //
// Get HII PackageList // Get HII PackageList
@ -355,7 +368,7 @@ HiiLibExtractGuidFromHiiHandle (
// //
CopyMem (Guid, &HiiPackageList->PackageListGuid, sizeof (EFI_GUID)); CopyMem (Guid, &HiiPackageList->PackageListGuid, sizeof (EFI_GUID));
gBS->FreePool (HiiPackageList); FreePool (HiiPackageList);
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -425,7 +438,7 @@ HiiLibDevicePathToHiiHandle (
break; break;
} }
} }
gBS->FreePool (Handles); FreePool (Handles);
if (DriverHandle == NULL) { if (DriverHandle == NULL) {
return NULL; return NULL;
@ -447,7 +460,7 @@ HiiLibDevicePathToHiiHandle (
HiiHandles HiiHandles
); );
if (Status == EFI_BUFFER_TOO_SMALL) { if (Status == EFI_BUFFER_TOO_SMALL) {
gBS->FreePool (HiiHandles); FreePool (HiiHandles);
HiiHandles = AllocatePool (BufferSize); HiiHandles = AllocatePool (BufferSize);
ASSERT (HiiHandles != NULL); ASSERT (HiiHandles != NULL);
@ -461,7 +474,7 @@ HiiLibDevicePathToHiiHandle (
} }
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
gBS->FreePool (HiiHandles); FreePool (HiiHandles);
return NULL; return NULL;
} }
@ -482,7 +495,7 @@ HiiLibDevicePathToHiiHandle (
} }
} }
gBS->FreePool (HiiHandles); FreePool (HiiHandles);
return HiiHandle; return HiiHandle;
} }

View File

@ -57,6 +57,10 @@ HiiLibNewString (
while (*LangStrings != 0) { while (*LangStrings != 0) {
HiiLibGetNextLanguage (&LangStrings, Lang); HiiLibGetNextLanguage (&LangStrings, Lang);
//
// For each language supported by the package,
// a string token is created.
//
Status = mHiiStringProt->NewString ( Status = mHiiStringProt->NewString (
mHiiStringProt, mHiiStringProt,
PackageList, PackageList,
@ -119,6 +123,10 @@ HiiLibSetString (
while (*LangStrings != 0) { while (*LangStrings != 0) {
HiiLibGetNextLanguage (&LangStrings, Lang); HiiLibGetNextLanguage (&LangStrings, Lang);
//
// For each language supported by the package,
// the string is updated.
//
Status = mHiiStringProt->SetString ( Status = mHiiStringProt->SetString (
mHiiStringProt, mHiiStringProt,
PackageList, PackageList,
@ -195,7 +203,7 @@ HiiLibGetStringFromToken (
Out: Out:
if (HiiHandleBuffer != NULL) { if (HiiHandleBuffer != NULL) {
gBS->FreePool (HiiHandleBuffer); FreePool (HiiHandleBuffer);
} }
return Status; return Status;
} }
@ -262,7 +270,7 @@ HiiLibGetString (
LangStrings = Languages; LangStrings = Languages;
HiiLibGetNextLanguage (&LangStrings, Lang); HiiLibGetNextLanguage (&LangStrings, Lang);
gBS->FreePool (Languages); FreePool (Languages);
Status = mHiiStringProt->GetString ( Status = mHiiStringProt->GetString (
mHiiStringProt, mHiiStringProt,
@ -318,7 +326,7 @@ HiiLibGetStringFromHandle (
Status = HiiLibGetString (HiiHandle, StringId, *String, &StringSize); Status = HiiLibGetString (HiiHandle, StringId, *String, &StringSize);
if (Status == EFI_BUFFER_TOO_SMALL) { if (Status == EFI_BUFFER_TOO_SMALL) {
gBS->FreePool (*String); FreePool (*String);
*String = AllocateZeroPool (StringSize); *String = AllocateZeroPool (StringSize);
if (*String == NULL) { if (*String == NULL) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
@ -336,7 +344,7 @@ HiiLibGetStringFromHandle (
// Each entry is 5 CHAR8 values long. The first 3 CHAR8 values are the ISO 639-2 code. // Each entry is 5 CHAR8 values long. The first 3 CHAR8 values are the ISO 639-2 code.
// The last 2 CHAR8 values are the ISO 639-1 code. // The last 2 CHAR8 values are the ISO 639-1 code.
// //
CHAR8 Iso639ToRfc3066ConversionTable[] = GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 Iso639ToRfc3066ConversionTable[] =
"\ "\
aaraa\ aaraa\
abkab\ abkab\