]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkPkg/Library/FrameworkHiiLib/HiiLib.c
correct some code style issue
[mirror_edk2.git] / IntelFrameworkPkg / Library / FrameworkHiiLib / HiiLib.c
CommitLineData
0a869bf8 1/** @file\r
2 HII Library implementation that uses DXE protocols and services.\r
3\r
4 Copyright (c) 2006, Intel Corporation<BR>\r
53f93f7e 5 All rights reserved. This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
0a869bf8 9\r
53f93f7e 10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
0a869bf8 12\r
0a869bf8 13**/\r
14\r
ed7748fe 15\r
564995cd 16#include <FrameworkDxe.h>\r
ed7748fe 17\r
dc7b4a5c 18#include <Protocol/FrameworkHii.h>\r
19\r
8e5b17b2 20#include <Library/FrameworkHiiLib.h>\r
53f93f7e 21#include <Library/DebugLib.h>\r
22#include <Library/MemoryAllocationLib.h>\r
dc7b4a5c 23#include <Library/UefiBootServicesTableLib.h>\r
bb557845 24\r
dc7b4a5c 25EFI_HII_PROTOCOL *mHii = NULL;\r
26\r
bb557845 27/**\r
28 Library constustor function for HiiLib library instance locate the\r
29 gEfiHiiProtocolGuid firstly, the other interface in this library\r
30 instance will dependent on the protocol of gEfiHiiProtocolGuid.\r
31 So the depex of gEfiHiiProtocolGuid is required for this library \r
32 instance.\r
33 If protocol of gEfiHiiProtocolGuid is not installed, then ASSERT().\r
34 \r
a387653d 35 @param ImageHandle The image handle of driver module who use this library \r
36 instance.\r
37 @param SystemTable Pointer to the EFI System Table.\r
38 @retval EFI_SUCCESS library constuctor always success.\r
bb557845 39**/\r
dc7b4a5c 40EFI_STATUS\r
41EFIAPI\r
42FrameworkHiiLibConstructor (\r
a387653d 43 IN EFI_HANDLE ImageHandle,\r
44 IN EFI_SYSTEM_TABLE *SystemTable\r
dc7b4a5c 45 )\r
46{\r
47 EFI_STATUS Status;\r
48 \r
49 Status = gBS->LocateProtocol (\r
50 &gEfiHiiProtocolGuid,\r
51 NULL,\r
52 (VOID **) &mHii\r
53 );\r
54 ASSERT_EFI_ERROR (Status);\r
55 ASSERT (mHii != NULL);\r
56\r
57 return EFI_SUCCESS;\r
58}\r
59\r
bb557845 60/**\r
61 This function is internal function that prepare and create\r
62 HII packages with given number and package's guid.\r
63 It is invoked by HiiAddPackages() and PreparePackages() interface.\r
64 If the parameter of package's number is 0, then ASSERT().\r
65 \r
66 @param NumberOfPackages Given number of package item in a HII package list.\r
67 @param Guid Given GUID of a HII package list.\r
68 @param Marker Package's content list.\r
69 \r
70 @return pointer to new created HII package list.\r
71**/\r
dc7b4a5c 72EFI_HII_PACKAGES *\r
73InternalPreparePackages (\r
a387653d 74 IN UINTN NumberOfPackages,\r
75 IN CONST EFI_GUID *Guid OPTIONAL,\r
76 IN VA_LIST Marker\r
dc7b4a5c 77 )\r
78{\r
79 EFI_HII_PACKAGES *HiiPackages;\r
80 VOID **Package;\r
81 UINTN Index;\r
82\r
83 ASSERT (NumberOfPackages > 0);\r
84\r
85 HiiPackages = AllocateZeroPool (sizeof (EFI_HII_PACKAGES) + NumberOfPackages * sizeof (VOID *));\r
86 ASSERT (HiiPackages != NULL);\r
87\r
88 HiiPackages->GuidId = (EFI_GUID *) Guid;\r
89 HiiPackages->NumberOfPackages = NumberOfPackages;\r
90 Package = (VOID **) (((UINT8 *) HiiPackages) + sizeof (EFI_HII_PACKAGES));\r
91\r
92 for (Index = 0; Index < NumberOfPackages; Index++) {\r
93 *Package = VA_ARG (Marker, VOID *);\r
94 Package++;\r
95 }\r
96\r
97 return HiiPackages;\r
98\r
99}\r
100\r
0a869bf8 101/**\r
102 This function allocates pool for an EFI_HII_PACKAGES structure\r
103 with enough space for the variable argument list of package pointers.\r
53f93f7e 104 The allocated structure is initialized using NumberOfPackages, Guid,\r
0a869bf8 105 and the variable length argument list of package pointers.\r
106\r
cd15d471 107 @param NumberOfPackages The number of HII packages to prepare.\r
108 @param Guid Package GUID.\r
109 @Param ... The variable argument list of package pointers.\r
0a869bf8 110\r
111 @return The allocated and initialized packages.\r
0a869bf8 112**/\r
113EFI_HII_PACKAGES *\r
114EFIAPI\r
115PreparePackages (\r
a387653d 116 IN UINTN NumberOfPackages,\r
117 IN CONST EFI_GUID *Guid OPTIONAL,\r
0a869bf8 118 ...\r
119 )\r
120{\r
121 VA_LIST Args;\r
0a869bf8 122\r
dc7b4a5c 123 VA_START (Args, Guid);\r
0a869bf8 124\r
dc7b4a5c 125 return InternalPreparePackages (NumberOfPackages, Guid, Args);\r
126}\r
0a869bf8 127\r
0a869bf8 128\r
dc7b4a5c 129/**\r
130 This function allocates pool for an EFI_HII_PACKAGE_LIST structure\r
131 with additional space that is big enough to host all packages described by the variable \r
132 argument list of package pointers. The allocated structure is initialized using NumberOfPackages, \r
133 GuidId, and the variable length argument list of package pointers.\r
0a869bf8 134\r
dc7b4a5c 135 Then, EFI_HII_PACKAGE_LIST will be register to the default System HII Database. The\r
136 Handle to the newly registered Package List is returned throught HiiHandle.\r
137\r
7459094d 138 @param NumberOfPackages The number of HII packages to register.\r
139 @param GuidId Package List GUID ID.\r
140 @param DriverHandle The pointer of driver handle\r
dc7b4a5c 141 @param HiiHandle The ID used to retrieve the Package List later.\r
7459094d 142 @param ... The variable argument list describing all HII Package.\r
dc7b4a5c 143\r
144 @return\r
145 The allocated and initialized packages.\r
dc7b4a5c 146**/\r
dc7b4a5c 147EFI_STATUS\r
148EFIAPI\r
568f78ab 149HiiLibAddPackages (\r
a387653d 150 IN UINTN NumberOfPackages,\r
151 IN CONST EFI_GUID *GuidId,\r
152 IN EFI_HANDLE DriverHandle, OPTIONAL\r
153 OUT EFI_HII_HANDLE *HiiHandle, OPTIONAL\r
dc7b4a5c 154 ...\r
155 )\r
156{\r
157 VA_LIST Args;\r
158 EFI_HII_PACKAGES *FrameworkHiiPacages;\r
159 FRAMEWORK_EFI_HII_HANDLE FrameworkHiiHandle;\r
160 EFI_STATUS Status;\r
161\r
162\r
163 VA_START (Args, HiiHandle);\r
164 FrameworkHiiPacages = InternalPreparePackages (NumberOfPackages, GuidId, Args);\r
165\r
166 Status = mHii->NewPack (mHii, FrameworkHiiPacages, &FrameworkHiiHandle);\r
167 if (HiiHandle != NULL) {\r
168 if (EFI_ERROR (Status)) {\r
169 *HiiHandle = NULL;\r
170 } else {\r
171 *HiiHandle = (EFI_HII_HANDLE) (UINTN) FrameworkHiiHandle;\r
172 }\r
0a869bf8 173 }\r
174\r
dc7b4a5c 175 FreePool (FrameworkHiiPacages);\r
176 \r
177 return Status;\r
178}\r
0a869bf8 179\r
bb557845 180/**\r
181 Removes a package list from the default HII database.\r
182\r
183 If HiiHandle is NULL, then ASSERT.\r
184 If HiiHandle is not a valid EFI_HII_HANDLE in the default HII database, then ASSERT.\r
185\r
a387653d 186 @param HiiHandle The handle that was previously registered to the data base that is requested for removal.\r
187 List later.\r
bb557845 188\r
189 @return VOID\r
bb557845 190**/\r
568f78ab 191VOID\r
dc7b4a5c 192EFIAPI\r
568f78ab 193HiiLibRemovePackages (\r
a387653d 194 IN EFI_HII_HANDLE HiiHandle\r
dc7b4a5c 195 )\r
196{\r
568f78ab 197 EFI_STATUS Status;\r
198 \r
199 Status = mHii->RemovePack (mHii, (FRAMEWORK_EFI_HII_HANDLE) (UINTN) HiiHandle);\r
200 ASSERT_EFI_ERROR (Status);\r
dc7b4a5c 201}\r
202\r
203\r
204/**\r
205 This function adds the string into String Package of each language.\r
206\r
207 @param PackageList Handle of the package list where this string will\r
208 be added.\r
209 @param StringId On return, contains the new strings id, which is\r
210 unique within PackageList.\r
211 @param String Points to the new null-terminated string.\r
212\r
213 @retval EFI_SUCCESS The new string was added successfully.\r
214 @retval EFI_NOT_FOUND The specified PackageList could not be found in\r
215 database.\r
216 @retval EFI_OUT_OF_RESOURCES Could not add the string due to lack of resources.\r
217 @retval EFI_INVALID_PARAMETER String is NULL or StringId is NULL is NULL.\r
218\r
219**/\r
220EFI_STATUS\r
221EFIAPI\r
568f78ab 222HiiLibNewString (\r
a387653d 223 IN EFI_HII_HANDLE PackageList,\r
224 OUT EFI_STRING_ID *StringId,\r
225 IN CONST EFI_STRING String\r
dc7b4a5c 226 )\r
227{\r
228 FRAMEWORK_EFI_HII_HANDLE FrameworkHiiHandle;\r
229 EFI_STATUS Status;\r
230\r
231 FrameworkHiiHandle = (FRAMEWORK_EFI_HII_HANDLE) (UINTN) PackageList;\r
232 Status = mHii->NewString (\r
233 mHii,\r
234 NULL,\r
235 FrameworkHiiHandle,\r
236 StringId,\r
237 String\r
238 );\r
239\r
240 return Status;\r
241}\r
242\r
bb557845 243/**\r
244 Get the string given the StringId and String package Producer's Guid. The caller\r
245 is responsible to free the *String.\r
dc7b4a5c 246\r
bb557845 247 If PackageList with the matching ProducerGuid is not found, then ASSERT.\r
248 If PackageList with the matching ProducerGuid is found but no String is\r
249 specified by StringId is found, then ASSERT.\r
dc7b4a5c 250\r
bb557845 251 @param ProducerGuid The Guid of String package list.\r
252 @param StringId The String ID.\r
253 @param String The output string.\r
dc7b4a5c 254\r
bb557845 255 @retval EFI_SUCCESS Operation is successful.\r
256 @retval EFI_OUT_OF_RESOURCES There is not enought memory in the system.\r
dc7b4a5c 257\r
bb557845 258**/\r
dc7b4a5c 259EFI_STATUS\r
260EFIAPI\r
568f78ab 261HiiLibGetStringFromToken (\r
a387653d 262 IN EFI_GUID *ProducerGuid,\r
263 IN EFI_STRING_ID StringId,\r
264 OUT EFI_STRING *String\r
dc7b4a5c 265 )\r
266{\r
267 return EFI_SUCCESS; \r
268}\r
269\r
bb557845 270/**\r
271 Get string specified by StringId form the HiiHandle. The caller\r
272 is responsible to free the *String.\r
273\r
274 If String is NULL, then ASSERT.\r
275 If HiiHandle could not be found in the default HII database, then ASSERT.\r
276 If StringId is not found in PackageList, then ASSERT.\r
277\r
7459094d 278 @param PackageList The HII handle of package list.\r
bb557845 279 @param StringId The String ID.\r
280 @param String The output string.\r
281\r
282 @retval EFI_NOT_FOUND String is not found.\r
283 @retval EFI_SUCCESS Operation is successful.\r
284 @retval EFI_OUT_OF_RESOURCES There is not enought memory in the system.\r
bb557845 285\r
286**/\r
dc7b4a5c 287EFI_STATUS\r
288EFIAPI\r
289HiiLibGetStringFromHandle (\r
a387653d 290 IN EFI_HII_HANDLE PackageList,\r
291 IN EFI_STRING_ID StringId,\r
292 OUT EFI_STRING *String\r
dc7b4a5c 293 )\r
294{\r
295 return EFI_SUCCESS;\r
296}\r
297\r
bb557845 298/**\r
299 Create the driver handle for HII driver. The protocol and \r
300 Package list of this driver wili be installed into this \r
301 driver handle. \r
302 The implement set DriverHandle to NULL simpliy to let \r
303 handle manager create a default new handle.\r
304 \r
305 @param[out] DriverHandle the pointer of driver handle\r
306 @return always successful.\r
307**/\r
dc7b4a5c 308EFI_STATUS\r
309EFIAPI\r
310HiiLibCreateHiiDriverHandle (\r
a387653d 311 OUT EFI_HANDLE *DriverHandle\r
dc7b4a5c 312 )\r
313{\r
314 //\r
315 // Driver\r
316 // This implementation does nothing as DriverHandle concept only\r
317 // applies to UEFI HII specification.\r
318 //\r
319 \r
320 *DriverHandle = NULL;\r
321 \r
322 return EFI_SUCCESS;\r
323}\r
324\r