Subversion Repositories HomeAutomation

Rev

Rev 1646 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1646 Rev 1768
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
 
-
 
28
#include "logging/Logger.h"
27
 
29
 
28
#include "types.h"
30
#include "types.h"
29
 
31
 
30
namespace atom {
32
namespace atom {
31
namespace timer {
33
namespace timer {
32
 
34
 
33
class Timer
35
class Timer
34
{
36
{
35
public:
37
public:
36
    typedef boost::shared_ptr<Timer> Pointer;
38
    typedef boost::shared_ptr<Timer> Pointer;
37
   
39
   
38
    typedef boost::signals2::signal<void(TimerId)> SignalOnTimeout;
40
    typedef boost::signals2::signal<void(TimerId)> SignalOnTimeout;
39
   
41
   
40
    Timer(boost::asio::io_service& io_service, TimerId id, unsigned int timeout, bool repeat);
42
    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);
43
    Timer(boost::asio::io_service& io_service, TimerId id, std::string time);
42
    virtual ~Timer();
44
    virtual ~Timer();
43
 
45
 
44
    void ConnectSlots(const SignalOnTimeout::slot_type& slot_on_timeout);
46
    void ConnectSlots(const SignalOnTimeout::slot_type& slot_on_timeout);
45
   
47
   
46
    TimerId GetId();
48
    TimerId GetId();
47
    bool GetRepeat();
49
    bool GetRepeat();
48
    void Start();
50
    void Start();
49
    void Cancel();
51
    void Cancel();
50
   
52
   
51
private:
53
private:
52
    boost::asio::deadline_timer instance_;
54
    boost::asio::deadline_timer instance_;
53
    TimerId id_;
55
    TimerId id_;
54
    std::string time_;
56
    std::string time_;
55
    unsigned int timeout_;
57
    unsigned int timeout_;
56
    bool repeat_;
58
    bool repeat_;
-
 
59
   
-
 
60
    logging::Logger LOG;
57
   
61
   
58
    SignalOnTimeout signal_on_timeout_;
62
    SignalOnTimeout signal_on_timeout_;
59
   
63
   
60
    void TimeoutHandler(const boost::system::error_code& error);
64
    void TimeoutHandler(const boost::system::error_code& error);
61
};
65
};
62
 
66
 
63
}; // namespace timer
67
}; // namespace timer
64
}; // namespace atom
68
}; // namespace atom
65
 
69
 
66
#endif // TIMER_TIMER_H
70
#endif // TIMER_TIMER_H
67
 
71