Rev 2726 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2726 | vana | 1 | /*++ |
2 | |||
3 | Copyright (c) 1998 Intel Corporation |
||
4 | |||
5 | Module Name: |
||
6 | |||
7 | event.c |
||
8 | |||
9 | Abstract: |
||
10 | |||
11 | |||
12 | |||
13 | |||
14 | Revision History |
||
15 | |||
16 | --*/ |
||
17 | |||
18 | #include "lib.h" |
||
19 | |||
20 | |||
21 | EFI_EVENT |
||
22 | LibCreateProtocolNotifyEvent ( |
||
23 | IN EFI_GUID *ProtocolGuid, |
||
24 | IN EFI_TPL NotifyTpl, |
||
25 | IN EFI_EVENT_NOTIFY NotifyFunction, |
||
26 | IN VOID *NotifyContext, |
||
27 | OUT VOID *Registration |
||
28 | ) |
||
29 | { |
||
30 | EFI_STATUS Status; |
||
31 | EFI_EVENT Event; |
||
32 | |||
33 | // |
||
34 | // Create the event |
||
35 | // |
||
36 | |||
37 | Status = BS->CreateEvent ( |
||
38 | EVT_NOTIFY_SIGNAL, |
||
39 | NotifyTpl, |
||
40 | NotifyFunction, |
||
41 | NotifyContext, |
||
42 | &Event |
||
43 | ); |
||
44 | ASSERT (!EFI_ERROR(Status)); |
||
45 | |||
46 | // |
||
47 | // Register for protocol notifactions on this event |
||
48 | // |
||
49 | |||
50 | Status = BS->RegisterProtocolNotify ( |
||
51 | ProtocolGuid, |
||
52 | Event, |
||
53 | Registration |
||
54 | ); |
||
55 | |||
56 | ASSERT (!EFI_ERROR(Status)); |
||
57 | |||
58 | // |
||
59 | // Kick the event so we will perform an initial pass of |
||
60 | // current installed drivers |
||
61 | // |
||
62 | |||
63 | BS->SignalEvent (Event); |
||
64 | return Event; |
||
65 | } |
||
66 | |||
67 | |||
68 | EFI_STATUS |
||
69 | WaitForSingleEvent ( |
||
70 | IN EFI_EVENT Event, |
||
71 | IN UINT64 Timeout OPTIONAL |
||
72 | ) |
||
73 | { |
||
74 | EFI_STATUS Status; |
||
75 | UINTN Index; |
||
76 | EFI_EVENT TimerEvent; |
||
77 | EFI_EVENT WaitList[2]; |
||
78 | |||
79 | if (Timeout) { |
||
80 | // |
||
81 | // Create a timer event |
||
82 | // |
||
83 | |||
84 | Status = BS->CreateEvent (EVT_TIMER, 0, NULL, NULL, &TimerEvent); |
||
85 | if (!EFI_ERROR(Status)) { |
||
86 | |||
87 | // |
||
88 | // Set the timer event |
||
89 | // |
||
90 | |||
91 | BS->SetTimer (TimerEvent, TimerRelative, Timeout); |
||
92 | |||
93 | // |
||
94 | // Wait for the original event or the timer |
||
95 | // |
||
96 | |||
97 | WaitList[0] = Event; |
||
98 | WaitList[1] = TimerEvent; |
||
99 | Status = BS->WaitForEvent (2, WaitList, &Index); |
||
100 | BS->CloseEvent (TimerEvent); |
||
101 | |||
102 | // |
||
103 | // If the timer expired, change the return to timed out |
||
104 | // |
||
105 | |||
106 | if (!EFI_ERROR(Status) && Index == 1) { |
||
107 | Status = EFI_TIMEOUT; |
||
108 | } |
||
109 | } |
||
110 | |||
111 | } else { |
||
112 | |||
113 | // |
||
114 | // No timeout... just wait on the event |
||
115 | // |
||
116 | |||
117 | Status = BS->WaitForEvent (1, &Event, &Index); |
||
118 | ASSERT (!EFI_ERROR(Status)); |
||
119 | ASSERT (Index == 0); |
||
120 | } |
||
121 | |||
122 | return Status; |
||
123 | } |
||
124 | |||
125 | VOID |
||
126 | WaitForEventWithTimeout ( |
||
127 | IN EFI_EVENT Event, |
||
128 | IN UINTN Timeout, |
||
129 | IN UINTN Row, |
||
130 | IN UINTN Column, |
||
131 | IN CHAR16 *String, |
||
132 | IN EFI_INPUT_KEY TimeoutKey, |
||
133 | OUT EFI_INPUT_KEY *Key |
||
134 | ) |
||
135 | { |
||
136 | EFI_STATUS Status; |
||
137 | |||
138 | do { |
||
139 | PrintAt (Column, Row, String, Timeout); |
||
140 | Status = WaitForSingleEvent (Event, 10000000); |
||
141 | if (Status == EFI_SUCCESS) { |
||
142 | if (!EFI_ERROR(ST->ConIn->ReadKeyStroke (ST->ConIn, Key))) { |
||
143 | return; |
||
144 | } |
||
145 | } |
||
146 | } while (Timeout > 0); |
||
147 | *Key = TimeoutKey; |
||
148 | } |
||
149 |