File: Event.c

package info (click to toggle)
edk2 0~20131112.2590861a-3
  • links: PTS, VCS
  • area: non-free
  • in suites: jessie, jessie-kfreebsd
  • size: 125,836 kB
  • ctags: 175,818
  • sloc: ansic: 1,274,042; python: 75,968; asm: 68,082; perl: 22,386; cpp: 22,278; makefile: 14,914; sh: 4,113; pascal: 1,126; xml: 318; lisp: 24
file content (219 lines) | stat: -rw-r--r-- 5,381 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/*++

Copyright (c) 2005 - 2006, Intel Corporation                                                         
All rights reserved. This program and the accompanying materials                          
are licensed and made available under the terms and conditions of the BSD License         
which accompanies this distribution. The full text of the license may be found at         
http://opensource.org/licenses/bsd-license.php                                            
                                                                                          
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             

Module Name:

    Event.c

Abstract:

  The event function

Revision History

--*/

#include "EfiShellLib.h"

EFI_EVENT
LibCreateProtocolNotifyEvent (
  IN EFI_GUID             *ProtocolGuid,
  IN EFI_TPL              NotifyTpl,
  IN EFI_EVENT_NOTIFY     NotifyFunction,
  IN VOID                 *NotifyContext,
  OUT VOID                **Registration
  )
/*++

Routine Description:
  Function creates a notification event and registers that event with all 
  the protocol instances specified by ProtocolGuid.   

Arguments:
  ProtocolGuid     - Supplies GUID of the protocol upon whose installation the event is fired.

  NotifyTpl        - Supplies the task priority level of the event notifications.

  NotifyFunction   - Supplies the function to notify when the event is signaled.

  NotifyContext    - The context parameter to pass to NotifyFunction. 

  Registration     - A pointer to a memory location to receive the registration value.  
                     This value is passed to LibLocateHandle() to obtain new handles that 
                     have been added that support the ProtocolGuid-specified protocol.

Returns:

  This function returns the notification event that was created.

--*/
{
  EFI_STATUS  Status;
  EFI_EVENT   Event;

  //
  // Create the event
  //
  Status = BS->CreateEvent (
                EFI_EVENT_NOTIFY_SIGNAL,
                NotifyTpl,
                NotifyFunction,
                NotifyContext,
                &Event
                );
  if (EFI_ERROR (Status)) {
    return NULL;
  }
  //
  // Register for protocol notifactions on this event
  //
  Status = BS->RegisterProtocolNotify (
                ProtocolGuid,
                Event,
                Registration
                );

  if (EFI_ERROR (Status)) {
    return NULL;
  }
  //
  // Kick the event so we will perform an initial pass of
  // current installed drivers
  //
  BS->SignalEvent (Event);
  return Event;
}

VOID
WaitForEventWithTimeout (
  IN  EFI_EVENT       Event,
  IN  UINTN           Timeout,
  IN  UINTN           Row,
  IN  UINTN           Column,
  IN  CHAR16          *String,
  IN  EFI_INPUT_KEY   TimeoutKey,
  OUT EFI_INPUT_KEY   *Key
  )
/*++

Routine Description:
  function prints a string for the given number of seconds until either the 
  timeout expires, or the user presses a key.

Arguments:
  Event            - The event to wait for

  Timeout          - A timeout value in 1 second units.

  Row              - A row to print String

  Column           - A column to print String

  String           - The string to display on the standard output device

  TimeoutKey       - The key to return in Key if a timeout occurs

  Key              - Either the key the user pressed or TimeoutKey if the Timeout expired.

Returns:

  none

--*/
{
  EFI_STATUS  Status;

  ASSERT (Key);
  
  while (Timeout > 0) {
    PrintAt (Column, Row, String, Timeout);
    Status = WaitForSingleEvent (Event, 10000000);
    if (Status == EFI_SUCCESS) {
      if (!EFI_ERROR (ST->ConIn->ReadKeyStroke (ST->ConIn, Key))) {
        return ;
      }
    }

    Timeout--;
  }

  *Key = TimeoutKey;
}

EFI_STATUS
WaitForSingleEvent (
  IN EFI_EVENT                  Event,
  IN UINT64                     Timeout OPTIONAL
  )
/*++

Routine Description:
  Function waits for a given event to fire, or for an optional timeout to expire.

Arguments:
  Event            - The event to wait for

  Timeout          - An optional timeout value in 100 ns units.

Returns:

  EFI_SUCCESS       - Event fired before Timeout expired.
  EFI_TIME_OUT     - Timout expired before Event fired..

--*/
{
  EFI_STATUS  Status;
  UINTN       Index;
  EFI_EVENT   TimerEvent;
  EFI_EVENT   WaitList[2];

  if (Timeout) {
    //
    // Create a timer event
    //
    Status = BS->CreateEvent (EFI_EVENT_TIMER, 0, NULL, NULL, &TimerEvent);
    if (!EFI_ERROR (Status)) {
      //
      // Set the timer event
      //
      BS->SetTimer (
            TimerEvent,
            TimerRelative,
            Timeout
            );

      //
      // Wait for the original event or the timer
      //
      WaitList[0] = Event;
      WaitList[1] = TimerEvent;
      Status      = BS->WaitForEvent (2, WaitList, &Index);
      BS->CloseEvent (TimerEvent);

      //
      // If the timer expired, change the return to timed out
      //
      if (!EFI_ERROR (Status) && Index == 1) {
        Status = EFI_TIMEOUT;
      }
    }
  } else {
    //
    // No timeout... just wait on the event
    //
    Status = BS->WaitForEvent (1, &Event, &Index);
    ASSERT (!EFI_ERROR (Status));
    ASSERT (Index == 0);
  }

  return Status;
}