]> git.proxmox.com Git - mirror_edk2.git/blob - UnixPkg/UnixConsoleDxe/ConsoleIn.c
Update the copyright notice format
[mirror_edk2.git] / UnixPkg / UnixConsoleDxe / ConsoleIn.c
1 /*++
2
3 Copyright (c) 2004, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 ConsoleIn.c
15
16 Abstract:
17
18 Console based on Posix APIs.
19
20 This file attaches a SimpleTextIn protocol to a previously open window.
21
22 The constructor for this protocol depends on an open window. Currently
23 the SimpleTextOut protocol creates a window when it's constructor is called.
24 Thus this code must run after the constructor for the SimpleTextOut
25 protocol
26
27 --*/
28
29 #include "Console.h"
30 #include <sys/poll.h>
31
32 //
33 // Private worker functions
34 //
35 EFI_STATUS
36 UnixSimpleTextInCheckKey (
37 UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private
38 );
39
40 EFI_STATUS
41 EFIAPI
42 UnixSimpleTextInReset (
43 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
44 IN BOOLEAN ExtendedVerification
45 )
46 /*++
47
48 Routine Description:
49
50 TODO: Add function description
51
52 Arguments:
53
54 This - TODO: add argument description
55 ExtendedVerification - TODO: add argument description
56
57 Returns:
58
59 EFI_SUCCESS - TODO: Add description for return value
60
61 --*/
62 {
63 UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;
64
65 Private = UNIX_SIMPLE_TEXT_IN_PRIVATE_DATA_FROM_THIS (This);
66 return EFI_SUCCESS;
67 }
68
69 EFI_STATUS
70 UnixConvertInputRecordToEfiKey (
71 IN char c,
72 OUT EFI_INPUT_KEY *Key
73 )
74 /*++
75
76 Routine Description:
77
78 TODO: Add function description
79
80 Arguments:
81
82 InputRecord - TODO: add argument description
83 Key - TODO: add argument description
84
85 Returns:
86
87 EFI_NOT_READY - TODO: Add description for return value
88 EFI_NOT_READY - TODO: Add description for return value
89 EFI_NOT_READY - TODO: Add description for return value
90 EFI_SUCCESS - TODO: Add description for return value
91
92 --*/
93 {
94 Key->ScanCode = 0;
95 if (c == '\n')
96 c = '\r';
97 Key->UnicodeChar = c;
98 return EFI_SUCCESS;
99 }
100
101 EFI_STATUS
102 EFIAPI
103 UnixSimpleTextInReadKeyStroke (
104 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
105 OUT EFI_INPUT_KEY *Key
106 )
107 /*++
108
109 Routine Description:
110
111 TODO: Add function description
112
113 Arguments:
114
115 This - TODO: add argument description
116 Key - TODO: add argument description
117
118 Returns:
119
120 EFI_DEVICE_ERROR - TODO: Add description for return value
121 EFI_NOT_READY - TODO: Add description for return value
122
123 --*/
124 {
125 EFI_STATUS Status;
126 UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;
127 char c;
128
129 Private = UNIX_SIMPLE_TEXT_IN_PRIVATE_DATA_FROM_THIS (This);
130
131 Status = UnixSimpleTextInCheckKey (Private);
132 if (EFI_ERROR (Status)) {
133 return Status;
134 }
135
136 if (Private->UnixThunk->Read (0, &c, 1) != 1)
137 return EFI_NOT_READY;
138 Status = UnixConvertInputRecordToEfiKey (c, Key);
139
140 return Status;
141 }
142
143 VOID
144 EFIAPI
145 UnixSimpleTextInWaitForKey (
146 IN EFI_EVENT Event,
147 IN VOID *Context
148 )
149 /*++
150
151 Routine Description:
152
153 TODO: Add function description
154
155 Arguments:
156
157 Event - TODO: add argument description
158 Context - TODO: add argument description
159
160 Returns:
161
162 TODO: add return values
163
164 --*/
165 {
166 UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;
167 EFI_STATUS Status;
168
169 Private = (UNIX_SIMPLE_TEXT_PRIVATE_DATA *) Context;
170 Status = UnixSimpleTextInCheckKey (Private);
171 if (!EFI_ERROR (Status)) {
172 gBS->SignalEvent (Event);
173 }
174 }
175
176 EFI_STATUS
177 UnixSimpleTextInCheckKey (
178 UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private
179 )
180 /*++
181
182 Routine Description:
183
184 TODO: Add function description
185
186 Arguments:
187
188 Private - TODO: add argument description
189
190 Returns:
191
192 TODO: add return values
193
194 --*/
195 {
196 struct pollfd pfd;
197
198 pfd.fd = 0;
199 pfd.events = POLLIN;
200 if (Private->UnixThunk->Poll (&pfd, 1, 0) <= 0) {
201 return EFI_NOT_READY;
202 }
203 return EFI_SUCCESS;
204 }
205
206 EFI_STATUS
207 UnixSimpleTextInAttachToWindow (
208 IN UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private
209 )
210 /*++
211
212 Routine Description:
213
214 TODO: Add function description
215
216 Arguments:
217
218 Private - TODO: add argument description
219
220 Returns:
221
222 TODO: add return values
223
224 --*/
225 {
226 EFI_STATUS Status;
227
228 Private->SimpleTextIn.Reset = UnixSimpleTextInReset;
229 Private->SimpleTextIn.ReadKeyStroke = UnixSimpleTextInReadKeyStroke;
230
231 Status = gBS->CreateEvent (
232 EVT_NOTIFY_WAIT,
233 TPL_NOTIFY,
234 UnixSimpleTextInWaitForKey,
235 Private,
236 &Private->SimpleTextIn.WaitForKey
237 );
238 ASSERT_EFI_ERROR (Status);
239
240 return Status;
241 }