2 Function definitions for shell simple text in and out on top of file handles.
4 Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
5 Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
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
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.
19 EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleTextIn
;
20 SHELL_FILE_HANDLE FileHandle
;
22 } SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
;
25 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL SimpleTextOut
;
26 SHELL_FILE_HANDLE FileHandle
;
28 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*OriginalSimpleTextOut
;
29 } SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
;
32 Event notification function for EFI_SIMPLE_TEXT_INPUT_PROTOCOL.WaitForKey event
33 Signal the event if there is key available
35 @param Event Indicates the event that invoke this function.
36 @param Context Indicates the calling context.
49 // Someone is waiting on the keystroke event, if there's
50 // a key pending, signal the event
52 // Context is the pointer to EFI_SIMPLE_TEXT_INPUT_PROTOCOL
54 ShellInfoObject
.NewEfiShellProtocol
->GetFilePosition(((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)Context
)->FileHandle
, &Position
);
55 ShellInfoObject
.NewEfiShellProtocol
->GetFileSize (((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)Context
)->FileHandle
, &Size
);
56 if (Position
< Size
) {
57 gBS
->SignalEvent (Event
);
62 Reset function for the fake simple text input.
64 @param[in] This A pointer to the SimpleTextIn structure.
65 @param[in] ExtendedVerification TRUE for extra validation, FALSE otherwise.
67 @retval EFI_SUCCESS The reset was successful.
71 FileBasedSimpleTextInReset(
72 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
73 IN BOOLEAN ExtendedVerification
80 ReadKeyStroke function for the fake simple text input.
82 @param[in] This A pointer to the SimpleTextIn structure.
83 @param[in, out] Key A pointer to the Key structure to fill.
85 @retval EFI_SUCCESS The read was successful.
89 FileBasedSimpleTextInReadKeyStroke(
90 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
91 IN OUT EFI_INPUT_KEY
*Key
95 Size
= sizeof(CHAR16
);
96 if (Key
== NULL
|| This
== NULL
) {
97 return (EFI_INVALID_PARAMETER
);
100 return (ShellInfoObject
.NewEfiShellProtocol
->ReadFile(
101 ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)This
)->FileHandle
,
107 Function to create a EFI_SIMPLE_TEXT_INPUT_PROTOCOL on top of a
108 SHELL_FILE_HANDLE to support redirecting input from a file.
110 @param[in] FileHandleToUse The pointer to the SHELL_FILE_HANDLE to use.
111 @param[in] HandleLocation The pointer of a location to copy handle with protocol to.
113 @retval NULL There was insufficient memory available.
114 @return A pointer to the allocated protocol structure;
116 EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*
118 CreateSimpleTextInOnFile(
119 IN SHELL_FILE_HANDLE FileHandleToUse
,
120 IN EFI_HANDLE
*HandleLocation
123 SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*ProtocolToReturn
;
126 if (HandleLocation
== NULL
|| FileHandleToUse
== NULL
) {
130 ProtocolToReturn
= AllocateZeroPool(sizeof(SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
));
131 if (ProtocolToReturn
== NULL
) {
134 ProtocolToReturn
->FileHandle
= FileHandleToUse
;
135 ProtocolToReturn
->SimpleTextIn
.Reset
= FileBasedSimpleTextInReset
;
136 ProtocolToReturn
->SimpleTextIn
.ReadKeyStroke
= FileBasedSimpleTextInReadKeyStroke
;
138 Status
= gBS
->CreateEvent (
142 &ProtocolToReturn
->SimpleTextIn
,
143 &ProtocolToReturn
->SimpleTextIn
.WaitForKey
146 if (EFI_ERROR(Status
)) {
147 FreePool(ProtocolToReturn
);
150 ///@todo possibly also install SimpleTextInputEx on the handle at this point.
151 Status
= gBS
->InstallProtocolInterface(
152 &(ProtocolToReturn
->TheHandle
),
153 &gEfiSimpleTextInProtocolGuid
,
154 EFI_NATIVE_INTERFACE
,
155 &(ProtocolToReturn
->SimpleTextIn
));
156 if (!EFI_ERROR(Status
)) {
157 *HandleLocation
= ProtocolToReturn
->TheHandle
;
158 return ((EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)ProtocolToReturn
);
160 FreePool(ProtocolToReturn
);
166 Function to close a EFI_SIMPLE_TEXT_INPUT_PROTOCOL on top of a
167 SHELL_FILE_HANDLE to support redirecting input from a file.
169 @param[in] SimpleTextIn The pointer to the SimpleTextIn to close.
171 @retval EFI_SUCCESS The object was closed.
175 CloseSimpleTextInOnFile(
176 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*SimpleTextIn
182 if (SimpleTextIn
== NULL
) {
183 return (EFI_INVALID_PARAMETER
);
186 Status
= gBS
->CloseEvent(((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)SimpleTextIn
)->SimpleTextIn
.WaitForKey
);
188 Status1
= gBS
->UninstallProtocolInterface(
189 ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)SimpleTextIn
)->TheHandle
,
190 &gEfiSimpleTextInProtocolGuid
,
191 &(((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)SimpleTextIn
)->SimpleTextIn
));
193 FreePool(SimpleTextIn
);
194 if (!EFI_ERROR(Status
)) {
202 Reset the text output device hardware and optionaly run diagnostics.
204 @param This pointer to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
205 @param ExtendedVerification Indicates that a more extensive test may be performed
207 @retval EFI_SUCCESS The text output device was reset.
211 FileBasedSimpleTextOutReset (
212 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
213 IN BOOLEAN ExtendedVerification
216 return (EFI_SUCCESS
);
220 Verifies that all characters in a Unicode string can be output to the
223 @param[in] This Protocol instance pointer.
224 @param[in] WString The NULL-terminated Unicode string to be examined.
226 @retval EFI_SUCCESS The device(s) are capable of rendering the output string.
230 FileBasedSimpleTextOutTestString (
231 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
235 return (EFI_SUCCESS
);
239 Returns information for an available text mode that the output device(s)
242 @param[in] This Protocol instance pointer.
243 @param[in] ModeNumber The mode number to return information on.
244 @param[out] Columns Upon return, the number of columns in the selected geometry
245 @param[out] Rows Upon return, the number of rows in the selected geometry
247 @retval EFI_UNSUPPORTED The mode number was not valid.
251 FileBasedSimpleTextOutQueryMode (
252 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
258 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*PassThruProtocol
;
260 PassThruProtocol
= ((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*)This
)->OriginalSimpleTextOut
;
262 // Pass the QueryMode call thru to the original SimpleTextOutProtocol
263 return (PassThruProtocol
->QueryMode(
271 Sets the output device(s) to a specified mode.
273 @param[in] This Protocol instance pointer.
274 @param[in] ModeNumber The mode number to set.
276 @retval EFI_UNSUPPORTED The mode number was not valid.
280 FileBasedSimpleTextOutSetMode (
281 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
285 return (EFI_UNSUPPORTED
);
289 Sets the background and foreground colors for the OutputString () and
290 ClearScreen () functions.
292 @param[in] This Protocol instance pointer.
293 @param[in] Attribute The attribute to set. Bits 0..3 are the foreground color, and
294 bits 4..6 are the background color. All other bits are undefined
295 and must be zero. The valid Attributes are defined in this file.
297 @retval EFI_SUCCESS The attribute was set.
301 FileBasedSimpleTextOutSetAttribute (
302 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
306 return (EFI_SUCCESS
);
310 Clears the output device(s) display to the currently selected background
313 @param[in] This Protocol instance pointer.
315 @retval EFI_UNSUPPORTED The output device is not in a valid text mode.
319 FileBasedSimpleTextOutClearScreen (
320 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
323 return (EFI_SUCCESS
);
327 Sets the current coordinates of the cursor position
329 @param[in] This Protocol instance pointer.
330 @param[in] Column Column to put the cursor in. Must be between zero and Column returned from QueryMode
331 @param[in] Row Row to put the cursor in. Must be between zero and Row returned from QueryMode
333 @retval EFI_SUCCESS The operation completed successfully.
337 FileBasedSimpleTextOutSetCursorPosition (
338 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
343 return (EFI_SUCCESS
);
347 Makes the cursor visible or invisible
349 @param[in] This Protocol instance pointer.
350 @param[in] Visible If TRUE, the cursor is set to be visible. If FALSE, the cursor is
353 @retval EFI_SUCCESS The operation completed successfully.
357 FileBasedSimpleTextOutEnableCursor (
358 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
362 return (EFI_SUCCESS
);
366 Write a Unicode string to the output device.
368 @param[in] This Protocol instance pointer.
369 @param[in] WString The NULL-terminated Unicode string to be displayed on the output
370 device(s). All output devices must also support the Unicode
371 drawing defined in this file.
372 @retval EFI_SUCCESS The string was output to the device.
373 @retval EFI_DEVICE_ERROR The device reported an error while attempting to output
375 @retval EFI_UNSUPPORTED The output device's mode is not currently in a
377 @retval EFI_WARN_UNKNOWN_GLYPH This warning code indicates that some of the
378 characters in the Unicode string could not be
379 rendered and were skipped.
383 FileBasedSimpleTextOutOutputString (
384 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
389 Size
= StrLen(WString
) * sizeof(CHAR16
);
390 return (ShellInfoObject
.NewEfiShellProtocol
->WriteFile(
391 ((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*)This
)->FileHandle
,
397 Function to create a EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL on top of a
398 SHELL_FILE_HANDLE to support redirecting output from a file.
400 @param[in] FileHandleToUse The pointer to the SHELL_FILE_HANDLE to use.
401 @param[in] HandleLocation The pointer of a location to copy handle with protocol to.
402 @param[in] OriginalProtocol The pointer to the original output protocol for pass thru of functions.
404 @retval NULL There was insufficient memory available.
405 @return A pointer to the allocated protocol structure;
407 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*
409 CreateSimpleTextOutOnFile(
410 IN SHELL_FILE_HANDLE FileHandleToUse
,
411 IN EFI_HANDLE
*HandleLocation
,
412 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*OriginalProtocol
415 SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*ProtocolToReturn
;
418 if (HandleLocation
== NULL
|| FileHandleToUse
== NULL
) {
422 ProtocolToReturn
= AllocateZeroPool(sizeof(SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
));
423 if (ProtocolToReturn
== NULL
) {
426 ProtocolToReturn
->FileHandle
= FileHandleToUse
;
427 ProtocolToReturn
->OriginalSimpleTextOut
= OriginalProtocol
;
428 ProtocolToReturn
->SimpleTextOut
.Reset
= FileBasedSimpleTextOutReset
;
429 ProtocolToReturn
->SimpleTextOut
.TestString
= FileBasedSimpleTextOutTestString
;
430 ProtocolToReturn
->SimpleTextOut
.QueryMode
= FileBasedSimpleTextOutQueryMode
;
431 ProtocolToReturn
->SimpleTextOut
.SetMode
= FileBasedSimpleTextOutSetMode
;
432 ProtocolToReturn
->SimpleTextOut
.SetAttribute
= FileBasedSimpleTextOutSetAttribute
;
433 ProtocolToReturn
->SimpleTextOut
.ClearScreen
= FileBasedSimpleTextOutClearScreen
;
434 ProtocolToReturn
->SimpleTextOut
.SetCursorPosition
= FileBasedSimpleTextOutSetCursorPosition
;
435 ProtocolToReturn
->SimpleTextOut
.EnableCursor
= FileBasedSimpleTextOutEnableCursor
;
436 ProtocolToReturn
->SimpleTextOut
.OutputString
= FileBasedSimpleTextOutOutputString
;
437 ProtocolToReturn
->SimpleTextOut
.Mode
= AllocateZeroPool(sizeof(EFI_SIMPLE_TEXT_OUTPUT_MODE
));
438 if (ProtocolToReturn
->SimpleTextOut
.Mode
== NULL
) {
439 FreePool(ProtocolToReturn
);
442 ProtocolToReturn
->SimpleTextOut
.Mode
->MaxMode
= OriginalProtocol
->Mode
->MaxMode
;
443 ProtocolToReturn
->SimpleTextOut
.Mode
->Mode
= OriginalProtocol
->Mode
->Mode
;
444 ProtocolToReturn
->SimpleTextOut
.Mode
->Attribute
= OriginalProtocol
->Mode
->Attribute
;
445 ProtocolToReturn
->SimpleTextOut
.Mode
->CursorColumn
= OriginalProtocol
->Mode
->CursorColumn
;
446 ProtocolToReturn
->SimpleTextOut
.Mode
->CursorRow
= OriginalProtocol
->Mode
->CursorRow
;
447 ProtocolToReturn
->SimpleTextOut
.Mode
->CursorVisible
= OriginalProtocol
->Mode
->CursorVisible
;
449 Status
= gBS
->InstallProtocolInterface(
450 &(ProtocolToReturn
->TheHandle
),
451 &gEfiSimpleTextOutProtocolGuid
,
452 EFI_NATIVE_INTERFACE
,
453 &(ProtocolToReturn
->SimpleTextOut
));
454 if (!EFI_ERROR(Status
)) {
455 *HandleLocation
= ProtocolToReturn
->TheHandle
;
456 return ((EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*)ProtocolToReturn
);
458 FreePool(ProtocolToReturn
);
464 Function to close a EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL on top of a
465 SHELL_FILE_HANDLE to support redirecting output from a file.
467 @param[in] SimpleTextOut The pointer to the SimpleTextOUT to close.
469 @retval EFI_SUCCESS The object was closed.
473 CloseSimpleTextOutOnFile(
474 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOut
478 if (SimpleTextOut
== NULL
) {
479 return (EFI_INVALID_PARAMETER
);
481 Status
= gBS
->UninstallProtocolInterface(
482 ((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*)SimpleTextOut
)->TheHandle
,
483 &gEfiSimpleTextOutProtocolGuid
,
484 &(((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*)SimpleTextOut
)->SimpleTextOut
));
485 FreePool(SimpleTextOut
);