Rev 1599 | Rev 1646 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1599 | Rev 1601 | ||
|---|---|---|---|
| Line 19... | Line 19... | ||
| 19 | */ |
19 | */ |
| 20 | 20 | ||
| 21 | #ifndef TIMER_MANAGER_H |
21 | #ifndef TIMER_MANAGER_H |
| 22 | #define TIMER_MANAGER_H |
22 | #define TIMER_MANAGER_H |
| 23 | 23 | ||
| 24 | #include <boost/asio.hpp> |
- | |
| 25 | #include <boost/signals2.hpp> |
24 | #include <boost/signals2.hpp> |
| 26 | #include <boost/shared_ptr.hpp> |
25 | #include <boost/shared_ptr.hpp> |
| - | 26 | ||
| 27 | #include |
27 | #include "common/IoService.h" |
| 28 | #include <boost/thread/mutex.hpp> |
- | |
| 29 | 28 | ||
| 30 | #include "types.h" |
29 | #include "types.h" |
| 31 | #include "Timer.h" |
30 | #include "Timer.h" |
| 32 | 31 | ||
| 33 | namespace atom { |
32 | namespace atom { |
| 34 | namespace timer { |
33 | namespace timer { |
| 35 | 34 | ||
| 36 | class Manager |
35 | class Manager : public virtual common::IoService |
| 37 | { |
36 | { |
| 38 | public: |
37 | public: |
| 39 | typedef boost::shared_ptr<Manager> Pointer; |
38 | typedef boost::shared_ptr<Manager> Pointer; |
| 40 | 39 | ||
| 41 | typedef boost::signals2::signal<void( |
40 | typedef boost::signals2::signal<void(TimerId, bool)> SignalOnTimeout; |
| 42 | 41 | ||
| 43 | virtual ~Manager(); |
42 | virtual ~Manager(); |
| 44 | 43 | ||
| 45 | static Pointer Instance(); |
44 | static Pointer Instance(); |
| 46 | static void Create(); |
45 | static void Create(); |
| 47 | static void Delete(); |
46 | static void Delete(); |
| 48 | 47 | ||
| 49 | void ConnectSlots(const SignalOnTimeout::slot_type& slot_on_timeout); |
48 | void ConnectSlots(const SignalOnTimeout::slot_type& slot_on_timeout); |
| 50 | 49 | ||
| 51 | TimerId Set(unsigned int timeout, bool repeat); |
50 | TimerId Set(unsigned int timeout, bool repeat); |
| 52 | void Cancel(TimerId id); |
51 | void Cancel(TimerId id); |
| 53 | 52 | ||
| 54 | private: |
53 | private: |
| 55 | typedef std::map<TimerId, Timer::Pointer> TimerList; |
54 | typedef std::map<TimerId, Timer::Pointer> TimerList; |
| 56 | 55 | ||
| 57 | static Pointer instance_; |
56 | static Pointer instance_; |
| 58 | - | ||
| 59 | boost::thread thread_; |
- | |
| 60 | boost::asio::io_service io_service_; |
- | |
| 61 | boost::asio::io_service::work io_service_work_; |
- | |
| 62 | 57 | ||
| 63 | TimerList timers_; |
58 | TimerList timers_; |
| 64 | boost::mutex mutex_timers_; |
59 | boost::mutex mutex_timers_; |
| 65 | 60 | ||
| 66 | SignalOnTimeout signal_on_timeout_; |
61 | SignalOnTimeout signal_on_timeout_; |