ShellPkg/tftp: Convert from NULL class library to Dynamic Command
[mirror_edk2.git] / ShellPkg / DynamicCommand / TftpDynamicCommand / TftpDynamicCommand.c
1 /** @file
2 Produce "tftp" shell dynamic command.
3
4 Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved. <BR>
5 Copyright (c) 2015, ARM Ltd. All rights reserved.<BR>
6
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
11
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
15 **/
16 #include "Tftp.h"
17 #include <Protocol/ShellDynamicCommand.h>
18
19 /**
20 This is the shell command handler function pointer callback type. This
21 function handles the command when it is invoked in the shell.
22
23 @param[in] This The instance of the EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL.
24 @param[in] SystemTable The pointer to the system table.
25 @param[in] ShellParameters The parameters associated with the command.
26 @param[in] Shell The instance of the shell protocol used in the context
27 of processing this command.
28
29 @return EFI_SUCCESS the operation was sucessful
30 @return other the operation failed.
31 **/
32 SHELL_STATUS
33 EFIAPI
34 TftpCommandHandler (
35 IN EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL *This,
36 IN EFI_SYSTEM_TABLE *SystemTable,
37 IN EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters,
38 IN EFI_SHELL_PROTOCOL *Shell
39 )
40 {
41 gEfiShellParametersProtocol = ShellParameters;
42 return RunTftp (gImageHandle, SystemTable);
43 }
44
45 /**
46 This is the command help handler function pointer callback type. This
47 function is responsible for displaying help information for the associated
48 command.
49
50 @param[in] This The instance of the EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL.
51 @param[in] Language The pointer to the language string to use.
52
53 @return string Pool allocated help string, must be freed by caller
54 **/
55 CHAR16 *
56 EFIAPI
57 TftpCommandGetHelp (
58 IN EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL *This,
59 IN CONST CHAR8 *Language
60 )
61 {
62 return HiiGetString (mTftpHiiHandle, STRING_TOKEN (STR_GET_HELP_TFTP), Language);
63 }
64
65 EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL mTftpDynamicCommand = {
66 L"tftp",
67 TftpCommandHandler,
68 TftpCommandGetHelp
69 };
70
71 /**
72 Entry point of Tftp Dynamic Command.
73
74 Produce the DynamicCommand protocol to handle "tftp" command.
75
76 @param ImageHandle The image handle of the process.
77 @param SystemTable The EFI System Table pointer.
78
79 @retval EFI_SUCCESS Tftp command is executed sucessfully.
80 @retval EFI_ABORTED HII package was failed to initialize.
81 @retval others Other errors when executing tftp command.
82 **/
83 EFI_STATUS
84 EFIAPI
85 TftpCommandInitialize (
86 IN EFI_HANDLE ImageHandle,
87 IN EFI_SYSTEM_TABLE *SystemTable
88 )
89 {
90 EFI_STATUS Status;
91 mTftpHiiHandle = InitializeHiiPackage (ImageHandle);
92 if (mTftpHiiHandle == NULL) {
93 return EFI_ABORTED;
94 }
95
96 Status = gBS->InstallProtocolInterface (
97 &ImageHandle,
98 &gEfiShellDynamicCommandProtocolGuid,
99 EFI_NATIVE_INTERFACE,
100 &mTftpDynamicCommand
101 );
102 ASSERT_EFI_ERROR (Status);
103 return Status;
104 }
105
106 /**
107 Tftp driver unload handler.
108
109 @param ImageHandle The image handle of the process.
110
111 @retval EFI_SUCCESS The image is unloaded.
112 @retval Others Failed to unload the image.
113 **/
114 EFI_STATUS
115 EFIAPI
116 TftpUnload (
117 IN EFI_HANDLE ImageHandle
118 )
119 {
120 EFI_STATUS Status;
121 Status = gBS->UninstallProtocolInterface (
122 ImageHandle,
123 &gEfiShellDynamicCommandProtocolGuid,
124 &mTftpDynamicCommand
125 );
126 if (EFI_ERROR (Status)) {
127 return Status;
128 }
129 HiiRemovePackages (mTftpHiiHandle);
130 return EFI_SUCCESS;
131 }