Apply GetBestLanguage() in UefiLib to get the driver name from Component Name (2) protocol.

RFC 4646 & ISO 639-2 Language are not supposed to be mixed. 

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@7940 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
qhuang8 2009-03-24 15:41:50 +00:00
parent 35db118601
commit f6a6518251
2 changed files with 65 additions and 108 deletions

View File

@ -39,8 +39,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <Protocol/DevicePathToText.h> #include <Protocol/DevicePathToText.h>
#include <Protocol/DevicePath.h> #include <Protocol/DevicePath.h>
#include <Guid/GlobalVariable.h>
#include <Library/BaseLib.h> #include <Library/BaseLib.h>
#include <Library/DebugLib.h> #include <Library/DebugLib.h>
#include <Library/UefiLib.h> #include <Library/UefiLib.h>
@ -53,7 +51,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <Library/ExtendedIfrSupportLib.h> #include <Library/ExtendedIfrSupportLib.h>
#include <Library/BaseMemoryLib.h> #include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h> #include <Library/MemoryAllocationLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/DevicePathLib.h> #include <Library/DevicePathLib.h>
#include "PlatOverMngr.h" #include "PlatOverMngr.h"
@ -93,7 +90,6 @@ EFI_LOADED_IMAGE_PROTOCOL *mDriverImageProtocol[MAX_CHOICE_NUM];
EFI_DEVICE_PATH_PROTOCOL *mControllerDevicePathProtocol[MAX_CHOICE_NUM]; EFI_DEVICE_PATH_PROTOCOL *mControllerDevicePathProtocol[MAX_CHOICE_NUM];
UINTN mSelectedDriverImageNum; UINTN mSelectedDriverImageNum;
UINTN mLastSavedDriverImageNum; UINTN mLastSavedDriverImageNum;
CHAR8 mLanguage[RFC_3066_ENTRY_SIZE];
UINT16 mCurrentPage; UINT16 mCurrentPage;
/** /**
@ -113,55 +109,71 @@ DevicePathToStr (
); );
/** /**
Do string convertion for the ComponentName supported language. It do Worker function to get the driver name by ComponentName or ComponentName2 protocol
the convertion just for english language code from RFC 3066 to ISO 639-2. according to the driver binding handle.
Then it will check whether the converted language is in the supported language list.
If not supported, NULL is returned.
If Language is not english, NULL is returned.
@param SupportedLanguages Pointer to ComponentName supported language string list. ISO 639-2 language @param DriverBindingHandle The Handle of DriverBinding.
@param Language The language string. RFC 3066 language @param ProtocolGuid The pointer to Component Name (2) protocol GUID.
@param VariableName The name of the RFC 4646 or ISO 639-2 language variable.
@return English language string (ISO 639-2) @retval !NULL Pointer into the image name if the image name is found,
@return NULL if the conertion is not successful. @retval NULL Pointer to NULL if the image name is not found.
**/ **/
CHAR8 * CHAR16 *
ConvertComponentNameSupportLanguage ( GetComponentNameWorker (
IN CHAR8 *SupportedLanguages, IN EFI_HANDLE DriverBindingHandle,
IN CHAR8 *Language IN EFI_GUID *ProtocolGuid,
IN CONST CHAR16 *VariableName
) )
{ {
CHAR8 *LangCode; EFI_STATUS Status;
LangCode = NULL; EFI_COMPONENT_NAME_PROTOCOL *ComponentName;
CHAR16 *DriverName;
CHAR8 *Language;
CHAR8 *BestLanguage;
// Status = gBS->OpenProtocol (
// Check the input language is English DriverBindingHandle,
// ProtocolGuid,
if (AsciiStrnCmp (Language, "en-", 3) != 0) { (VOID *) &ComponentName,
NULL,
NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
return NULL; return NULL;
} }
// //
// Check SupportedLanguages format // Find the best matching language.
// //
if (AsciiStrStr (SupportedLanguages, "en-") != NULL) { Language = GetEfiGlobalVariable (VariableName);
// BestLanguage = GetBestLanguage (
// Create RFC 3066 language ComponentName->SupportedLanguages,
// (BOOLEAN) (ProtocolGuid == &gEfiComponentNameProtocolGuid),
LangCode = AllocateZeroPool(AsciiStrSize (Language)); Language,
AsciiStrCpy (LangCode, Language); NULL
} else if (AsciiStrStr (SupportedLanguages, "en") != NULL) { );
//
// Create ISO 639-2 Language DriverName = NULL;
// if (BestLanguage != NULL) {
LangCode = AllocateZeroPool(4); ComponentName->GetDriverName (
AsciiStrCpy (LangCode, "eng"); ComponentName,
BestLanguage,
&DriverName
);
FreePool (BestLanguage);
} }
return LangCode; if (Language != NULL) {
FreePool (Language);
}
return DriverName;
} }
/** /**
Get the driver name by ComponentName or ComponentName2 protocol Get the driver name by ComponentName or ComponentName2 protocol
according to the driver binding handle according to the driver binding handle
@ -177,59 +189,17 @@ GetComponentName (
IN EFI_HANDLE DriverBindingHandle IN EFI_HANDLE DriverBindingHandle
) )
{ {
EFI_STATUS Status;
EFI_COMPONENT_NAME_PROTOCOL *ComponentName;
EFI_COMPONENT_NAME2_PROTOCOL *ComponentName2;
CHAR8 *SupportedLanguage;
CHAR16 *DriverName; CHAR16 *DriverName;
ComponentName = NULL; //
ComponentName2 = NULL; // Try RFC 4646 Component Name 2 protocol first.
Status = gBS->OpenProtocol ( //
DriverBindingHandle, DriverName = GetComponentNameWorker (DriverBindingHandle, &gEfiComponentName2ProtocolGuid, L"PlatformLang");
&gEfiComponentName2ProtocolGuid, if (DriverName == NULL) {
(VOID **) &ComponentName2, //
NULL, // If we can not get driver name from Component Name 2 protocol, we can try ISO 639-2 Component Name protocol.
NULL, //
EFI_OPEN_PROTOCOL_GET_PROTOCOL DriverName = GetComponentNameWorker (DriverBindingHandle, &gEfiComponentNameProtocolGuid, L"Lang");
);
if (EFI_ERROR(Status)) {
Status = gBS->OpenProtocol (
DriverBindingHandle,
&gEfiComponentNameProtocolGuid,
(VOID **) &ComponentName,
NULL,
NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
}
Status = EFI_SUCCESS;
DriverName = NULL;
if (ComponentName != NULL) {
if (ComponentName->GetDriverName != NULL) {
SupportedLanguage = ConvertComponentNameSupportLanguage (ComponentName->SupportedLanguages, mLanguage);
if (SupportedLanguage != NULL) {
Status = ComponentName->GetDriverName (
ComponentName,
SupportedLanguage,
&DriverName
);
FreePool (SupportedLanguage);
}
}
} else if (ComponentName2 != NULL) {
if (ComponentName2->GetDriverName != NULL) {
Status = ComponentName2->GetDriverName (
ComponentName2,
mLanguage,
&DriverName
);
}
}
if (EFI_ERROR (Status)) {
return NULL;
} }
return DriverName; return DriverName;
@ -237,7 +207,7 @@ GetComponentName (
/** /**
Get the image name from EFI UI section. Get the image name from EFI UI section.
Get FV protocol by its loaded image protoocl to abastract EFI UI section. Get FV protocol by its loaded image protocol to abstract EFI UI section.
@param Image Pointer to the loaded image protocol @param Image Pointer to the loaded image protocol
@ -340,7 +310,6 @@ UpdateDeviceSelectPage (
{ {
EFI_HII_UPDATE_DATA UpdateData; EFI_HII_UPDATE_DATA UpdateData;
EFI_STATUS Status; EFI_STATUS Status;
UINTN LangSize;
UINTN Index; UINTN Index;
UINTN DevicePathHandleCount; UINTN DevicePathHandleCount;
CHAR16 *NewString; CHAR16 *NewString;
@ -356,19 +325,6 @@ UpdateDeviceSelectPage (
// //
mCurrentPage = FORM_ID_DEVICE; mCurrentPage = FORM_ID_DEVICE;
//
// Get Platform supported Language (RFC_3066 format)
//
LangSize = RFC_3066_ENTRY_SIZE;
Status = gRT->GetVariable (
L"PlatformLang",
&gEfiGlobalVariableGuid,
NULL,
&LangSize,
mLanguage
);
ASSERT_EFI_ERROR (Status);
// //
// Initial the mapping database in memory // Initial the mapping database in memory
// //

View File

@ -62,11 +62,12 @@
ExtendedIfrSupportLib ExtendedIfrSupportLib
BaseMemoryLib BaseMemoryLib
MemoryAllocationLib MemoryAllocationLib
UefiRuntimeServicesTableLib
DevicePathLib DevicePathLib
[Guids] [Guids]
gEfiGlobalVariableGuid ## CONSUMED ## Variable:L"PlatformLang" this variable specifies the platform supported language string (RFC 3066 format) ## This GUID C Name is not required for build since it is from UefiLib and not directly used by this module source.
## gEfiGlobalVariableGuid ## SOMETIMES_CONSUMED ## Variable:L"PlatformLang" this variable specifies the platform supported language string (RFC 4646 format)
## gEfiGlobalVariableGuid ## SOMETIMES_CONSUMED ## Variable:L"Lang" this variable specifies the platform supported language string (ISO 639-2 format)
[Protocols] [Protocols]
gEfiComponentName2ProtocolGuid ## SOMETIMES_CONSUMED (Get Driver Name if ComponentName2Protocol exists) gEfiComponentName2ProtocolGuid ## SOMETIMES_CONSUMED (Get Driver Name if ComponentName2Protocol exists)