]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkPkg/Library/FrameworkHiiLib/HiiLib.c
Fix typo in comment.
[mirror_edk2.git] / IntelFrameworkPkg / Library / FrameworkHiiLib / HiiLib.c
index 4315f38a32bdcfbec27eca55210e2d289919c65b..f2edf44317a837b985bdd18288c7c9cfb7d51719 100644 (file)
   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
-  Module Name:  HiiLib.c\r
-\r
 **/\r
 \r
-//\r
-// The package level header files this module uses\r
-//\r
-#include <PiDxe.h>\r
-//\r
-// The protocols, PPI and GUID defintions for this module\r
-//\r
-//\r
-// The Library classes this module consumes\r
-//\r
+\r
+#include <FrameworkDxe.h>\r
+\r
+#include <Protocol/FrameworkHii.h>\r
+\r
 #include <Library/FrameworkHiiLib.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+\r
+\r
+EFI_HII_PROTOCOL *mHii = NULL;\r
+\r
+/**\r
+  Library constustor function for HiiLib library instance locate the\r
+  gEfiHiiProtocolGuid firstly, the other interface in this library\r
+  instance will dependent on the protocol of gEfiHiiProtocolGuid.\r
+  So the depex of gEfiHiiProtocolGuid is required for this library \r
+  instance.\r
+  If protocol of gEfiHiiProtocolGuid is not installed, then ASSERT().\r
+  \r
+  @param ImageHandle  The image handle of driver module who use this library \r
+                      instance.\r
+  @param SystemTable  Pointer to the EFI System Table.\r
+  @retval EFI_SUCCESS library constuctor always success.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FrameworkHiiLibConstructor (\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+  \r
+  Status = gBS->LocateProtocol (\r
+      &gEfiHiiProtocolGuid,\r
+      NULL,\r
+      (VOID **) &mHii\r
+    );\r
+  ASSERT_EFI_ERROR (Status);\r
+  ASSERT (mHii != NULL);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  This function is internal function that prepare and create\r
+  HII packages with given number and package's guid.\r
+  It is invoked by HiiAddPackages() and PreparePackages() interface.\r
+  If the parameter of package's number is 0, then ASSERT().\r
+  \r
+  @param NumberOfPackages  Given number of package item in a HII package list.\r
+  @param Guid              Given GUID of a HII package list.\r
+  @param Marker            Package's content list.\r
+  \r
+  @return pointer to new created HII package list.\r
+**/\r
+EFI_HII_PACKAGES *\r
+InternalPreparePackages (\r
+  IN UINTN           NumberOfPackages,\r
+  IN CONST EFI_GUID  *Guid OPTIONAL,\r
+  VA_LIST            Marker\r
+  )\r
+{\r
+  EFI_HII_PACKAGES  *HiiPackages;\r
+  VOID              **Package;\r
+  UINTN             Index;\r
+\r
+  ASSERT (NumberOfPackages > 0);\r
+\r
+  HiiPackages                   = AllocateZeroPool (sizeof (EFI_HII_PACKAGES) + NumberOfPackages * sizeof (VOID *));\r
+  ASSERT (HiiPackages != NULL);\r
+\r
+  HiiPackages->GuidId           = (EFI_GUID *) Guid;\r
+  HiiPackages->NumberOfPackages = NumberOfPackages;\r
+  Package                       = (VOID **) (((UINT8 *) HiiPackages) + sizeof (EFI_HII_PACKAGES));\r
+\r
+  for (Index = 0; Index < NumberOfPackages; Index++) {\r
+    *Package = VA_ARG (Marker, VOID *);\r
+    Package++;\r
+  }\r
+\r
+  return HiiPackages;\r
+\r
+}\r
 \r
 /**\r
   This function allocates pool for an EFI_HII_PACKAGES structure\r
@@ -49,28 +121,210 @@ PreparePackages (
   )\r
 {\r
   VA_LIST           Args;\r
-  EFI_HII_PACKAGES  *HiiPackages;\r
-  VOID              **Package;\r
-  UINTN             Index;\r
 \r
-  ASSERT (NumberOfPackages > 0);\r
+  VA_START (Args, Guid);\r
 \r
-  HiiPackages                   = AllocateZeroPool (sizeof (EFI_HII_PACKAGES) + NumberOfPackages * sizeof (VOID *));\r
-  ASSERT (HiiPackages != NULL);\r
+  return InternalPreparePackages (NumberOfPackages, Guid, Args);\r
+}\r
 \r
-  HiiPackages->GuidId           = (EFI_GUID *) Guid;\r
-  HiiPackages->NumberOfPackages = NumberOfPackages;\r
-  Package                       = (VOID **) (((UINT8 *) HiiPackages) + sizeof (EFI_HII_PACKAGES));\r
 \r
-  VA_START (Args, Guid);\r
+/**\r
+  This function allocates pool for an EFI_HII_PACKAGE_LIST structure\r
+  with additional space that is big enough to host all packages described by the variable \r
+  argument list of package pointers.  The allocated structure is initialized using NumberOfPackages, \r
+  GuidId,  and the variable length argument list of package pointers.\r
 \r
-  for (Index = 0; Index < NumberOfPackages; Index++) {\r
-    *Package = VA_ARG (Args, VOID *);\r
-    Package++;\r
+  Then, EFI_HII_PACKAGE_LIST will be register to the default System HII Database. The\r
+  Handle to the newly registered Package List is returned throught HiiHandle.\r
+\r
+  @param  NumberOfPackages         The number of HII packages to register.\r
+  @param  GuidId                   Package List GUID ID.\r
+  @param  DriverHandle             The pointer of driver handle\r
+  @param  HiiHandle                The ID used to retrieve the Package List later.\r
+  @param  ...                      The variable argument list describing all HII Package.\r
+\r
+  @return\r
+  The allocated and initialized packages.\r
+\r
+**/\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+HiiLibAddPackages (\r
+  IN       UINTN               NumberOfPackages,\r
+  IN CONST EFI_GUID            *GuidId,\r
+  IN       EFI_HANDLE          DriverHandle, OPTIONAL\r
+  OUT      EFI_HII_HANDLE      *HiiHandle, OPTIONAL\r
+  ...\r
+  )\r
+{\r
+  VA_LIST                   Args;\r
+  EFI_HII_PACKAGES          *FrameworkHiiPacages;\r
+  FRAMEWORK_EFI_HII_HANDLE  FrameworkHiiHandle;\r
+  EFI_STATUS                Status;\r
+\r
+\r
+  VA_START (Args, HiiHandle);\r
+  FrameworkHiiPacages = InternalPreparePackages (NumberOfPackages, GuidId, Args);\r
+\r
+  Status      = mHii->NewPack (mHii, FrameworkHiiPacages, &FrameworkHiiHandle);\r
+  if (HiiHandle != NULL) {\r
+    if (EFI_ERROR (Status)) {\r
+      *HiiHandle = NULL;\r
+    } else {\r
+      *HiiHandle = (EFI_HII_HANDLE) (UINTN) FrameworkHiiHandle;\r
+    }\r
   }\r
 \r
-  VA_END (Args);\r
+  FreePool (FrameworkHiiPacages);\r
+  \r
+  return Status;\r
+}\r
 \r
-  return HiiPackages;\r
+/**\r
+  Removes a package list from the default HII database.\r
+\r
+  If HiiHandle is NULL, then ASSERT.\r
+  If HiiHandle is not a valid EFI_HII_HANDLE in the default HII database, then ASSERT.\r
+\r
+  @param  HiiHandle                The handle that was previously registered to the data base that is requested for removal.\r
+                                             List later.\r
+\r
+  @return  VOID\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+HiiLibRemovePackages (\r
+  IN      EFI_HII_HANDLE      HiiHandle\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+  \r
+  Status = mHii->RemovePack (mHii, (FRAMEWORK_EFI_HII_HANDLE) (UINTN) HiiHandle);\r
+  ASSERT_EFI_ERROR (Status);\r
+}\r
+\r
+\r
+/**\r
+  This function adds the string into String Package of each language.\r
+\r
+  @param  PackageList            Handle of the package list where this string will\r
+                                 be added.\r
+  @param  StringId               On return, contains the new strings id, which is\r
+                                 unique within PackageList.\r
+  @param  String                 Points to the new null-terminated string.\r
+\r
+  @retval EFI_SUCCESS            The new string was added successfully.\r
+  @retval EFI_NOT_FOUND          The specified PackageList could not be found in\r
+                                 database.\r
+  @retval EFI_OUT_OF_RESOURCES   Could not add the string due to lack of resources.\r
+  @retval EFI_INVALID_PARAMETER  String is NULL or StringId is NULL is NULL.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HiiLibNewString (\r
+  IN  EFI_HII_HANDLE                  PackageList,\r
+  OUT EFI_STRING_ID                   *StringId,\r
+  IN  CONST EFI_STRING                String\r
+  )\r
+{\r
+  FRAMEWORK_EFI_HII_HANDLE  FrameworkHiiHandle;\r
+  EFI_STATUS                Status;\r
+\r
+  FrameworkHiiHandle = (FRAMEWORK_EFI_HII_HANDLE) (UINTN) PackageList;\r
+  Status = mHii->NewString (\r
+            mHii,\r
+            NULL,\r
+            FrameworkHiiHandle,\r
+            StringId,\r
+            String\r
+          );\r
 \r
+  return Status;\r
 }\r
+\r
+/**\r
+  Get the string given the StringId and String package Producer's Guid. The caller\r
+  is responsible to free the *String.\r
+\r
+  If PackageList with the matching ProducerGuid is not found, then ASSERT.\r
+  If PackageList with the matching ProducerGuid is found but no String is\r
+  specified by StringId is found, then ASSERT.\r
+\r
+  @param  ProducerGuid           The Guid of String package list.\r
+  @param  StringId               The String ID.\r
+  @param  String                 The output string.\r
+\r
+  @retval EFI_SUCCESS            Operation is successful.\r
+  @retval EFI_OUT_OF_RESOURCES   There is not enought memory in the system.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HiiLibGetStringFromToken (\r
+  IN  EFI_GUID                        *ProducerGuid,\r
+  IN  EFI_STRING_ID                   StringId,\r
+  OUT EFI_STRING                      *String\r
+  )\r
+{\r
+  return EFI_SUCCESS;  \r
+}\r
+\r
+/**\r
+  Get string specified by StringId form the HiiHandle. The caller\r
+  is responsible to free the *String.\r
+\r
+  If String is NULL, then ASSERT.\r
+  If HiiHandle could not be found in the default HII database, then ASSERT.\r
+  If StringId is not found in PackageList, then ASSERT.\r
+\r
+  @param  PackageList            The HII handle of package list.\r
+  @param  StringId               The String ID.\r
+  @param  String                 The output string.\r
+\r
+  @retval EFI_NOT_FOUND          String is not found.\r
+  @retval EFI_SUCCESS            Operation is successful.\r
+  @retval EFI_OUT_OF_RESOURCES   There is not enought memory in the system.\r
+  @retval EFI_INVALID_PARAMETER  The String is NULL.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HiiLibGetStringFromHandle (\r
+  IN  EFI_HII_HANDLE                  PackageList,\r
+  IN  EFI_STRING_ID                   StringId,\r
+  OUT EFI_STRING                      *String\r
+  )\r
+{\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Create the driver handle for HII driver. The protocol and \r
+  Package list of this driver wili be installed into this \r
+  driver handle. \r
+  The implement set DriverHandle to NULL simpliy to let \r
+  handle manager create a default new handle.\r
+  \r
+  @param[out] DriverHandle the pointer of driver handle\r
+  @return always successful.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HiiLibCreateHiiDriverHandle (\r
+  OUT EFI_HANDLE               *DriverHandle\r
+  )\r
+{\r
+  //\r
+  // Driver\r
+  // This implementation does nothing as DriverHandle concept only\r
+  // applies to UEFI HII specification.\r
+  //\r
+  \r
+  *DriverHandle = NULL;\r
+  \r
+  return EFI_SUCCESS;\r
+}\r
+\r