Subversion Repositories HomeAutomation

Rev

Rev 1595 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
1593 runge 1
/*
2
 *
3
 *    Copyright (C) 2010  Mattias Runge
4
 *
5
 *    This program is free software; you can redistribute it and/or modify
6
 *    it under the terms of the GNU General Public License as published by
7
 *    the Free Software Foundation; either version 2 of the License, or
8
 *    (at your option) any later version.
9
 *
10
 *    This program is distributed in the hope that it will be useful,
11
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *    GNU General Public License for more details.
14
 *
15
 *    You should have received a copy of the GNU General Public License along
16
 *    with this program; if not, write to the Free Software Foundation, Inc.,
17
 *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
 *
19
 */
20
 
21
#ifndef TIMER_TIMER_H
22
#define TIMER_TIMER_H
23
 
24
#include <boost/asio.hpp>
25
#include <boost/signals2.hpp>
26
#include <boost/shared_ptr.hpp>
27
 
1595 runge 28
#include "types.h"
1593 runge 29
 
30
namespace atom {
31
namespace timer {
32
 
33
class Timer
34
{
35
public:
36
    typedef boost::shared_ptr<Timer> Pointer;
37
 
38
    typedef boost::signals2::signal<void(TimerId)> SignalOnTimeout;
39
 
40
    Timer(boost::asio::io_service& io_service, TimerId id, unsigned int timeout, bool repeat);
1646 runge 41
    Timer(boost::asio::io_service& io_service, TimerId id, std::string time);
1593 runge 42
    virtual ~Timer();
43
 
44
    void ConnectSlots(const SignalOnTimeout::slot_type& slot_on_timeout);
45
 
46
    TimerId GetId();
47
    bool GetRepeat();
48
    void Start();
49
    void Cancel();
50
 
51
private:
52
    boost::asio::deadline_timer instance_;
53
    TimerId id_;
1646 runge 54
    std::string time_;
1593 runge 55
    unsigned int timeout_;
56
    bool repeat_;
57
 
58
    SignalOnTimeout signal_on_timeout_;
59
 
60
    void TimeoutHandler(const boost::system::error_code& error);
61
};
62
 
63
}; // namespace timer
64
}; // namespace atom
65
 
66
#endif // TIMER_TIMER_H