]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/HiiDatabase.c
Add in thunk support for HiiGetSecondaryLanguages and HiiGetPrimaryLanguages
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / FrameworkHiiToUefiHiiThunk / HiiDatabase.c
1 /**@file
2 Framework to UEFI 2.1 HII Thunk. The driver consume UEFI HII protocols
3 to produce a Framework HII protocol.
4
5 Copyright (c) 2008, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #include "HiiDatabase.h"
17
18
19 EFI_HII_THUNK_PRIVATE_DATA HiiThunkPrivateDataTempate = {
20 {//Signature
21 EFI_HII_THUNK_DRIVER_DATA_SIGNATURE
22 },
23 {//Handle
24 (EFI_HANDLE) NULL
25 },
26 { //Hii
27 HiiNewPack,
28 HiiRemovePack,
29 HiiFindHandles,
30 HiiExportDatabase,
31
32 HiiTestString,
33 HiiGetGlyph,
34 HiiGlyphToBlt,
35
36 HiiNewString,
37 HiiGetPrimaryLanguages,
38 HiiGetSecondaryLanguages,
39 HiiGetString,
40 HiiResetStrings,
41 HiiGetLine,
42 HiiGetForms,
43 HiiGetDefaultImage,
44 HiiUpdateForm,
45
46 HiiGetKeyboardLayout
47 },
48 { //StaticHiiHandle
49 //The FRAMEWORK_EFI_HII_HANDLE starts from 1
50 // and increase upwords untill reach 2^(sizeof (FRAMEWORK_EFI_HII_HANDLE)) - 1.
51 // The code will assert to prevent overflow.
52 (FRAMEWORK_EFI_HII_HANDLE) 1
53 },
54 {
55 NULL, NULL //HiiHandleLinkList
56 },
57 };
58
59 EFI_HII_DATABASE_PROTOCOL *mUefiHiiDatabaseProtocol;
60 EFI_HII_FONT_PROTOCOL *mUefiHiiFontProtocol;
61 EFI_HII_IMAGE_PROTOCOL *mUefiHiiImageProtocol;
62 EFI_HII_STRING_PROTOCOL *mUefiStringProtocol;
63
64 EFI_STATUS
65 EFIAPI
66 InitializeHiiDatabase (
67 IN EFI_HANDLE ImageHandle,
68 IN EFI_SYSTEM_TABLE *SystemTable
69 )
70 /*++
71
72 Routine Description:
73 Initialize HII Database
74
75 Arguments:
76 (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)
77
78 Returns:
79 EFI_SUCCESS - Setup loaded.
80 other - Setup Error
81
82 --*/
83 {
84 EFI_HII_THUNK_PRIVATE_DATA *HiiData;
85 EFI_HANDLE Handle;
86 EFI_STATUS Status;
87
88 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiHiiProtocolGuid);
89
90 HiiData = AllocateCopyPool (sizeof (EFI_HII_THUNK_PRIVATE_DATA), &HiiThunkPrivateDataTempate);
91 ASSERT (HiiData != NULL);
92 InitializeListHead (&HiiData->HiiThunkHandleMappingDBListHead);
93
94 Status = gBS->LocateProtocol (
95 &gEfiHiiDatabaseProtocolGuid,
96 NULL,
97 (VOID **) &mUefiHiiDatabaseProtocol
98 );
99 ASSERT_EFI_ERROR (Status);
100
101 Status = gBS->LocateProtocol (
102 &gEfiHiiFontProtocolGuid,
103 NULL,
104 (VOID **) &mUefiHiiFontProtocol
105 );
106 ASSERT_EFI_ERROR (Status);
107
108 Status = gBS->LocateProtocol (
109 &gEfiHiiImageProtocolGuid,
110 NULL,
111 (VOID **) &mUefiHiiImageProtocol
112 );
113 ASSERT_EFI_ERROR (Status);
114
115 Status = gBS->LocateProtocol (
116 &gEfiHiiStringProtocolGuid,
117 NULL,
118 (VOID **) &mUefiStringProtocol
119 );
120 ASSERT_EFI_ERROR (Status);
121
122 //
123 // Install protocol interface
124 //
125 Handle = NULL;
126 Status = gBS->InstallProtocolInterface (
127 &HiiData->Handle,
128 &gEfiHiiProtocolGuid,
129 EFI_NATIVE_INTERFACE,
130 (VOID *) &HiiData->Hii
131 );
132 ASSERT_EFI_ERROR (Status);
133
134 return Status;
135 }
136
137 EFI_STATUS
138 EFIAPI
139 HiiFindHandles (
140 IN EFI_HII_PROTOCOL *This,
141 IN OUT UINT16 *HandleBufferLength,
142 OUT FRAMEWORK_EFI_HII_HANDLE Handle[1]
143 )
144 /*++
145
146 Routine Description:
147 Determines the handles that are currently active in the database.
148
149 Arguments:
150
151 Returns:
152
153 --*/
154 {
155 ASSERT (FALSE);
156 return EFI_SUCCESS;
157 }
158
159 EFI_STATUS
160 EFIAPI
161 HiiGetPrimaryLanguages (
162 IN EFI_HII_PROTOCOL *This,
163 IN FRAMEWORK_EFI_HII_HANDLE Handle,
164 OUT EFI_STRING *LanguageString
165 )
166 /*++
167
168 Routine Description:
169
170 This function allows a program to determine what the primary languages that are supported on a given handle.
171
172 Arguments:
173
174 Returns:
175
176 --*/
177 {
178 EFI_HII_THUNK_PRIVATE_DATA *Private;
179 EFI_HII_HANDLE UefiHiiHandle;
180 CHAR8 *AsciiLanguageCodes;
181 CHAR16 *UnicodeLanguageCodes;
182
183 Private = EFI_HII_THUNK_PRIVATE_DATA_FROM_THIS(This);
184
185
186
187 UefiHiiHandle = FrameworkHiiHandleToUefiHiiHandle (Private, Handle);
188 if (UefiHiiHandle == NULL) {
189 return EFI_INVALID_PARAMETER;
190 }
191
192 AsciiLanguageCodes = HiiLibGetSupportedLanguages (UefiHiiHandle);
193
194 if (AsciiLanguageCodes == NULL) {
195 return EFI_INVALID_PARAMETER;
196 }
197
198 UnicodeLanguageCodes = AllocateZeroPool (AsciiStrSize (AsciiLanguageCodes) * sizeof (CHAR16));
199 if (UnicodeLanguageCodes == NULL) {
200 return EFI_OUT_OF_RESOURCES;
201 }
202
203 //
204 // The language returned is in RFC 3066 format.
205 //
206 *LanguageString = AsciiStrToUnicodeStr (AsciiLanguageCodes, UnicodeLanguageCodes);
207
208 return EFI_SUCCESS;
209 }
210
211 EFI_STATUS
212 EFIAPI
213 HiiGetSecondaryLanguages (
214 IN EFI_HII_PROTOCOL *This,
215 IN FRAMEWORK_EFI_HII_HANDLE Handle,
216 IN CHAR16 *PrimaryLanguage,
217 OUT EFI_STRING *LanguageString
218 )
219 /*++
220
221 Routine Description:
222
223 This function allows a program to determine which secondary languages are supported
224 on a given handle for a given primary language.
225
226 Arguments:
227
228 Returns:
229
230 --*/
231 {
232 EFI_HII_THUNK_PRIVATE_DATA *Private;
233 EFI_HII_HANDLE UefiHiiHandle;
234 CHAR8 *AsciiPrimaryLanguage;
235 CHAR8 *AsciiLanguageCodes;
236 CHAR16 *UnicodeLanguageCodes;
237
238 Private = EFI_HII_THUNK_PRIVATE_DATA_FROM_THIS(This);
239
240
241
242 UefiHiiHandle = FrameworkHiiHandleToUefiHiiHandle (Private, Handle);
243 if (UefiHiiHandle == NULL) {
244 return EFI_INVALID_PARAMETER;
245 }
246
247 AsciiPrimaryLanguage = AllocateZeroPool (StrLen (PrimaryLanguage) + 1);
248
249 UnicodeStrToAsciiStr (PrimaryLanguage, AsciiPrimaryLanguage);
250
251 AsciiLanguageCodes = HiiLibGetSupportedSecondaryLanguages (UefiHiiHandle, AsciiPrimaryLanguage);
252
253 if (AsciiLanguageCodes == NULL) {
254 return EFI_INVALID_PARAMETER;
255 }
256
257 UnicodeLanguageCodes = AllocateZeroPool (AsciiStrSize (AsciiLanguageCodes) * sizeof (CHAR16));
258 if (UnicodeLanguageCodes == NULL) {
259 return EFI_OUT_OF_RESOURCES;
260 }
261
262 //
263 // The language returned is in RFC 3066 format.
264 //
265 *LanguageString = AsciiStrToUnicodeStr (AsciiLanguageCodes, UnicodeLanguageCodes);
266
267 return EFI_SUCCESS;
268 }
269
270