]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/DynamicCommand/DpDynamicCommand/DpDynamicCommand.c
ShellPkg/dp: Convert from NULL class library to Dynamic Command
[mirror_edk2.git] / ShellPkg / DynamicCommand / DpDynamicCommand / DpDynamicCommand.c
1 /** @file
2 Produce "dp" shell dynamic command.
3
4 Copyright (c) 2017, Intel Corporation. All rights reserved. <BR>
5
6 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 #include "Dp.h"
16 #include <Protocol/ShellDynamicCommand.h>
17
18 /**
19 This is the shell command handler function pointer callback type. This
20 function handles the command when it is invoked in the shell.
21
22 @param[in] This The instance of the EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL.
23 @param[in] SystemTable The pointer to the system table.
24 @param[in] ShellParameters The parameters associated with the command.
25 @param[in] Shell The instance of the shell protocol used in the context
26 of processing this command.
27
28 @return EFI_SUCCESS the operation was sucessful
29 @return other the operation failed.
30 **/
31 SHELL_STATUS
32 EFIAPI
33 DpCommandHandler (
34 IN EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL *This,
35 IN EFI_SYSTEM_TABLE *SystemTable,
36 IN EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters,
37 IN EFI_SHELL_PROTOCOL *Shell
38 )
39 {
40 gEfiShellParametersProtocol = ShellParameters;
41 return RunDp (gImageHandle, SystemTable);
42 }
43
44 /**
45 This is the command help handler function pointer callback type. This
46 function is responsible for displaying help information for the associated
47 command.
48
49 @param[in] This The instance of the EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL.
50 @param[in] Language The pointer to the language string to use.
51
52 @return string Pool allocated help string, must be freed by caller
53 **/
54 CHAR16 *
55 EFIAPI
56 DpCommandGetHelp (
57 IN EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL *This,
58 IN CONST CHAR8 *Language
59 )
60 {
61 return HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_GET_HELP_DP), Language);
62 }
63
64 EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL mDpDynamicCommand = {
65 L"dp",
66 DpCommandHandler,
67 DpCommandGetHelp
68 };
69
70 /**
71 Entry point of Tftp Dynamic Command.
72
73 Produce the DynamicCommand protocol to handle "tftp" command.
74
75 @param ImageHandle The image handle of the process.
76 @param SystemTable The EFI System Table pointer.
77
78 @retval EFI_SUCCESS Tftp command is executed sucessfully.
79 @retval EFI_ABORTED HII package was failed to initialize.
80 @retval others Other errors when executing tftp command.
81 **/
82 EFI_STATUS
83 EFIAPI
84 DpCommandInitialize (
85 IN EFI_HANDLE ImageHandle,
86 IN EFI_SYSTEM_TABLE *SystemTable
87 )
88 {
89 EFI_STATUS Status;
90 mDpHiiHandle = InitializeHiiPackage (ImageHandle);
91 if (mDpHiiHandle == NULL) {
92 return EFI_ABORTED;
93 }
94
95 Status = gBS->InstallProtocolInterface (
96 &ImageHandle,
97 &gEfiShellDynamicCommandProtocolGuid,
98 EFI_NATIVE_INTERFACE,
99 &mDpDynamicCommand
100 );
101 ASSERT_EFI_ERROR (Status);
102 return Status;
103 }
104
105 /**
106 Tftp driver unload handler.
107
108 @param ImageHandle The image handle of the process.
109
110 @retval EFI_SUCCESS The image is unloaded.
111 @retval Others Failed to unload the image.
112 **/
113 EFI_STATUS
114 EFIAPI
115 DpUnload (
116 IN EFI_HANDLE ImageHandle
117 )
118 {
119 EFI_STATUS Status;
120 Status = gBS->UninstallProtocolInterface (
121 ImageHandle,
122 &gEfiShellDynamicCommandProtocolGuid,
123 &mDpDynamicCommand
124 );
125 if (EFI_ERROR (Status)) {
126 return Status;
127 }
128 HiiRemovePackages (mDpHiiHandle);
129 return EFI_SUCCESS;
130 }