]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/Strings.c
Fixed build failed.
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / FrameworkHiiOnUefiHiiThunk / Strings.c
CommitLineData
26a76fbc 1/** @file\r
0368663f 2 This file implements the protocol functions related to string package.\r
3 \r
bf4a3dbd 4Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
584d5652 5This program and the accompanying materials\r
4259256b 6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15\r
16#include "HiiDatabase.h"\r
17\r
3321fa09 18/**\r
19 Test if all of the characters in a string have corresponding font characters.\r
20\r
21 This is a deprecated API. No Framework HII module is calling it. This function will ASSERT and\r
22 return EFI_UNSUPPORTED.\r
133a9dfb 23\r
3321fa09 24 @param This A pointer to the EFI_HII_PROTOCOL instance.\r
25 @param StringToTest A pointer to a Unicode string.\r
26 @param FirstMissing A pointer to an index into the string. On input, the index of \r
27 the first character in the StringToTest to examine. On exit, the index \r
28 of the first character encountered for which a glyph is unavailable. \r
29 If all glyphs in the string are available, the index is the index of the terminator \r
30 of the string. \r
31 @param GlyphBufferSize A pointer to a value. On output, if the function returns EFI_SUCCESS, \r
cb7d01c0 32 it contains the amount of memory that is required to store the string? glyph equivalent.\r
3321fa09 33\r
34 @retval EFI_UNSUPPORTED The function performs nothing and return EFI_UNSUPPORTED.\r
35**/\r
4259256b 36EFI_STATUS\r
37EFIAPI\r
38HiiTestString (\r
39 IN EFI_HII_PROTOCOL *This,\r
40 IN CHAR16 *StringToTest,\r
41 IN OUT UINT32 *FirstMissing,\r
42 OUT UINT32 *GlyphBufferSize\r
43 )\r
4259256b 44{\r
45 ASSERT (FALSE);\r
3321fa09 46 \r
47 return EFI_UNSUPPORTED;\r
4259256b 48}\r
49\r
133a9dfb 50\r
3321fa09 51/**\r
52 Find the corressponding TAG GUID from a Framework HII Handle given.\r
53\r
54 @param Private The HII Thunk Module Private context.\r
55 @param FwHiiHandle The Framemwork HII Handle.\r
56 @param TagGuid The output of TAG GUID found.\r
133a9dfb 57\r
3321fa09 58 @return NULL If Framework HII Handle is invalid.\r
59 @return The corresponding HII Thunk Context.\r
60**/\r
4259256b 61EFI_STATUS\r
0368663f 62GetTagGuidByFwHiiHandle (\r
63 IN CONST HII_THUNK_PRIVATE_DATA *Private,\r
64 IN FRAMEWORK_EFI_HII_HANDLE FwHiiHandle,\r
4259256b 65 OUT EFI_GUID *TagGuid\r
66 )\r
67{\r
0368663f 68 LIST_ENTRY *Link;\r
69 HII_THUNK_CONTEXT *ThunkContext;\r
4259256b 70\r
71 ASSERT (TagGuid != NULL);\r
72\r
0368663f 73 Link = GetFirstNode (&Private->ThunkContextListHead);\r
74 while (!IsNull (&Private->ThunkContextListHead, Link)) {\r
4259256b 75\r
0368663f 76 ThunkContext = HII_THUNK_CONTEXT_FROM_LINK (Link);\r
4259256b 77\r
0368663f 78 if (FwHiiHandle == ThunkContext->FwHiiHandle) {\r
79 CopyGuid (TagGuid, &ThunkContext->TagGuid);\r
4259256b 80 return EFI_SUCCESS;\r
81 }\r
0368663f 82\r
83 Link = GetNextNode (&Private->ThunkContextListHead, Link);\r
4259256b 84 }\r
0368663f 85\r
4259256b 86 return EFI_NOT_FOUND;\r
87}\r
88\r
3321fa09 89/**\r
90 Create or update the String given a new string and String ID.\r
91\r
92 @param ThunkContext The Thunk Context.\r
8cf6dad8 93 @param Rfc4646AsciiLanguage The RFC 4646 Language code in ASCII string format.\r
3321fa09 94 @param NewString The new string.\r
95 @param StringId The String ID. If StringId is 0, a new String Token\r
96 is created. Otherwise, the String Token StringId is \r
97 updated.\r
98 \r
99\r
100 @retval EFI_SUCCESS The new string is created or updated successfully. \r
101 The new String Token ID is returned in StringId if\r
102 *StringId is 0 on input.\r
103 @return Others The update of string failed. \r
104 \r
105**/\r
106EFI_STATUS\r
107UpdateString (\r
108 IN CONST HII_THUNK_CONTEXT *ThunkContext,\r
8cf6dad8 109 IN CONST CHAR8 *Rfc4646AsciiLanguage,\r
3321fa09 110 IN CHAR16 *NewString,\r
111 IN OUT STRING_REF *StringId\r
112 )\r
113{\r
114 EFI_STRING_ID NewStringId;\r
3321fa09 115\r
8cf6dad8 116 NewStringId = HiiSetString (ThunkContext->UefiHiiHandle, *StringId, NewString, Rfc4646AsciiLanguage);\r
cb7d01c0 117 *StringId = NewStringId;\r
118 if (NewStringId == 0) {\r
3321fa09 119 //\r
120 // Only EFI_INVALID_PARAMETER is defined in HII 0.92 specification.\r
121 //\r
cb7d01c0 122 return EFI_INVALID_PARAMETER;\r
123 } else {\r
124 return EFI_SUCCESS;\r
3321fa09 125 }\r
3321fa09 126}\r
127\r
128/**\r
129 Create or update a String Token in a String Package.\r
130\r
131 If *Reference == 0, a new String Token is created.\r
132\r
133 @param This A pointer to the EFI_HII_PROTOCOL instance.\r
134 @param Language Pointer to a NULL-terminated string containing a single ISO 639-2 language\r
135 identifier, indicating the language to print. A string consisting of\r
136 all spaces indicates that the string is applicable to all languages.\r
137 @param Handle The handle of the language pack to which the string is to be added.\r
26a76fbc 138 @param Reference The string token assigned to the string.\r
3321fa09 139 @param NewString The string to be added.\r
140\r
0368663f 141\r
3321fa09 142 @retval EFI_SUCCESS The string was effectively registered.\r
143 @retval EFI_INVALID_PARAMETER The Handle was unknown. The string is not created or updated in the\r
144 the string package.\r
145**/\r
4259256b 146EFI_STATUS\r
0368663f 147EFIAPI\r
148HiiNewString (\r
149 IN EFI_HII_PROTOCOL *This,\r
150 IN CHAR16 *Language,\r
151 IN FRAMEWORK_EFI_HII_HANDLE Handle,\r
152 IN OUT STRING_REF *Reference,\r
153 IN CHAR16 *NewString\r
4259256b 154 )\r
155{\r
156 EFI_STATUS Status;\r
0368663f 157 HII_THUNK_PRIVATE_DATA *Private;\r
158 EFI_GUID TagGuid;\r
159 LIST_ENTRY *Link;\r
160 HII_THUNK_CONTEXT *ThunkContext;\r
3321fa09 161 HII_THUNK_CONTEXT *StringPackThunkContext;\r
0368663f 162 EFI_STRING_ID StringId;\r
163 EFI_STRING_ID LastStringId;\r
133a9dfb 164 CHAR8 AsciiLanguage[ISO_639_2_ENTRY_SIZE + 1];\r
8ea58c07 165 CHAR16 LanguageCopy[ISO_639_2_ENTRY_SIZE + 1];\r
8cf6dad8 166 CHAR8 *Rfc4646AsciiLanguage;\r
4259256b 167\r
0368663f 168 LastStringId = (EFI_STRING_ID) 0;\r
169 StringId = (EFI_STRING_ID) 0;\r
8cf6dad8 170 Rfc4646AsciiLanguage = NULL;\r
4259256b 171\r
0368663f 172 if (Language != NULL) {\r
133a9dfb 173 ZeroMem (AsciiLanguage, sizeof (AsciiLanguage));;\r
8ea58c07 174 ZeroMem (LanguageCopy, sizeof (LanguageCopy));\r
175 CopyMem (LanguageCopy, Language, ISO_639_2_ENTRY_SIZE * sizeof (CHAR16));\r
176 UnicodeStrToAsciiStr (LanguageCopy, AsciiLanguage);\r
7c9d25ae 177 Rfc4646AsciiLanguage = ConvertLanguagesIso639ToRfc4646 (AsciiLanguage);\r
8cf6dad8 178 ASSERT (Rfc4646AsciiLanguage != NULL);\r
ea58467b 179 }\r
4259256b 180\r
3321fa09 181 Private = HII_THUNK_PRIVATE_DATA_FROM_THIS(This);\r
4259256b 182\r
3321fa09 183 StringPackThunkContext = FwHiiHandleToThunkContext (Private, Handle);\r
184 if (StringPackThunkContext == NULL) {\r
185 return EFI_INVALID_PARAMETER;\r
186 }\r
187\r
188 if (StringPackThunkContext->SharingStringPack) {\r
189 Status = GetTagGuidByFwHiiHandle (Private, Handle, &TagGuid);\r
190 ASSERT_EFI_ERROR (Status);\r
191\r
192 Link = GetFirstNode (&Private->ThunkContextListHead);\r
193 while (!IsNull (&Private->ThunkContextListHead, Link)) {\r
194 ThunkContext = HII_THUNK_CONTEXT_FROM_LINK (Link);\r
0368663f 195\r
3321fa09 196 if (CompareGuid (&TagGuid, &ThunkContext->TagGuid)) {\r
197 if (ThunkContext->SharingStringPack) {\r
198 StringId = *Reference;\r
8cf6dad8 199 Status = UpdateString (ThunkContext, Rfc4646AsciiLanguage, NewString, &StringId);\r
3321fa09 200 if (EFI_ERROR (Status)) {\r
201 break;\r
4259256b 202 }\r
3321fa09 203 \r
204 DEBUG_CODE_BEGIN ();\r
205 if (*Reference == 0) {\r
206 //\r
207 // When creating new string token, make sure all created token is the same\r
208 // for all string packages registered using FW HII interface.\r
209 //\r
210 if (LastStringId == (EFI_STRING_ID) 0) {\r
211 LastStringId = StringId;\r
212 } else {\r
213 if (LastStringId != StringId) {\r
214 ASSERT(FALSE);\r
215 }\r
216 }\r
217 }\r
218 DEBUG_CODE_END ();\r
219 \r
4259256b 220 }\r
221 }\r
0368663f 222\r
3321fa09 223 Link = GetNextNode (&Private->ThunkContextListHead, Link);\r
224 }\r
225 } else {\r
226 StringId = *Reference;\r
8cf6dad8 227 Status = UpdateString (StringPackThunkContext, Rfc4646AsciiLanguage, NewString, &StringId);\r
4259256b 228 }\r
229\r
3321fa09 230 if (!EFI_ERROR (Status)) {\r
0368663f 231 if (*Reference == 0) {\r
232 *Reference = StringId;\r
233 }\r
4259256b 234 } else {\r
0368663f 235 //\r
3321fa09 236 // Only EFI_INVALID_PARAMETER is defined in HII 0.92 specification.\r
0368663f 237 //\r
3321fa09 238 Status = EFI_INVALID_PARAMETER;\r
4259256b 239 }\r
240 \r
46b5ebc8 241 return Status;\r
4259256b 242}\r
243\r
3321fa09 244/**\r
245 This function removes any new strings that were added after the initial string export for this handle.\r
246 UEFI HII String Protocol does not have Reset String function. This function perform nothing.\r
247\r
248 @param This A pointer to the EFI_HII_PROTOCOL instance.\r
249 @param Handle The HII handle on which the string resides.\r
250\r
251 @retval EFI_SUCCESS This function is a NOP and always return EFI_SUCCESS.\r
252\r
253**/\r
4259256b 254EFI_STATUS\r
255EFIAPI\r
256HiiResetStrings (\r
257 IN EFI_HII_PROTOCOL *This,\r
258 IN FRAMEWORK_EFI_HII_HANDLE Handle\r
259 )\r
4259256b 260{\r
0368663f 261 return EFI_SUCCESS;\r
4259256b 262}\r
263\r
3321fa09 264/**\r
265 This function extracts a string from a package already registered with the EFI HII database.\r
266\r
267 @param This A pointer to the EFI_HII_PROTOCOL instance.\r
268 @param Handle The HII handle on which the string resides.\r
269 @param Token The string token assigned to the string.\r
270 @param Raw If TRUE, the string is returned unedited in the internal storage format described\r
271 above. If false, the string returned is edited by replacing <cr> with <space>\r
272 and by removing special characters such as the <wide> prefix.\r
273 @param LanguageString Pointer to a NULL-terminated string containing a single ISO 639-2 language\r
274 identifier, indicating the language to print. If the LanguageString is empty (starts\r
275 with a NULL), the default system language will be used to determine the language.\r
276 @param BufferLength Length of the StringBuffer. If the status reports that the buffer width is too\r
277 small, this parameter is filled with the length of the buffer needed.\r
278 @param StringBuffer The buffer designed to receive the characters in the string. Type EFI_STRING is\r
279 defined in String.\r
280\r
281 @retval EFI_INVALID_PARAMETER If input parameter is invalid.\r
282 @retval EFI_BUFFER_TOO_SMALL If the *BufferLength is too small.\r
283 @retval EFI_SUCCESS Operation is successful.\r
284\r
285**/\r
4259256b 286EFI_STATUS\r
287EFIAPI\r
cdaf7905 288HiiThunkGetString (\r
133a9dfb 289 IN EFI_HII_PROTOCOL *This,\r
290 IN FRAMEWORK_EFI_HII_HANDLE Handle,\r
291 IN STRING_REF Token,\r
292 IN BOOLEAN Raw,\r
293 IN CHAR16 *LanguageString,\r
26a76fbc 294 IN OUT UINTN *BufferLength,\r
133a9dfb 295 OUT EFI_STRING StringBuffer\r
4259256b 296 )\r
4259256b 297{\r
0368663f 298 HII_THUNK_PRIVATE_DATA *Private;\r
cb7d01c0 299 CHAR8 *Iso639AsciiLanguage;\r
8cf6dad8 300 CHAR8 *Rfc4646AsciiLanguage;\r
cb7d01c0 301 CHAR8 *SupportedLanguages;\r
302 CHAR8 *PlatformLanguage;\r
303 CHAR8 *BestLanguage;\r
133a9dfb 304 EFI_HII_HANDLE UefiHiiHandle;\r
305 EFI_STATUS Status;\r
4259256b 306\r
0368663f 307 Private = HII_THUNK_PRIVATE_DATA_FROM_THIS(This);\r
4259256b 308\r
8cf6dad8 309 Rfc4646AsciiLanguage = NULL;\r
43ffc47f
LG
310 SupportedLanguages = NULL;\r
311 PlatformLanguage = NULL;\r
312 Status = EFI_SUCCESS;\r
133a9dfb 313\r
314 if (LanguageString != NULL) {\r
315 Iso639AsciiLanguage = AllocateZeroPool (StrLen (LanguageString) + 1);\r
316 if (Iso639AsciiLanguage == NULL) {\r
4259256b 317 return EFI_OUT_OF_RESOURCES;\r
318 }\r
133a9dfb 319 UnicodeStrToAsciiStr (LanguageString, Iso639AsciiLanguage);\r
ea58467b 320\r
133a9dfb 321 //\r
322 // Caller of Framework HII Interface uses the Language Identification String defined \r
8cf6dad8 323 // in Iso639. So map it to the Language Identifier defined in RFC4646.\r
133a9dfb 324 //\r
7c9d25ae 325 Rfc4646AsciiLanguage = ConvertLanguagesIso639ToRfc4646 (Iso639AsciiLanguage);\r
f324bf4d 326 FreePool (Iso639AsciiLanguage);\r
1668bd49 327\r
328 //\r
8cf6dad8 329 // If Rfc4646AsciiLanguage is NULL, more language mapping must be added to \r
330 // Iso639ToRfc4646Map.\r
1668bd49 331 //\r
8cf6dad8 332 ASSERT (Rfc4646AsciiLanguage != NULL);\r
4259256b 333 }\r
334\r
133a9dfb 335 UefiHiiHandle = FwHiiHandleToUefiHiiHandle (Private, Handle);\r
336 if (UefiHiiHandle == NULL) {\r
337 Status = EFI_NOT_FOUND;\r
338 goto Done;\r
339 }\r
4259256b 340\r
f324bf4d 341 //\r
342 // Get the languages that the package specified by HiiHandle supports\r
343 //\r
344 SupportedLanguages = HiiGetSupportedLanguages (UefiHiiHandle);\r
345 if (SupportedLanguages == NULL) {\r
43ffc47f 346 goto Done;\r
f324bf4d 347 }\r
cb7d01c0 348\r
f324bf4d 349 //\r
350 // Get the current platform language setting\r
351 //\r
f01b91ae 352 GetEfiGlobalVariable2 (L"PlatformLang", (VOID**)&PlatformLanguage, NULL);\r
cb7d01c0 353\r
f324bf4d 354 //\r
355 // Get the best matching language from SupportedLanguages\r
356 //\r
357 BestLanguage = GetBestLanguage (\r
358 SupportedLanguages, \r
359 FALSE, // RFC 4646 mode\r
43ffc47f
LG
360 (Rfc4646AsciiLanguage != NULL) ? Rfc4646AsciiLanguage : "", // Highest priority \r
361 (PlatformLanguage != NULL) ? PlatformLanguage : "", // Next highest priority\r
f324bf4d 362 SupportedLanguages, // Lowest priority \r
363 NULL\r
364 );\r
43ffc47f
LG
365 if (BestLanguage != NULL) {\r
366 Status = mHiiStringProtocol->GetString (\r
367 mHiiStringProtocol,\r
368 BestLanguage,\r
369 UefiHiiHandle,\r
370 Token,\r
371 StringBuffer,\r
26a76fbc 372 BufferLength,\r
43ffc47f
LG
373 NULL\r
374 );\r
375 FreePool (BestLanguage);\r
376 } else {\r
f324bf4d 377 Status = EFI_INVALID_PARAMETER;\r
4259256b 378 }\r
379\r
133a9dfb 380Done:\r
f324bf4d 381 if (Rfc4646AsciiLanguage != NULL) {\r
382 FreePool (Rfc4646AsciiLanguage);\r
7001eaf8 383 }\r
43ffc47f
LG
384\r
385 if (SupportedLanguages != NULL) {\r
386 FreePool (SupportedLanguages);\r
387 }\r
388\r
389 if (PlatformLanguage != NULL) {\r
390 FreePool (PlatformLanguage);\r
391 }\r
133a9dfb 392 return Status;\r
4259256b 393}\r
394\r
3321fa09 395/**\r
4259256b 396\r
397 This function allows a program to extract a part of a string of not more than a given width.\r
398 With repeated calls, this allows a calling program to extract "lines" of text that fit inside\r
399 columns. The effort of measuring the fit of strings inside columns is localized to this call.\r
400\r
3321fa09 401 This is a deprecated API. No Framework HII module is calling it. This function will ASSERT and\r
402 return EFI_UNSUPPORTED.\r
403\r
404 @param This A pointer to the EFI_HII_PROTOCOL instance.\r
405 @param Handle The HII handle on which the string resides.\r
406 @param Token The string token assigned to the string.\r
26a76fbc
LG
407 @param Index On input, the offset into the string where the line is to start.\r
408 On output, the index is updated to point to beyond the last character returned\r
409 in the call.\r
410 @param LineWidth The maximum width of the line in units of narrow glyphs.\r
3321fa09 411 @param LanguageString Pointer to a NULL-terminated string containing a single ISO 639-2 language\r
412 identifier, indicating the language to print. If the LanguageString is empty (starts\r
413 with a NULL), the default system language will be used to determine the language.\r
414 @param BufferLength Length of the StringBuffer. If the status reports that the buffer width is too\r
415 small, this parameter is filled with the length of the buffer needed.\r
416 @param StringBuffer The buffer designed to receive the characters in the string. Type EFI_STRING is\r
417 defined in String.\r
418\r
419 @retval EFI_UNSUPPORTED.\r
420**/\r
421EFI_STATUS\r
422EFIAPI\r
423HiiGetLine (\r
424 IN EFI_HII_PROTOCOL *This,\r
425 IN FRAMEWORK_EFI_HII_HANDLE Handle,\r
426 IN STRING_REF Token,\r
427 IN OUT UINT16 *Index,\r
428 IN UINT16 LineWidth,\r
429 IN CHAR16 *LanguageString,\r
430 IN OUT UINT16 *BufferLength,\r
431 OUT EFI_STRING StringBuffer\r
432 )\r
4259256b 433{\r
434 ASSERT (FALSE);\r
435 return EFI_UNSUPPORTED;\r
436}\r
437\r
1668bd49 438\r