Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

149 lines
3.2 KiB

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