]> git.proxmox.com Git - mirror_edk2.git/blob - EdkUnixPkg/Dxe/UnixThunk/Bus/Console/ConsoleIn.c
Change many windows references to unix.
[mirror_edk2.git] / EdkUnixPkg / Dxe / UnixThunk / Bus / Console / ConsoleIn.c
1 /*++
2
3 Copyright (c) 2004, Intel Corporation
4 All rights reserved. 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 STATIC
36 EFI_STATUS
37 UnixSimpleTextInCheckKey (
38 UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private
39 );
40
41 EFI_STATUS
42 EFIAPI
43 UnixSimpleTextInReset (
44 IN EFI_SIMPLE_TEXT_IN_PROTOCOL *This,
45 IN BOOLEAN ExtendedVerification
46 )
47 /*++
48
49 Routine Description:
50
51 TODO: Add function description
52
53 Arguments:
54
55 This - TODO: add argument description
56 ExtendedVerification - TODO: add argument description
57
58 Returns:
59
60 EFI_SUCCESS - TODO: Add description for return value
61
62 --*/
63 {
64 UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;
65
66 Private = UNIX_SIMPLE_TEXT_IN_PRIVATE_DATA_FROM_THIS (This);
67 return EFI_SUCCESS;
68 }
69
70 STATIC
71 EFI_STATUS
72 UnixConvertInputRecordToEfiKey (
73 IN char c,
74 OUT EFI_INPUT_KEY *Key
75 )
76 /*++
77
78 Routine Description:
79
80 TODO: Add function description
81
82 Arguments:
83
84 InputRecord - TODO: add argument description
85 Key - TODO: add argument description
86
87 Returns:
88
89 EFI_NOT_READY - TODO: Add description for return value
90 EFI_NOT_READY - TODO: Add description for return value
91 EFI_NOT_READY - TODO: Add description for return value
92 EFI_SUCCESS - TODO: Add description for return value
93
94 --*/
95 {
96 Key->ScanCode = 0;
97 if (c == '\n')
98 c = '\r';
99 Key->UnicodeChar = c;
100 return EFI_SUCCESS;
101 }
102
103 STATIC
104 EFI_STATUS
105 EFIAPI
106 UnixSimpleTextInReadKeyStroke (
107 IN EFI_SIMPLE_TEXT_IN_PROTOCOL *This,
108 OUT EFI_INPUT_KEY *Key
109 )
110 /*++
111
112 Routine Description:
113
114 TODO: Add function description
115
116 Arguments:
117
118 This - TODO: add argument description
119 Key - TODO: add argument description
120
121 Returns:
122
123 EFI_DEVICE_ERROR - TODO: Add description for return value
124 EFI_NOT_READY - TODO: Add description for return value
125
126 --*/
127 {
128 EFI_STATUS Status;
129 UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;
130 char c;
131
132 Private = UNIX_SIMPLE_TEXT_IN_PRIVATE_DATA_FROM_THIS (This);
133
134 Status = UnixSimpleTextInCheckKey (Private);
135 if (EFI_ERROR (Status)) {
136 return Status;
137 }
138
139 if (Private->UnixThunk->Read (0, &c, 1) != 1)
140 return EFI_NOT_READY;
141 Status = UnixConvertInputRecordToEfiKey (c, Key);
142
143 return Status;
144 }
145
146 STATIC
147 VOID
148 EFIAPI
149 UnixSimpleTextInWaitForKey (
150 IN EFI_EVENT Event,
151 IN VOID *Context
152 )
153 /*++
154
155 Routine Description:
156
157 TODO: Add function description
158
159 Arguments:
160
161 Event - TODO: add argument description
162 Context - TODO: add argument description
163
164 Returns:
165
166 TODO: add return values
167
168 --*/
169 {
170 UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;
171 EFI_STATUS Status;
172
173 Private = (UNIX_SIMPLE_TEXT_PRIVATE_DATA *) Context;
174 Status = UnixSimpleTextInCheckKey (Private);
175 if (!EFI_ERROR (Status)) {
176 gBS->SignalEvent (Event);
177 }
178 }
179
180 STATIC
181 EFI_STATUS
182 UnixSimpleTextInCheckKey (
183 UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private
184 )
185 /*++
186
187 Routine Description:
188
189 TODO: Add function description
190
191 Arguments:
192
193 Private - TODO: add argument description
194
195 Returns:
196
197 TODO: add return values
198
199 --*/
200 {
201 struct pollfd pfd;
202
203 pfd.fd = 0;
204 pfd.events = POLLIN;
205 if (Private->UnixThunk->Poll (&pfd, 1, 0) <= 0) {
206 return EFI_NOT_READY;
207 }
208 return EFI_SUCCESS;
209 }
210
211 EFI_STATUS
212 UnixSimpleTextInAttachToWindow (
213 IN UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private
214 )
215 /*++
216
217 Routine Description:
218
219 TODO: Add function description
220
221 Arguments:
222
223 Private - TODO: add argument description
224
225 Returns:
226
227 TODO: add return values
228
229 --*/
230 {
231 EFI_STATUS Status;
232
233 Private->SimpleTextIn.Reset = UnixSimpleTextInReset;
234 Private->SimpleTextIn.ReadKeyStroke = UnixSimpleTextInReadKeyStroke;
235
236 Status = gBS->CreateEvent (
237 EFI_EVENT_NOTIFY_WAIT,
238 EFI_TPL_NOTIFY,
239 UnixSimpleTextInWaitForKey,
240 Private,
241 &Private->SimpleTextIn.WaitForKey
242 );
243 ASSERT_EFI_ERROR (Status);
244
245 return Status;
246 }