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.

187 lines
3.8 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. event.c
  5. Abstract:
  6. This module contains the event handling routines for SAC.
  7. Author:
  8. Sean Selitrennikoff (v-seans) - Jan 22, 1999
  9. Brian Guarraci (briangu)
  10. Revision History:
  11. --*/
  12. #include "sac.h"
  13. #if DBG
  14. //
  15. // A timer to show how many times we've hit the TimerDPC routine
  16. //
  17. // Note: use KD to view this value
  18. //
  19. ULONG TimerDpcCount = 0;
  20. #endif
  21. //
  22. // Serial Port Buffer globals
  23. //
  24. PUCHAR SerialPortBuffer = NULL;
  25. ULONG SerialPortProducerIndex = 0;
  26. ULONG SerialPortConsumerIndex = 0;
  27. VOID
  28. WorkerProcessEvents(
  29. IN PSAC_DEVICE_CONTEXT DeviceContext
  30. )
  31. /*++
  32. Routine Description:
  33. This is the routine for the worker thread. It blocks on an event, when
  34. the event is signalled, then that indicates a request is ready to be processed.
  35. Arguments:
  36. DeviceContext - A pointer to this device.
  37. Return Value:
  38. None.
  39. --*/
  40. {
  41. //
  42. // Call the Worker handler
  43. //
  44. // Note: currently hardcoded to the console manager
  45. //
  46. IoMgrWorkerProcessEvents(DeviceContext);
  47. }
  48. VOID
  49. TimerDpcRoutine(
  50. IN struct _KDPC *Dpc,
  51. IN PVOID DeferredContext,
  52. IN PVOID SystemArgument1,
  53. IN PVOID SystemArgument2
  54. )
  55. /*++
  56. Routine Description:
  57. This is a DPC routine that is queue'd by DriverEntry. It is used to check for any
  58. user input and then processes them.
  59. Arguments:
  60. DeferredContext - A pointer to the device context.
  61. All other parameters are unused.
  62. Return Value:
  63. None.
  64. --*/
  65. {
  66. NTSTATUS Status;
  67. SIZE_T i;
  68. BOOLEAN HaveNewData;
  69. HEADLESS_RSP_GET_BYTE Response;
  70. //
  71. // Keep track of how many times we've been here
  72. //
  73. #if DBG
  74. InterlockedIncrement((volatile long *)&TimerDpcCount);
  75. #endif
  76. UNREFERENCED_PARAMETER(Dpc);
  77. UNREFERENCED_PARAMETER(SystemArgument1);
  78. UNREFERENCED_PARAMETER(SystemArgument2);
  79. //
  80. // default: we didn't receive any new data
  81. //
  82. HaveNewData = FALSE;
  83. i = sizeof(HEADLESS_RSP_GET_BYTE);
  84. do {
  85. //
  86. // Check for user input
  87. //
  88. Status = HeadlessDispatch(
  89. HeadlessCmdGetByte,
  90. NULL,
  91. 0,
  92. &Response,
  93. &i
  94. );
  95. if (! NT_SUCCESS(Status)) {
  96. break;
  97. }
  98. //
  99. // If we received new data, add it to the buffer
  100. //
  101. if (Response.Value != 0) {
  102. //
  103. // we have new data
  104. //
  105. HaveNewData = TRUE;
  106. //
  107. // Assign the new value to the current producer index
  108. //
  109. // Note: We overrun data in the buffer if the consumer hasn't caught up
  110. //
  111. SerialPortBuffer[SerialPortProducerIndex] = Response.Value;
  112. //
  113. // Compute the new producer index and store it atomically
  114. //
  115. InterlockedExchange(
  116. (volatile long *)&SerialPortProducerIndex,
  117. (SerialPortProducerIndex + 1) % SERIAL_PORT_BUFFER_LENGTH
  118. );
  119. }
  120. } while ( Response.Value != 0 );
  121. //
  122. // if we have new data, notify the worker thread to process the serial port buffer
  123. //
  124. if (HaveNewData) {
  125. PSAC_DEVICE_CONTEXT DeviceContext;
  126. ProcessingType = SAC_PROCESS_SERIAL_PORT_BUFFER;
  127. DeviceContext = (PSAC_DEVICE_CONTEXT)DeferredContext;
  128. KeSetEvent(
  129. &(DeviceContext->ProcessEvent),
  130. DeviceContext->PriorityBoost,
  131. FALSE
  132. );
  133. }
  134. }