Subversion Repositories HomeAutomation

Rev

Rev 1595 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

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