Obsoleted by new schema and new build tools.
[mirror_edk2.git] / EdkNt32Pkg / Dxe / WinNtThunk / Bus / Uga / WinNtUgaInput.c
CommitLineData
878ddf1f 1/*++\r
2\r
3Copyright (c) 2006, 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 WinNtUgaInput.c\r
15\r
16Abstract:\r
17\r
18 This file produces the Simple Text In for an Uga window. \r
19\r
20 This stuff is linked at the hip to the Window, since the window\r
21 processing is done in a thread kicked off in WinNtUgaImplementation.c\r
22\r
23 Since the window information is processed in an other thread we need\r
24 a keyboard Queue to pass data about. The Simple Text In code just \r
25 takes data off the Queue. The WinProc message loop takes keyboard input\r
26 and places it in the Queue.\r
27\r
28--*/\r
29\r
30#include "WinNtUga.h"\r
31\r
32EFI_STATUS\r
33UgaPrivateCreateQ (\r
34 IN UGA_PRIVATE_DATA *Private\r
35 )\r
36/*++\r
37\r
38Routine Description:\r
39\r
40 TODO: Add function description\r
41\r
42Arguments:\r
43\r
44 Private - TODO: add argument description\r
45\r
46Returns:\r
47\r
48 EFI_SUCCESS - TODO: Add description for return value\r
49\r
50--*/\r
51{\r
52 Private->WinNtThunk->InitializeCriticalSection (&Private->QCriticalSection);\r
53\r
54 Private->Queue.Front = 0;\r
55 Private->Queue.Rear = MAX_Q - 1;\r
56 Private->Queue.Count = 0;\r
57 return EFI_SUCCESS;\r
58}\r
59\r
60EFI_STATUS\r
61UgaPrivateDestroyQ (\r
62 IN UGA_PRIVATE_DATA *Private\r
63 )\r
64/*++\r
65\r
66Routine Description:\r
67\r
68 TODO: Add function description\r
69\r
70Arguments:\r
71\r
72 Private - TODO: add argument description\r
73\r
74Returns:\r
75\r
76 EFI_SUCCESS - TODO: Add description for return value\r
77\r
78--*/\r
79{\r
80 Private->Queue.Count = 0;\r
81 Private->WinNtThunk->DeleteCriticalSection (&Private->QCriticalSection);\r
82 return EFI_SUCCESS;\r
83}\r
84\r
85EFI_STATUS\r
86UgaPrivateAddQ (\r
87 IN UGA_PRIVATE_DATA *Private,\r
88 IN EFI_INPUT_KEY Key\r
89 )\r
90/*++\r
91\r
92Routine Description:\r
93\r
94 TODO: Add function description\r
95\r
96Arguments:\r
97\r
98 Private - TODO: add argument description\r
99 Key - TODO: add argument description\r
100\r
101Returns:\r
102\r
103 EFI_NOT_READY - TODO: Add description for return value\r
104 EFI_SUCCESS - TODO: Add description for return value\r
105\r
106--*/\r
107{\r
108 Private->WinNtThunk->EnterCriticalSection (&Private->QCriticalSection);\r
109\r
110 if (Private->Queue.Count == MAX_Q) {\r
111 Private->WinNtThunk->LeaveCriticalSection (&Private->QCriticalSection);\r
112 return EFI_NOT_READY;\r
113 }\r
114\r
115 Private->Queue.Rear = (Private->Queue.Rear + 1) % MAX_Q;\r
116 Private->Queue.Q[Private->Queue.Rear] = Key;\r
117 Private->Queue.Count++;\r
118\r
119 Private->WinNtThunk->LeaveCriticalSection (&Private->QCriticalSection);\r
120 return EFI_SUCCESS;\r
121}\r
122\r
123EFI_STATUS\r
124UgaPrivateDeleteQ (\r
125 IN UGA_PRIVATE_DATA *Private,\r
126 OUT EFI_INPUT_KEY *Key\r
127 )\r
128/*++\r
129\r
130Routine Description:\r
131\r
132 TODO: Add function description\r
133\r
134Arguments:\r
135\r
136 Private - TODO: add argument description\r
137 Key - TODO: add argument description\r
138\r
139Returns:\r
140\r
141 EFI_NOT_READY - TODO: Add description for return value\r
142 EFI_SUCCESS - TODO: Add description for return value\r
143\r
144--*/\r
145{\r
146 Private->WinNtThunk->EnterCriticalSection (&Private->QCriticalSection);\r
147\r
148 if (Private->Queue.Count == 0) {\r
149 Private->WinNtThunk->LeaveCriticalSection (&Private->QCriticalSection);\r
150 return EFI_NOT_READY;\r
151 }\r
152\r
153 *Key = Private->Queue.Q[Private->Queue.Front];\r
154 Private->Queue.Front = (Private->Queue.Front + 1) % MAX_Q;\r
155 Private->Queue.Count--;\r
156\r
157 Private->WinNtThunk->LeaveCriticalSection (&Private->QCriticalSection);\r
158 return EFI_SUCCESS;\r
159}\r
160\r
161EFI_STATUS\r
162UgaPrivateCheckQ (\r
163 IN UGA_PRIVATE_DATA *Private\r
164 )\r
165/*++\r
166\r
167Routine Description:\r
168\r
169 TODO: Add function description\r
170\r
171Arguments:\r
172\r
173 Private - TODO: add argument description\r
174\r
175Returns:\r
176\r
177 EFI_NOT_READY - TODO: Add description for return value\r
178 EFI_SUCCESS - TODO: Add description for return value\r
179\r
180--*/\r
181{\r
182 if (Private->Queue.Count == 0) {\r
183 return EFI_NOT_READY;\r
184 }\r
185\r
186 return EFI_SUCCESS;\r
187}\r
188\r
189//\r
190// Simple Text In implementation.\r
191//\r
192\r
193EFI_STATUS\r
194EFIAPI\r
195WinNtUgaSimpleTextInReset (\r
196 IN EFI_SIMPLE_TEXT_IN_PROTOCOL *This,\r
197 IN BOOLEAN ExtendedVerification\r
198 )\r
199/*++\r
200\r
201Routine Description:\r
202\r
203 TODO: Add function description\r
204\r
205Arguments:\r
206\r
207 This - TODO: add argument description\r
208 ExtendedVerification - TODO: add argument description\r
209\r
210Returns:\r
211\r
212 EFI_SUCCESS - TODO: Add description for return value\r
213\r
214--*/\r
215{\r
216 UGA_PRIVATE_DATA *Private;\r
217 EFI_INPUT_KEY Key;\r
218 EFI_TPL OldTpl;\r
219\r
220 Private = UGA_PRIVATE_DATA_FROM_TEXT_IN_THIS (This);\r
221\r
222 //\r
223 // Enter critical section\r
224 //\r
225 OldTpl = gBS->RaiseTPL (EFI_TPL_NOTIFY);\r
226\r
227 //\r
228 // A reset is draining the Queue\r
229 //\r
230 while (UgaPrivateDeleteQ (Private, &Key) == EFI_SUCCESS)\r
231 ;\r
232\r
233 //\r
234 // Leave critical section and return\r
235 //\r
236 gBS->RestoreTPL (OldTpl);\r
237 return EFI_SUCCESS;\r
238}\r
239\r
240STATIC\r
241EFI_STATUS\r
242EFIAPI\r
243WinNtUgaSimpleTextInReadKeyStroke (\r
244 IN EFI_SIMPLE_TEXT_IN_PROTOCOL *This,\r
245 OUT EFI_INPUT_KEY *Key\r
246 )\r
247/*++\r
248\r
249Routine Description:\r
250\r
251 TODO: Add function description\r
252\r
253Arguments:\r
254\r
255 This - TODO: add argument description\r
256 Key - TODO: add argument description\r
257\r
258Returns:\r
259\r
260 TODO: add return values\r
261\r
262--*/\r
263{\r
264 UGA_PRIVATE_DATA *Private;\r
265 EFI_STATUS Status;\r
266 EFI_TPL OldTpl;\r
267\r
268 Private = UGA_PRIVATE_DATA_FROM_TEXT_IN_THIS (This);\r
269\r
270 //\r
271 // Enter critical section\r
272 //\r
273 OldTpl = gBS->RaiseTPL (EFI_TPL_NOTIFY);\r
274\r
275 Status = UgaPrivateCheckQ (Private);\r
276 if (!EFI_ERROR (Status)) {\r
277 //\r
278 // If a Key press exists try and read it.\r
279 //\r
280 Status = UgaPrivateDeleteQ (Private, Key);\r
281 }\r
282\r
283 //\r
284 // Leave critical section and return\r
285 //\r
286 gBS->RestoreTPL (OldTpl);\r
287\r
288 return Status;\r
289}\r
290\r
291STATIC\r
292VOID\r
293EFIAPI\r
294WinNtUgaSimpleTextInWaitForKey (\r
295 IN EFI_EVENT Event,\r
296 IN VOID *Context\r
297 )\r
298/*++\r
299\r
300Routine Description:\r
301\r
302 TODO: Add function description\r
303\r
304Arguments:\r
305\r
306 Event - TODO: add argument description\r
307 Context - TODO: add argument description\r
308\r
309Returns:\r
310\r
311 TODO: add return values\r
312\r
313--*/\r
314{\r
315 UGA_PRIVATE_DATA *Private;\r
316 EFI_STATUS Status;\r
317 EFI_TPL OldTpl;\r
318\r
319 Private = (UGA_PRIVATE_DATA *) Context;\r
320\r
321 //\r
322 // Enter critical section\r
323 //\r
324 OldTpl = gBS->RaiseTPL (EFI_TPL_NOTIFY);\r
325\r
326 Status = UgaPrivateCheckQ (Private);\r
327 if (!EFI_ERROR (Status)) {\r
328 //\r
329 // If a there is a key in the queue signal our event.\r
330 //\r
331 gBS->SignalEvent (Event);\r
332 } else {\r
333 //\r
334 // We need to sleep or NT will schedule this thread with such high\r
335 // priority that WinProc thread will never run and we will not see\r
336 // keyboard input. This Sleep makes the syste run 10x faster, so don't\r
337 // remove it.\r
338 //\r
339 Private->WinNtThunk->Sleep (1);\r
340 }\r
341\r
342 //\r
343 // Leave critical section and return\r
344 //\r
345 gBS->RestoreTPL (OldTpl);\r
346}\r
347\r
348EFI_STATUS\r
349WinNtUgaInitializeSimpleTextInForWindow (\r
350 IN UGA_PRIVATE_DATA *Private\r
351 )\r
352/*++\r
353\r
354Routine Description:\r
355\r
356 TODO: Add function description\r
357\r
358Arguments:\r
359\r
360 Private - TODO: add argument description\r
361\r
362Returns:\r
363\r
364 TODO: add return values\r
365\r
366--*/\r
367{\r
368 EFI_STATUS Status;\r
369\r
370 UgaPrivateCreateQ (Private);\r
371\r
372 //\r
373 // Initialize Simple Text In protoocol\r
374 //\r
375 Private->SimpleTextIn.Reset = WinNtUgaSimpleTextInReset;\r
376 Private->SimpleTextIn.ReadKeyStroke = WinNtUgaSimpleTextInReadKeyStroke;\r
377\r
378 Status = gBS->CreateEvent (\r
379 EFI_EVENT_NOTIFY_WAIT,\r
380 EFI_TPL_NOTIFY,\r
381 WinNtUgaSimpleTextInWaitForKey,\r
382 Private,\r
383 &Private->SimpleTextIn.WaitForKey\r
384 );\r
385\r
386 return Status;\r
387}\r
388\r
389EFI_STATUS\r
390WinNtUgaDestroySimpleTextInForWindow (\r
391 IN UGA_PRIVATE_DATA *Private\r
392 )\r
393/*++\r
394\r
395Routine Description:\r
396\r
397 TODO: Add function description\r
398\r
399Arguments:\r
400\r
401 Private - TODO: add argument description\r
402\r
403Returns:\r
404\r
405 EFI_SUCCESS - TODO: Add description for return value\r
406\r
407--*/\r
408{\r
409 UgaPrivateDestroyQ (Private);\r
410 return EFI_SUCCESS;\r
411}\r