Change name to remove Template
[mirror_edk2.git] / EmbeddedPkg / Library / EblAddExternalCommandLib / EblAddExternalCommandLib.c
1 /** @file
2 Add external EblCmd Lib
3
4 Copyright (c) 2007, Intel Corporation<BR>
5 Portions copyright (c) 2008-2009, Apple Inc. All rights reserved.
6
7 All rights reserved. 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 **/
17
18 #include <Uefi.h>
19 #include <Library/UefiLib.h>
20 #include <Library/UefiBootServicesTableLib.h>
21 #include <Library/EblAddExternalCommandLib.h>
22 #include <Protocol/EblAddCommand.h>
23
24 STATIC BOOLEAN gInstalledCommand = FALSE;
25 STATIC EFI_EVENT mEblCommandRegistration = NULL;
26
27 STATIC const EBL_COMMAND_TABLE *mAddExternalCmdLibTemplate = NULL;
28 STATIC UINTN mAddExternalCmdLibTemplateSize = 0;
29 EBL_ADD_COMMAND_PROTOCOL *gEblExternalCommand = NULL;
30
31
32 /**
33 Return a keypress or optionally timeout if a timeout value was passed in.
34 An optional callback funciton is called evey second when waiting for a
35 timeout.
36
37 @param Key EFI Key information returned
38 @param TimeoutInSec Number of seconds to wait to timeout
39 @param CallBack Callback called every second during the timeout wait
40
41 @return EFI_SUCCESS Key was returned
42 @return EFI_TIMEOUT If the TimoutInSec expired
43
44 **/
45 EFI_STATUS
46 EFIAPI
47 EblGetCharKey (
48 IN OUT EFI_INPUT_KEY *Key,
49 IN UINTN TimeoutInSec,
50 IN EBL_GET_CHAR_CALL_BACK CallBack OPTIONAL
51 )
52 {
53 if (gEblExternalCommand != NULL) {
54 return gEblExternalCommand->EblGetCharKey (Key, TimeoutInSec, CallBack);
55 }
56 return EFI_TIMEOUT;
57 }
58
59
60 /**
61 This routine is used prevent command output data from scrolling off the end
62 of the screen. The global gPageBreak is used to turn on or off this feature.
63 If the CurrentRow is near the end of the screen pause and print out a prompt
64 If the use hits Q to quit return TRUE else for any other key return FALSE.
65 PrefixNewline is used to figure out if a newline is needed before the prompt
66 string. This depends on the last print done before calling this function.
67 CurrentRow is updated by one on a call or set back to zero if a prompt is
68 needed.
69
70 @param CurrentRow Used to figure out if its the end of the page and updated
71 @param PrefixNewline Did previous print issue a newline
72
73 @return TRUE if Q was hit to quit, FALSE in all other cases.
74
75 **/
76 BOOLEAN
77 EFIAPI
78 EblAnyKeyToContinueQtoQuit (
79 IN UINTN *CurrentRow,
80 IN BOOLEAN PrefixNewline
81 )
82 {
83 if (gEblExternalCommand != NULL) {
84 return gEblExternalCommand->EblAnyKeyToContinueQtoQuit (CurrentRow, PrefixNewline);
85 }
86 return FALSE;
87 }
88
89
90
91 /**
92 Update mFvbEntry. Add new entry, or update existing entry if Fvb protocol is
93 reinstalled.
94
95 @param Event The Event that is being processed
96 @param Context Event Context
97
98 **/
99 VOID
100 EFIAPI
101 EblAddCommandNotificationEvent (
102 IN EFI_EVENT Event,
103 IN VOID *Context
104 )
105 {
106 EFI_STATUS Status;
107
108 if (!gInstalledCommand) {
109 Status = gBS->LocateProtocol (&gEfiEblAddCommandProtocolGuid, NULL, (VOID **)&gEblExternalCommand);
110 if (!EFI_ERROR (Status)) {
111 gEblExternalCommand->AddCommands (mAddExternalCmdLibTemplate, mAddExternalCmdLibTemplateSize);
112 gInstalledCommand = TRUE;
113 }
114 }
115 }
116
117
118
119 /**
120 The user Entry Point for the driver. The user code starts with this function
121 as the real entry point for the image goes into a library that calls this
122 function.
123
124 @param[in] ImageHandle The firmware allocated handle for the EFI image.
125 @param[in] SystemTable A pointer to the EFI System Table.
126
127 @retval EFI_SUCCESS The entry point is executed successfully.
128 @retval other Some error occurs when executing this entry point.
129
130 **/
131 EFI_STATUS
132 EFIAPI
133 EblAddExternalCommands (
134 IN const EBL_COMMAND_TABLE *EntryArray,
135 IN UINTN ArrayCount
136 )
137 {
138 if (mAddExternalCmdLibTemplate != NULL) {
139 return EFI_ALREADY_STARTED;
140 }
141
142 mAddExternalCmdLibTemplate = EntryArray;
143 mAddExternalCmdLibTemplateSize = ArrayCount;
144
145 EfiCreateProtocolNotifyEvent (
146 &gEfiEblAddCommandProtocolGuid,
147 TPL_CALLBACK,
148 EblAddCommandNotificationEvent,
149 NULL,
150 &mEblCommandRegistration
151 );
152
153 return EFI_SUCCESS;
154 }
155