Rev 1593 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1593 | Rev 1646 | ||
|---|---|---|---|
| Line 17... | Line 17... | ||
| 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
18 | * |
| 19 | */ |
19 | */ |
| 20 | 20 | ||
| 21 | #include "Timer.h" |
21 | #include "Timer.h" |
| - | 22 | ||
| - | 23 | #include <boost/date_time/posix_time/posix_time.hpp> |
|
| 22 | 24 | ||
| 23 | namespace atom { |
25 | namespace atom { |
| 24 | namespace timer { |
26 | namespace timer { |
| 25 | 27 | ||
| 26 | Timer::Timer(boost::asio::io_service& io_service, TimerId id, unsigned int timeout, bool repeat) : instance_(io_service) |
28 | Timer::Timer(boost::asio::io_service& io_service, TimerId id, unsigned int timeout, bool repeat) : instance_(io_service) |
| 27 | { |
29 | { |
| 28 | this->id_ = id; |
30 | this->id_ = id; |
| 29 | this->timeout_ = timeout; |
31 | this->timeout_ = timeout; |
| 30 | this->repeat_ = repeat; |
32 | this->repeat_ = repeat; |
| - | 33 | this->time_ = ""; |
|
| 31 | } |
34 | } |
| - | 35 | ||
| - | 36 | Timer::Timer(boost::asio::io_service& io_service, TimerId id, std::string time) : instance_(io_service) |
|
| - | 37 | { |
|
| - | 38 | this->id_ = id; |
|
| - | 39 | this->timeout_ = 0; |
|
| - | 40 | this->repeat_ = false; |
|
| - | 41 | this->time_ = time; |
|
| - | 42 | } |
|
| 32 | 43 | ||
| 33 | Timer::~Timer() |
44 | Timer::~Timer() |
| 34 | { |
45 | { |
| 35 | this->Cancel(); |
46 | this->Cancel(); |
| 36 | } |
47 | } |
| 37 | 48 | ||
| 38 | void Timer::ConnectSlots(const SignalOnTimeout::slot_type& slot_on_timeout) |
49 | void Timer::ConnectSlots(const SignalOnTimeout::slot_type& slot_on_timeout) |
| 39 | { |
50 | { |
| 40 | this->signal_on_timeout_.connect(slot_on_timeout); |
51 | this->signal_on_timeout_.connect(slot_on_timeout); |
| 41 | } |
52 | } |
| 42 | 53 | ||
| 43 | void Timer::Start() |
54 | void Timer::Start() |
| - | 55 | { |
|
| - | 56 | if (this->timeout_ == 0) |
|
| - | 57 | { |
|
| - | 58 | boost::posix_time::ptime now = boost::posix_time::second_clock::local_time(); |
|
| - | 59 | ||
| - | 60 | this->instance_.expires_from_now(boost::posix_time::time_from_string(this->time_) - now); |
|
| - | 61 | } |
|
| - | 62 | else |
|
| 44 | { |
63 | { |
| 45 | this->instance_.expires_from_now(boost::posix_time::millisec(this->timeout_)); |
64 | this->instance_.expires_from_now(boost::posix_time::millisec(this->timeout_)); |
| - | 65 | } |
|
| 46 | 66 | ||
| 47 | this->instance_.async_wait(boost::bind(&Timer::TimeoutHandler, |
67 | this->instance_.async_wait(boost::bind(&Timer::TimeoutHandler, |
| 48 | this, |
68 | this, |
| 49 | boost::asio::placeholders::error)); |
69 | boost::asio::placeholders::error)); |
| 50 | } |
70 | } |