Source code of Windows XP (NT5)
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.

133 lines
3.1 KiB

  1. #include <irda.h>
  2. #include <irioctl.h>
  3. #include <irlap.h>
  4. #include <irlmp.h>
  5. VOID
  6. IrdaTimerExpFunc(struct CTEEvent *Event, void *Arg);
  7. void
  8. IrdaTimerInitialize(PIRDA_TIMER pTimer,
  9. VOID (*ExpFunc)(PVOID Context),
  10. UINT Timeout,
  11. PVOID Context,
  12. PIRDA_LINK_CB pIrdaLinkCb)
  13. {
  14. #if DBG
  15. DEBUGMSG(DBG_TIMER, (TEXT("%hs timer initialized, context %x\n"),
  16. pTimer->pName, pTimer));
  17. #endif
  18. CTEInitTimer(&pTimer->CteTimer);
  19. CTEInitEvent(&pTimer->CteEvent, IrdaTimerExpFunc);
  20. pTimer->ExpFunc = ExpFunc;
  21. pTimer->Context = Context;
  22. pTimer->Timeout = Timeout;
  23. pTimer->pIrdaLinkCb = pIrdaLinkCb;
  24. }
  25. void
  26. TimerFuncAtDpcLevel(CTEEvent *Event, void *Arg)
  27. {
  28. PIRDA_TIMER pIrdaTimer = (PIRDA_TIMER) Arg;
  29. #if DBG
  30. DEBUGMSG(DBG_TIMER, (TEXT("%hs timer expired at DPC, context %x\n"),
  31. pIrdaTimer->pName, pIrdaTimer));
  32. #endif
  33. CTEScheduleEvent(&pIrdaTimer->CteEvent, Arg);
  34. return;
  35. }
  36. VOID
  37. IrdaTimerExpFunc(struct CTEEvent *Event, void *Arg)
  38. {
  39. PIRDA_TIMER pIrdaTimer = (PIRDA_TIMER) Arg;
  40. PIRDA_LINK_CB pIrdaLinkCb;
  41. #if DBG
  42. DEBUGMSG(DBG_TIMER, (TEXT("%hs timer expired, context %x\n"),
  43. pIrdaTimer->pName, pIrdaTimer));
  44. #endif
  45. pIrdaLinkCb = pIrdaTimer->pIrdaLinkCb;
  46. if (pIrdaLinkCb)
  47. LOCK_LINK(pIrdaLinkCb);
  48. if (pIrdaTimer->Late != TRUE)
  49. pIrdaTimer->ExpFunc(pIrdaTimer->Context);
  50. else
  51. {
  52. DEBUGMSG(DBG_WARN | DBG_TIMER,
  53. (TEXT("IRDA TIMER LATE, ignoring\n")));
  54. pIrdaTimer->Late = FALSE;
  55. }
  56. if (pIrdaLinkCb)
  57. {
  58. UNLOCK_LINK(pIrdaLinkCb);
  59. REFDEL(&pIrdaLinkCb->RefCnt,'RMIT');
  60. }
  61. return;
  62. }
  63. VOID
  64. IrdaTimerStart(PIRDA_TIMER pIrdaTimer)
  65. {
  66. if (pIrdaTimer->pIrdaLinkCb)
  67. REFADD(&pIrdaTimer->pIrdaLinkCb->RefCnt, 'RMIT');
  68. pIrdaTimer->Late = FALSE;
  69. CTEStartTimer(&pIrdaTimer->CteTimer, pIrdaTimer->Timeout,
  70. TimerFuncAtDpcLevel, (PVOID) pIrdaTimer);
  71. #if DBG
  72. DEBUGMSG(DBG_TIMER, (TEXT("Start timer %hs (%dms) context %x\n"),
  73. pIrdaTimer->pName,
  74. pIrdaTimer->Timeout,
  75. pIrdaTimer));
  76. #endif
  77. return;
  78. }
  79. VOID
  80. IrdaTimerStop(PIRDA_TIMER pIrdaTimer)
  81. {
  82. if (pIrdaTimer->pIrdaLinkCb)
  83. LOCK_LINK(pIrdaTimer->pIrdaLinkCb);
  84. if (CTEStopTimer(&pIrdaTimer->CteTimer) == 0)
  85. {
  86. pIrdaTimer->Late = TRUE;
  87. }
  88. else
  89. {
  90. if (pIrdaTimer->pIrdaLinkCb)
  91. REFDEL(&pIrdaTimer->pIrdaLinkCb->RefCnt,'RMIT');
  92. }
  93. #if DBG
  94. DEBUGMSG(DBG_TIMER, (TEXT("Timer %hs stopped, late %d\n"), pIrdaTimer->pName,
  95. pIrdaTimer->Late));
  96. #endif
  97. if (pIrdaTimer->pIrdaLinkCb)
  98. {
  99. UNLOCK_LINK(pIrdaTimer->pIrdaLinkCb);
  100. }
  101. return;
  102. }
  103. VOID
  104. IrdaTimerRestart(PIRDA_TIMER pIrdaTimer)
  105. {
  106. IrdaTimerStop(pIrdaTimer);
  107. IrdaTimerStart(pIrdaTimer);
  108. }