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