2 Function definitions for shell simple text in and out on top of file handles.
4 Copyright (c) 2010 - 2011, 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.
18 EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleTextIn
;
19 SHELL_FILE_HANDLE FileHandle
;
21 } SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
;
24 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL SimpleTextOut
;
25 SHELL_FILE_HANDLE FileHandle
;
27 } SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
;
30 Event notification function for EFI_SIMPLE_TEXT_INPUT_PROTOCOL.WaitForKey event
31 Signal the event if there is key available
33 @param Event Indicates the event that invoke this function.
34 @param Context Indicates the calling context.
47 // Someone is waiting on the keystroke event, if there's
48 // a key pending, signal the event
50 // Context is the pointer to EFI_SIMPLE_TEXT_INPUT_PROTOCOL
52 ShellInfoObject
.NewEfiShellProtocol
->GetFilePosition(((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)Context
)->FileHandle
, &Position
);
53 ShellInfoObject
.NewEfiShellProtocol
->GetFileSize (((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)Context
)->FileHandle
, &Size
);
54 if (Position
< Size
) {
55 gBS
->SignalEvent (Event
);
60 Reset function for the fake simple text input.
62 @param[in] This A pointer to the SimpleTextIn structure.
63 @param[in] ExtendedVerification TRUE for extra validation, FALSE otherwise.
65 @retval EFI_SUCCESS The reset was successful.
69 FileBasedSimpleTextInReset(
70 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
71 IN BOOLEAN ExtendedVerification
78 ReadKeyStroke function for the fake simple text input.
80 @param[in] This A pointer to the SimpleTextIn structure.
81 @param[in, out] Key A pointer to the Key structure to fill.
83 @retval EFI_SUCCESS The read was successful.
87 FileBasedSimpleTextInReadKeyStroke(
88 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
89 IN OUT EFI_INPUT_KEY
*Key
93 Size
= sizeof(CHAR16
);
94 if (Key
== NULL
|| This
== NULL
) {
95 return (EFI_INVALID_PARAMETER
);
98 return (ShellInfoObject
.NewEfiShellProtocol
->ReadFile(
99 ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)This
)->FileHandle
,
105 Function to create a EFI_SIMPLE_TEXT_INPUT_PROTOCOL on top of a
106 SHELL_FILE_HANDLE to support redirecting input from a file.
108 @param[in] FileHandleToUse The pointer to the SHELL_FILE_HANDLE to use.
109 @param[in] HandleLocation The pointer of a location to copy handle with protocol to.
111 @retval NULL There was insufficient memory available.
112 @return A pointer to the allocated protocol structure;
114 EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*
116 CreateSimpleTextInOnFile(
117 IN SHELL_FILE_HANDLE FileHandleToUse
,
118 IN EFI_HANDLE
*HandleLocation
121 SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*ProtocolToReturn
;
124 if (HandleLocation
== NULL
|| FileHandleToUse
== NULL
) {
128 ProtocolToReturn
= AllocateZeroPool(sizeof(SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
));
129 if (ProtocolToReturn
== NULL
) {
132 ProtocolToReturn
->FileHandle
= FileHandleToUse
;
133 ProtocolToReturn
->SimpleTextIn
.Reset
= FileBasedSimpleTextInReset
;
134 ProtocolToReturn
->SimpleTextIn
.ReadKeyStroke
= FileBasedSimpleTextInReadKeyStroke
;
136 Status
= gBS
->CreateEvent (
140 &ProtocolToReturn
->SimpleTextIn
,
141 &ProtocolToReturn
->SimpleTextIn
.WaitForKey
144 if (EFI_ERROR(Status
)) {
145 FreePool(ProtocolToReturn
);
148 ///@todo possibly also install SimpleTextInputEx on the handle at this point.
149 Status
= gBS
->InstallProtocolInterface(
150 &(ProtocolToReturn
->TheHandle
),
151 &gEfiSimpleTextInProtocolGuid
,
152 EFI_NATIVE_INTERFACE
,
153 &(ProtocolToReturn
->SimpleTextIn
));
154 if (!EFI_ERROR(Status
)) {
155 *HandleLocation
= ProtocolToReturn
->TheHandle
;
156 return ((EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)ProtocolToReturn
);
158 FreePool(ProtocolToReturn
);
164 Function to close a EFI_SIMPLE_TEXT_INPUT_PROTOCOL on top of a
165 SHELL_FILE_HANDLE to support redirecting input from a file.
167 @param[in] SimpleTextIn The pointer to the SimpleTextIn to close.
169 @retval EFI_SUCCESS The object was closed.
173 CloseSimpleTextInOnFile(
174 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*SimpleTextIn
180 if (SimpleTextIn
== NULL
) {
181 return (EFI_INVALID_PARAMETER
);
184 Status
= gBS
->CloseEvent(((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)SimpleTextIn
)->SimpleTextIn
.WaitForKey
);
186 Status1
= gBS
->UninstallProtocolInterface(
187 ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)SimpleTextIn
)->TheHandle
,
188 &gEfiSimpleTextInProtocolGuid
,
189 &(((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)SimpleTextIn
)->SimpleTextIn
));
191 FreePool(SimpleTextIn
);
192 if (!EFI_ERROR(Status
)) {
200 Reset the text output device hardware and optionaly run diagnostics.
202 @param This pointer to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
203 @param ExtendedVerification Indicates that a more extensive test may be performed
205 @retval EFI_SUCCESS The text output device was reset.
209 FileBasedSimpleTextOutReset (
210 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
211 IN BOOLEAN ExtendedVerification
214 return (EFI_SUCCESS
);
218 Verifies that all characters in a Unicode string can be output to the
221 @param[in] This Protocol instance pointer.
222 @param[in] WString The NULL-terminated Unicode string to be examined.
224 @retval EFI_SUCCESS The device(s) are capable of rendering the output string.
228 FileBasedSimpleTextOutTestString (
229 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
233 return (EFI_SUCCESS
);
237 Returns information for an available text mode that the output device(s)
240 @param[in] This Protocol instance pointer.
241 @param[in] ModeNumber The mode number to return information on.
242 @param[out] Columns Upon return, the number of columns in the selected geometry
243 @param[out] Rows Upon return, the number of rows in the selected geometry
245 @retval EFI_UNSUPPORTED The mode number was not valid.
249 FileBasedSimpleTextOutQueryMode (
250 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
256 return (EFI_UNSUPPORTED
);
260 Sets the output device(s) to a specified mode.
262 @param[in] This Protocol instance pointer.
263 @param[in] ModeNumber The mode number to set.
265 @retval EFI_UNSUPPORTED The mode number was not valid.
269 FileBasedSimpleTextOutSetMode (
270 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
274 return (EFI_UNSUPPORTED
);
278 Sets the background and foreground colors for the OutputString () and
279 ClearScreen () functions.
281 @param[in] This Protocol instance pointer.
282 @param[in] Attribute The attribute to set. Bits 0..3 are the foreground color, and
283 bits 4..6 are the background color. All other bits are undefined
284 and must be zero. The valid Attributes are defined in this file.
286 @retval EFI_SUCCESS The attribute was set.
290 FileBasedSimpleTextOutSetAttribute (
291 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
295 return (EFI_SUCCESS
);
299 Clears the output device(s) display to the currently selected background
302 @param[in] This Protocol instance pointer.
304 @retval EFI_UNSUPPORTED The output device is not in a valid text mode.
308 FileBasedSimpleTextOutClearScreen (
309 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
312 return (EFI_SUCCESS
);
316 Sets the current coordinates of the cursor position
318 @param[in] This Protocol instance pointer.
319 @param[in] Column Column to put the cursor in. Must be between zero and Column returned from QueryMode
320 @param[in] Row Row to put the cursor in. Must be between zero and Row returned from QueryMode
322 @retval EFI_SUCCESS The operation completed successfully.
326 FileBasedSimpleTextOutSetCursorPosition (
327 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
332 return (EFI_SUCCESS
);
336 Makes the cursor visible or invisible
338 @param[in] This Protocol instance pointer.
339 @param[in] Visible If TRUE, the cursor is set to be visible. If FALSE, the cursor is
342 @retval EFI_SUCCESS The operation completed successfully.
346 FileBasedSimpleTextOutEnableCursor (
347 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
351 return (EFI_SUCCESS
);
355 Write a Unicode string to the output device.
357 @param[in] This Protocol instance pointer.
358 @param[in] WString The NULL-terminated Unicode string to be displayed on the output
359 device(s). All output devices must also support the Unicode
360 drawing defined in this file.
361 @retval EFI_SUCCESS The string was output to the device.
362 @retval EFI_DEVICE_ERROR The device reported an error while attempting to output
364 @retval EFI_UNSUPPORTED The output device's mode is not currently in a
366 @retval EFI_WARN_UNKNOWN_GLYPH This warning code indicates that some of the
367 characters in the Unicode string could not be
368 rendered and were skipped.
372 FileBasedSimpleTextOutOutputString (
373 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
378 Size
= StrLen(WString
) * sizeof(CHAR16
);
379 return (ShellInfoObject
.NewEfiShellProtocol
->WriteFile(
380 ((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*)This
)->FileHandle
,
386 Function to create a EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL on top of a
387 SHELL_FILE_HANDLE to support redirecting output from a file.
389 @param[in] FileHandleToUse The pointer to the SHELL_FILE_HANDLE to use.
390 @param[in] HandleLocation The pointer of a location to copy handle with protocol to.
392 @retval NULL There was insufficient memory available.
393 @return A pointer to the allocated protocol structure;
395 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*
397 CreateSimpleTextOutOnFile(
398 IN SHELL_FILE_HANDLE FileHandleToUse
,
399 IN EFI_HANDLE
*HandleLocation
402 SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*ProtocolToReturn
;
405 if (HandleLocation
== NULL
|| FileHandleToUse
== NULL
) {
409 ProtocolToReturn
= AllocateZeroPool(sizeof(SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
));
410 if (ProtocolToReturn
== NULL
) {
413 ProtocolToReturn
->FileHandle
= FileHandleToUse
;
414 ProtocolToReturn
->SimpleTextOut
.Reset
= FileBasedSimpleTextOutReset
;
415 ProtocolToReturn
->SimpleTextOut
.TestString
= FileBasedSimpleTextOutTestString
;
416 ProtocolToReturn
->SimpleTextOut
.QueryMode
= FileBasedSimpleTextOutQueryMode
;
417 ProtocolToReturn
->SimpleTextOut
.SetMode
= FileBasedSimpleTextOutSetMode
;
418 ProtocolToReturn
->SimpleTextOut
.SetAttribute
= FileBasedSimpleTextOutSetAttribute
;
419 ProtocolToReturn
->SimpleTextOut
.ClearScreen
= FileBasedSimpleTextOutClearScreen
;
420 ProtocolToReturn
->SimpleTextOut
.SetCursorPosition
= FileBasedSimpleTextOutSetCursorPosition
;
421 ProtocolToReturn
->SimpleTextOut
.EnableCursor
= FileBasedSimpleTextOutEnableCursor
;
422 ProtocolToReturn
->SimpleTextOut
.OutputString
= FileBasedSimpleTextOutOutputString
;
423 ProtocolToReturn
->SimpleTextOut
.Mode
= AllocateZeroPool(sizeof(EFI_SIMPLE_TEXT_OUTPUT_MODE
));
424 if (ProtocolToReturn
->SimpleTextOut
.Mode
== NULL
) {
425 FreePool(ProtocolToReturn
);
428 ProtocolToReturn
->SimpleTextOut
.Mode
->MaxMode
= 0;
429 ProtocolToReturn
->SimpleTextOut
.Mode
->Mode
= 0;
430 ProtocolToReturn
->SimpleTextOut
.Mode
->Attribute
= 0;
431 ProtocolToReturn
->SimpleTextOut
.Mode
->CursorColumn
= 0;
432 ProtocolToReturn
->SimpleTextOut
.Mode
->CursorRow
= 0;
433 ProtocolToReturn
->SimpleTextOut
.Mode
->CursorVisible
= FALSE
;
435 Status
= gBS
->InstallProtocolInterface(
436 &(ProtocolToReturn
->TheHandle
),
437 &gEfiSimpleTextOutProtocolGuid
,
438 EFI_NATIVE_INTERFACE
,
439 &(ProtocolToReturn
->SimpleTextOut
));
440 if (!EFI_ERROR(Status
)) {
441 *HandleLocation
= ProtocolToReturn
->TheHandle
;
442 return ((EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*)ProtocolToReturn
);
444 FreePool(ProtocolToReturn
);
450 Function to close a EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL on top of a
451 SHELL_FILE_HANDLE to support redirecting output from a file.
453 @param[in] SimpleTextOut The pointer to the SimpleTextOUT to close.
455 @retval EFI_SUCCESS The object was closed.
459 CloseSimpleTextOutOnFile(
460 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOut
464 if (SimpleTextOut
== NULL
) {
465 return (EFI_INVALID_PARAMETER
);
467 Status
= gBS
->UninstallProtocolInterface(
468 ((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*)SimpleTextOut
)->TheHandle
,
469 &gEfiSimpleTextOutProtocolGuid
,
470 &(((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*)SimpleTextOut
)->SimpleTextOut
));
471 FreePool(SimpleTextOut
);