linux版本中间件

TimeScheduler.h 829B

123456789101112131415161718192021222324252627282930313233
  1. #pragma once
  2. #include <iostream>
  3. #include <boost/asio.hpp>
  4. #include <boost/asio/steady_timer.hpp>
  5. #include <boost/asio/system_timer.hpp>
  6. #include <boost/asio/high_resolution_timer.hpp>
  7. #include <list>
  8. #include "ITimer.h"
  9. using namespace boost::posix_time;
  10. using namespace boost::asio;
  11. using namespace std;
  12. class TimeScheduler
  13. {
  14. public:
  15. void startTimer();
  16. void attachITimer(ITimer* pTimer);
  17. void detachITimer(ITimer* pTimer);
  18. static TimeScheduler* GetInstance() { return &instance; };
  19. private:
  20. TimeScheduler();
  21. ~TimeScheduler();
  22. TimeScheduler(const TimeScheduler&)=default;
  23. TimeScheduler& operator = (const TimeScheduler&) = default;
  24. void __onTimer(const error_code& ec);
  25. private:
  26. boost::asio::io_service io_;
  27. boost::asio::steady_timer timer_;
  28. std::list<ITimer*> m_ITimes;
  29. static TimeScheduler instance;
  30. };