Subversion Repositories HomeAutomation

Rev

Rev 1646 | 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_MANAGER_H
22
#define TIMER_MANAGER_H
23
 
24
#include <boost/signals2.hpp>
25
#include <boost/shared_ptr.hpp>
26
 
1601 runge 27
#include "common/IoService.h"
1768 runge 28
#include "logging/Logger.h"
1601 runge 29
 
1595 runge 30
#include "types.h"
1593 runge 31
#include "Timer.h"
32
 
33
namespace atom {
34
namespace timer {
35
 
1601 runge 36
class Manager : public virtual common::IoService
1593 runge 37
{
38
public:
39
    typedef boost::shared_ptr<Manager> Pointer;
40
 
1601 runge 41
    typedef boost::signals2::signal<void(TimerId, bool)> SignalOnTimeout;
1593 runge 42
 
43
    virtual ~Manager();
44
 
45
    static Pointer Instance();
1599 runge 46
    static void Create();
1593 runge 47
    static void Delete();
48
 
49
    void ConnectSlots(const SignalOnTimeout::slot_type& slot_on_timeout);
1646 runge 50
 
51
    TimerId SetAlarm(std::string time);
52
    TimerId SetTimer(unsigned int timeout, bool repeat);
1593 runge 53
    void Cancel(TimerId id);
54
 
55
private:
56
    typedef std::map<TimerId, Timer::Pointer> TimerList;
57
 
58
    static Pointer instance_;
59
 
60
    TimerList timers_;
61
    boost::mutex mutex_timers_;
62
 
63
    SignalOnTimeout signal_on_timeout_;
64
 
1768 runge 65
    logging::Logger LOG;
66
 
1593 runge 67
    Manager();
68
 
69
    TimerId GetFreeId();
70
 
71
    void CancelHandler(TimerId id);
72
 
73
    void SlotOnTimeout(TimerId id);
74
};
75
 
76
}; // namespace timer
77
}; // namespace atom
78
 
79
#endif // TIMER_MANAGER_H