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.

85 lines
2.2 KiB

  1. #ifndef __TP_WRAP_
  2. #define __TP_WRAP_
  3. #ifdef DBG
  4. #undef NDEBUG
  5. #endif
  6. #include <assert.h>
  7. #include <windows.h>
  8. #include <locks.h>
  9. class Dispatcher;
  10. class EventHandler : public LIST_ENTRY
  11. {
  12. protected:
  13. LONG refCount_;
  14. LONG scheduledClose_; // logicaly bool
  15. HANDLE handlerID_;
  16. LONG once_;
  17. Dispatcher * dispatcher_;
  18. friend class Dispatcher;
  19. public:
  20. enum HANDLER_TYPE { TIMER, WAIT} type_;
  21. HANDLER_TYPE handlerType(){ return type_;}
  22. virtual LONG AddRef(void);
  23. virtual LONG Release(void);
  24. virtual void close(void);
  25. virtual HANDLE getHandle(void);
  26. virtual int handleTimeout(void);
  27. virtual int handleEvent(void);
  28. virtual DWORD getTimeOut(void);
  29. Dispatcher * dispatcher(void);
  30. void dispatcher(Dispatcher* r);
  31. protected:
  32. EventHandler(void);
  33. virtual ~EventHandler(void)=0;
  34. };
  35. #ifdef WINVER
  36. #if (WINVER>=0x0500)
  37. class Dispatcher{
  38. static LIST_ENTRY handlerListHead_;
  39. static volatile LONG registeredHandlers_;
  40. static bool startShutDown_;
  41. static CriticalSection handlerListLock_;
  42. public:
  43. static int registerHandler(EventHandler& eh, int flags = WT_EXECUTELONGFUNCTION) ;
  44. static int registerHandlerOnce(EventHandler& eh, int flags = WT_EXECUTELONGFUNCTION) ;
  45. static int removeHandler(EventHandler& handler);
  46. static int scheduleTimer(EventHandler& eh, DWORD first, DWORD repeat=0, DWORD mode = WT_EXECUTELONGFUNCTION);
  47. static int cancelTimer(EventHandler& handler);
  48. static int changeTimer(EventHandler& handler, DWORD first, DWORD repeat=0);
  49. static int close();
  50. static int open();
  51. private:
  52. static void insertTail(EventHandler *entry);
  53. static void removeEntry(EventHandler *entry);
  54. static void closeHandler(EventHandler* entry);
  55. static void openHandler(EventHandler* entry);
  56. static DWORD WINAPI DeleteTimer( LPVOID lpParameter);
  57. static DWORD WINAPI DeleteNotification( LPVOID lpParameter);
  58. static BOOL PostDeleteNotification(EventHandler& ev);
  59. static BOOL PostDeleteTimer(EventHandler& ev);
  60. static VOID CALLBACK HandleWaitOrTimerCallback( PVOID lpParameter, BOOLEAN TimerOrWaitFired );
  61. static void CALLBACK TimerCallback(void* lpParameter, BOOLEAN TimerOrWaitFired);
  62. };
  63. #endif
  64. #endif
  65. #endif