EventThread.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. CString m_threadName;
  26. public:
  27. void Start(void *param = NULL);
  28. void Stop(int waitTime = 5000);
  29. void AddEvent(int eventId);
  30. void AddEvent(int eventId, CString name);
  31. bool FireEvent(int eventId);
  32. bool IsCancelled() { return m_exitThread; }
  33. void CancelThread() { m_exitThread = true; }
  34. bool IsRunning() { return m_threadRunning; }
  35. bool ThreadWasStarted() { return m_threadWasStarted; }
  36. void WaitForThreadToExit(int waitTime);
  37. };