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