worker.h 573 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #ifndef WORKER_H
  2. #define WORKER_H
  3. #include "timer.h"
  4. #include <iostream>
  5. namespace iv {
  6. class Worker
  7. {
  8. public:
  9. enum
  10. {
  11. WS_INIT = 0x001,
  12. WS_RUN = 0x002,
  13. WS_SUSPEND = 0x003,
  14. WS_TERMINATE = 0x004,
  15. };
  16. public:
  17. Worker(float hz=20);
  18. virtual ~Worker();
  19. virtual void DoWork() = 0;
  20. void Run();
  21. void Suspend();
  22. void Terminate();
  23. protected:
  24. void MainThread();
  25. protected:
  26. std::thread main_thread_;
  27. Timer timer_;
  28. std::uint16_t worker_state_;
  29. };
  30. }
  31. #endif // WORKER_H