2 Function definitions for shell simple text in and out on top of file handles.
4 Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include <ShellBase.h>
18 #include "ConsoleWrappers.h"
22 EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleTextIn
;
23 SHELL_FILE_HANDLE FileHandle
;
25 } SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
;
28 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL SimpleTextOut
;
29 SHELL_FILE_HANDLE FileHandle
;
31 } SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
;
34 Event notification function for EFI_SIMPLE_TEXT_INPUT_PROTOCOL.WaitForKey event
35 Signal the event if there is key available
37 @param Event Indicates the event that invoke this function.
38 @param Context Indicates the calling context.
51 // Someone is waiting on the keystroke event, if there's
52 // a key pending, signal the event
54 // Context is the pointer to EFI_SIMPLE_TEXT_INPUT_PROTOCOL
56 ShellInfoObject
.NewEfiShellProtocol
->GetFilePosition(((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)Context
)->FileHandle
, &Position
);
57 ShellInfoObject
.NewEfiShellProtocol
->GetFileSize (((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)Context
)->FileHandle
, &Size
);
58 if (Position
< Size
) {
59 gBS
->SignalEvent (Event
);
64 Reset function for the fake simple text input.
66 @param[in] This A pointer to the SimpleTextIn structure.
67 @param[in] ExtendedVerification TRUE for extra validation, FALSE otherwise.
69 @retval EFI_SUCCESS The reset was successful.
73 FileBasedSimpleTextInReset(
74 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
75 IN BOOLEAN ExtendedVerification
82 ReadKeyStroke function for the fake simple text input.
84 @param[in] This A pointer to the SimpleTextIn structure.
85 @param[out] Key A pointer to the Key structure to fill.
87 @retval EFI_SUCCESS The read was successful.
91 FileBasedSimpleTextInReadKeyStroke(
92 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
97 Size
= sizeof(CHAR16
);
98 if (Key
== NULL
|| This
== NULL
) {
99 return (EFI_INVALID_PARAMETER
);
102 return (ShellInfoObject
.NewEfiShellProtocol
->ReadFile(
103 ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)This
)->FileHandle
,
109 Function to create a EFI_SIMPLE_TEXT_INPUT_PROTOCOL on top of a
110 SHELL_FILE_HANDLE to support redirecting input from a file.
112 @param[in] FileHandleToUse The pointer to the SHELL_FILE_HANDLE to use.
113 @param[in] HandleLocation The pointer of a location to copy handle with protocol to.
115 @retval NULL There was insufficient memory available.
116 @return A pointer to the allocated protocol structure;
118 EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*
120 CreateSimpleTextInOnFile(
121 IN SHELL_FILE_HANDLE FileHandleToUse
,
122 IN EFI_HANDLE
*HandleLocation
125 SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*ProtocolToReturn
;
128 if (HandleLocation
== NULL
|| FileHandleToUse
== NULL
) {
132 ProtocolToReturn
= AllocateZeroPool(sizeof(SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
));
133 if (ProtocolToReturn
== NULL
) {
136 ProtocolToReturn
->FileHandle
= FileHandleToUse
;
137 ProtocolToReturn
->SimpleTextIn
.Reset
= FileBasedSimpleTextInReset
;
138 ProtocolToReturn
->SimpleTextIn
.ReadKeyStroke
= FileBasedSimpleTextInReadKeyStroke
;
140 Status
= gBS
->CreateEvent (
144 &ProtocolToReturn
->SimpleTextIn
,
145 &ProtocolToReturn
->SimpleTextIn
.WaitForKey
148 if (EFI_ERROR(Status
)) {
149 FreePool(ProtocolToReturn
);
152 ///@todo possibly also install SimpleTextInputEx on the handle at this point.
153 Status
= gBS
->InstallProtocolInterface(
154 &(ProtocolToReturn
->TheHandle
),
155 &gEfiSimpleTextInProtocolGuid
,
156 EFI_NATIVE_INTERFACE
,
157 &(ProtocolToReturn
->SimpleTextIn
));
158 if (!EFI_ERROR(Status
)) {
159 *HandleLocation
= ProtocolToReturn
->TheHandle
;
160 return ((EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)ProtocolToReturn
);
162 FreePool(ProtocolToReturn
);
168 Function to close a EFI_SIMPLE_TEXT_INPUT_PROTOCOL on top of a
169 SHELL_FILE_HANDLE to support redirecting input from a file.
171 @param[in] SimpleTextIn The pointer to the SimpleTextIn to close.
173 @retval EFI_SUCCESS The object was closed.
177 CloseSimpleTextInOnFile(
178 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*SimpleTextIn
184 if (SimpleTextIn
== NULL
) {
185 return (EFI_INVALID_PARAMETER
);
188 Status
= gBS
->CloseEvent(((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)SimpleTextIn
)->SimpleTextIn
.WaitForKey
);
190 Status1
= gBS
->UninstallProtocolInterface(
191 ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)SimpleTextIn
)->TheHandle
,
192 &gEfiSimpleTextInProtocolGuid
,
193 &(((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)SimpleTextIn
)->SimpleTextIn
));
195 FreePool(SimpleTextIn
);
196 if (!EFI_ERROR(Status
)) {
204 Reset the text output device hardware and optionaly run diagnostics.
206 @param This pointer to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
207 @param ExtendedVerification Indicates that a more extensive test may be performed
209 @retval EFI_SUCCESS The text output device was reset.
213 FileBasedSimpleTextOutReset (
214 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
215 IN BOOLEAN ExtendedVerification
218 return (EFI_SUCCESS
);
222 Verifies that all characters in a Unicode string can be output to the
225 @param[in] This Protocol instance pointer.
226 @param[in] WString The NULL-terminated Unicode string to be examined.
228 @retval EFI_SUCCESS The device(s) are capable of rendering the output string.
232 FileBasedSimpleTextOutTestString (
233 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
237 return (EFI_SUCCESS
);
241 Returns information for an available text mode that the output device(s)
244 @param[in] This Protocol instance pointer.
245 @param[in] ModeNumber The mode number to return information on.
246 @param[out] Columns Upon return, the number of columns in the selected geometry
247 @param[out] Rows Upon return, the number of rows in the selected geometry
249 @retval EFI_UNSUPPORTED The mode number was not valid.
253 FileBasedSimpleTextOutQueryMode (
254 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
260 return (EFI_UNSUPPORTED
);
264 Sets the output device(s) to a specified mode.
266 @param[in] This Protocol instance pointer.
267 @param[in] ModeNumber The mode number to set.
269 @retval EFI_UNSUPPORTED The mode number was not valid.
273 FileBasedSimpleTextOutSetMode (
274 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
278 return (EFI_UNSUPPORTED
);
282 Sets the background and foreground colors for the OutputString () and
283 ClearScreen () functions.
285 @param[in] This Protocol instance pointer.
286 @param[in] Attribute The attribute to set. Bits 0..3 are the foreground color, and
287 bits 4..6 are the background color. All other bits are undefined
288 and must be zero. The valid Attributes are defined in this file.
290 @retval EFI_SUCCESS The attribute was set.
294 FileBasedSimpleTextOutSetAttribute (
295 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
299 return (EFI_SUCCESS
);
303 Clears the output device(s) display to the currently selected background
306 @param[in] This Protocol instance pointer.
308 @retval EFI_UNSUPPORTED The output device is not in a valid text mode.
312 FileBasedSimpleTextOutClearScreen (
313 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
316 return (EFI_SUCCESS
);
320 Sets the current coordinates of the cursor position
322 @param[in] This Protocol instance pointer.
323 @param[in] Column Column to put the cursor in. Must be between zero and Column returned from QueryMode
324 @param[in] Row Row to put the cursor in. Must be between zero and Row returned from QueryMode
326 @retval EFI_SUCCESS The operation completed successfully.
330 FileBasedSimpleTextOutSetCursorPosition (
331 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
336 return (EFI_SUCCESS
);
340 Makes the cursor visible or invisible
342 @param[in] This Protocol instance pointer.
343 @param[in] Visible If TRUE, the cursor is set to be visible. If FALSE, the cursor is
346 @retval EFI_SUCCESS The operation completed successfully.
350 FileBasedSimpleTextOutEnableCursor (
351 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
355 return (EFI_SUCCESS
);
359 Write a Unicode string to the output device.
361 @param[in] This Protocol instance pointer.
362 @param[in] WString The NULL-terminated Unicode string to be displayed on the output
363 device(s). All output devices must also support the Unicode
364 drawing defined in this file.
365 @retval EFI_SUCCESS The string was output to the device.
366 @retval EFI_DEVICE_ERROR The device reported an error while attempting to output
368 @retval EFI_UNSUPPORTED The output device's mode is not currently in a
370 @retval EFI_WARN_UNKNOWN_GLYPH This warning code indicates that some of the
371 characters in the Unicode string could not be
372 rendered and were skipped.
376 FileBasedSimpleTextOutOutputString (
377 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
382 Size
= StrLen(WString
) * sizeof(CHAR16
);
383 return (ShellInfoObject
.NewEfiShellProtocol
->WriteFile(
384 ((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*)This
)->FileHandle
,
390 Function to create a EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL on top of a
391 SHELL_FILE_HANDLE to support redirecting output from a file.
393 @param[in] FileHandleToUse The pointer to the SHELL_FILE_HANDLE to use.
394 @param[in] HandleLocation The pointer of a location to copy handle with protocol to.
396 @retval NULL There was insufficient memory available.
397 @return A pointer to the allocated protocol structure;
399 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*
401 CreateSimpleTextOutOnFile(
402 IN SHELL_FILE_HANDLE FileHandleToUse
,
403 IN EFI_HANDLE
*HandleLocation
406 SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*ProtocolToReturn
;
409 if (HandleLocation
== NULL
|| FileHandleToUse
== NULL
) {
413 ProtocolToReturn
= AllocateZeroPool(sizeof(SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
));
414 if (ProtocolToReturn
== NULL
) {
417 ProtocolToReturn
->FileHandle
= FileHandleToUse
;
418 ProtocolToReturn
->SimpleTextOut
.Reset
= FileBasedSimpleTextOutReset
;
419 ProtocolToReturn
->SimpleTextOut
.TestString
= FileBasedSimpleTextOutTestString
;
420 ProtocolToReturn
->SimpleTextOut
.QueryMode
= FileBasedSimpleTextOutQueryMode
;
421 ProtocolToReturn
->SimpleTextOut
.SetMode
= FileBasedSimpleTextOutSetMode
;
422 ProtocolToReturn
->SimpleTextOut
.SetAttribute
= FileBasedSimpleTextOutSetAttribute
;
423 ProtocolToReturn
->SimpleTextOut
.ClearScreen
= FileBasedSimpleTextOutClearScreen
;
424 ProtocolToReturn
->SimpleTextOut
.SetCursorPosition
= FileBasedSimpleTextOutSetCursorPosition
;
425 ProtocolToReturn
->SimpleTextOut
.EnableCursor
= FileBasedSimpleTextOutEnableCursor
;
426 ProtocolToReturn
->SimpleTextOut
.OutputString
= FileBasedSimpleTextOutOutputString
;
427 ProtocolToReturn
->SimpleTextOut
.Mode
= AllocateZeroPool(sizeof(EFI_SIMPLE_TEXT_OUTPUT_MODE
));
428 if (ProtocolToReturn
->SimpleTextOut
.Mode
== NULL
) {
429 FreePool(ProtocolToReturn
);
432 ProtocolToReturn
->SimpleTextOut
.Mode
->MaxMode
= 0;
433 ProtocolToReturn
->SimpleTextOut
.Mode
->Mode
= 0;
434 ProtocolToReturn
->SimpleTextOut
.Mode
->Attribute
= 0;
435 ProtocolToReturn
->SimpleTextOut
.Mode
->CursorColumn
= 0;
436 ProtocolToReturn
->SimpleTextOut
.Mode
->CursorRow
= 0;
437 ProtocolToReturn
->SimpleTextOut
.Mode
->CursorVisible
= FALSE
;
439 Status
= gBS
->InstallProtocolInterface(
440 &(ProtocolToReturn
->TheHandle
),
441 &gEfiSimpleTextOutProtocolGuid
,
442 EFI_NATIVE_INTERFACE
,
443 &(ProtocolToReturn
->SimpleTextOut
));
444 if (!EFI_ERROR(Status
)) {
445 *HandleLocation
= ProtocolToReturn
->TheHandle
;
446 return ((EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*)ProtocolToReturn
);
448 FreePool(ProtocolToReturn
);
454 Function to close a EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL on top of a
455 SHELL_FILE_HANDLE to support redirecting output from a file.
457 @param[in] SimpleTextOut The pointer to the SimpleTextOUT to close.
459 @retval EFI_SUCCESS The object was closed.
463 CloseSimpleTextOutOnFile(
464 OUT EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOut
468 if (SimpleTextOut
== NULL
) {
469 return (EFI_INVALID_PARAMETER
);
471 Status
= gBS
->UninstallProtocolInterface(
472 ((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*)SimpleTextOut
)->TheHandle
,
473 &gEfiSimpleTextOutProtocolGuid
,
474 &(((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*)SimpleTextOut
)->SimpleTextOut
));
475 FreePool(SimpleTextOut
);