EventThread.h 1002 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #pragma once
  2. #include <vector>
  3. #include <map>
  4. typedef std::map<HANDLE, int> EventMapType;
  5. class CEventThread
  6. {
  7. public:
  8. CEventThread(void);
  9. ~CEventThread(void);
  10. static unsigned int __stdcall EventThreadFnc(void* thisptr);
  11. protected:
  12. virtual void OnEvent(int eventId, void *param) { return; }
  13. virtual void OnTimeOut(void *param) { return; }
  14. void RunThread();
  15. bool UndoFireEvent(int eventId);
  16. UINT m_threadID;
  17. HANDLE m_thread;
  18. HANDLE m_hEvt;
  19. EventMapType m_eventMap;
  20. bool m_exitThread;
  21. bool m_threadRunning;
  22. bool m_threadWasStarted;
  23. void *m_param;
  24. int m_waitTimeout;
  25. public:
  26. void Start(void *param = NULL);
  27. void Stop(int waitTime = 5000);
  28. void AddEvent(int eventId);
  29. void AddEvent(int eventId, CString name);
  30. bool FireEvent(int eventId);
  31. bool IsCancelled() { return m_exitThread; }
  32. void CancelThread() { m_exitThread = true; }
  33. bool IsRunning() { return m_threadRunning; }
  34. bool ThreadWasStarted() { return m_threadWasStarted; }
  35. void WaitForThreadToExit(int waitTime);
  36. };