OpenZWave Library: TimerThread.h Source File

| OpenZWave Library 1.6.0

TimerThread.h
Go to the documentation of this file.
1//-----------------------------------------------------------------------------
2//
3// TimerThread.h
4//
5// Timer for scheduling future events
6//
7// Copyright (c) 2017 h3ctrl <h3ctrl@gmail.com>
8//
9// SOFTWARE NOTICE AND LICENSE
10//
11// This file is part of OpenZWave.
12//
13// OpenZWave is free software: you can redistribute it and/or modify
14// it under the terms of the GNU Lesser General Public License as published
15// by the Free Software Foundation, either version 3 of the License,
16// or (at your option) any later version.
17//
18// OpenZWave is distributed in the hope that it will be useful,
19// but WITHOUT ANY WARRANTY; without even the implied warranty of
20// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21// GNU Lesser General Public License for more details.
22//
23// You should have received a copy of the GNU Lesser General Public License
24// along with OpenZWave. If not, see <http://www.gnu.org/licenses/>.
25//
26//-----------------------------------------------------------------------------
27
28#ifndef _TIMERTHREAD_H_
29#define _TIMERTHREAD_H_
30
31#if __cplusplus >= 201103L || __APPLE__ || _MSC_VER
32#include <functional>
33using std::bind;
34using std::function;
35#else
36#include <tr1/functional>
37using std::tr1::bind;
38using std::tr1::function;
39#endif
40
41#include "Defs.h"
42#include "platform/Event.h"
43#include "platform/Mutex.h"
44#include "platform/TimeStamp.h"
45
46namespace OpenZWave
47{
48 class Driver;
49 class Thread;
50 class Timer;
51
55 class OPENZWAVE_EXPORT TimerThread
56 {
57 friend class Timer;
58 //-----------------------------------------------------------------------------
59 // Timer based actions
60 //-----------------------------------------------------------------------------
61 public:
63 typedef function<void(uint32)> TimerCallback;
64
68 TimerThread( Driver *_driver );
69
73 ~TimerThread();
74
75 struct TimerEventEntry
76 {
77 Timer *instance;
78 TimeStamp timestamp;
79 TimerCallback callback;
80 uint32 id;
81 };
82
88 static void TimerThreadEntryPoint( Event* _exitEvent, void* _context );
89
90 private:
91 //Driver* m_driver;
92
99 TimerEventEntry* TimerSetEvent( int32 _milliseconds, TimerCallback _callback, Timer *_instance, uint32 id );
100
105 void TimerDelEvent(TimerEventEntry *);
106
111 void TimerThreadProc( Event* _exitEvent );
112
113
115 list<TimerEventEntry *> m_timerEventList;
116
117 Event* m_timerEvent; // Event to signal new timed action requested
118 Mutex* m_timerMutex; // Serialize access to class members
119 int32 m_timerTimeout; // Time in milliseconds to wait until next event
120 };
121
128 class OPENZWAVE_EXPORT Timer
129 {
130 public:
135 Timer( Driver *_driver );
140 Timer();
144 ~Timer();
151 TimerThread::TimerEventEntry* TimerSetEvent( int32 _milliseconds, TimerThread::TimerCallback _callback, uint32 id );
155 void TimerDelEvents();
160 void TimerDelEvent(TimerThread::TimerEventEntry *te);
165 void TimerDelEvent(uint32 id);
166
171 void SetDriver(Driver *_driver);
176 void TimerFireEvent(TimerThread::TimerEventEntry *te);
177 private:
178 Driver* m_driver;
179 list<TimerThread::TimerEventEntry *> m_timerEventList;
180
181
182 };
183} // namespace OpenZWave
184
185#endif // _TIMERTHREAD_H_
Defs.h
uint32
unsigned int uint32
Definition: Defs.h:95
int32
signed int int32
Definition: Defs.h:94
OPENZWAVE_EXPORT
#define OPENZWAVE_EXPORT
Definition: Defs.h:51
Event.h
Mutex.h
TimeStamp.h
OpenZWave::Driver
The Driver class handles communication between OpenZWave and a device attached via a serial port (typ...
Definition: Driver.h:65
OpenZWave::Event
Platform-independent definition of event objects.
Definition: Event.h:41
OpenZWave::Mutex
Implements a platform-independent mutex–for serializing access to a shared resource.
Definition: Mutex.h:41
OpenZWave::TimeStamp
Implements a platform-independent TimeStamp.
Definition: TimeStamp.h:41
OpenZWave::TimerThread
The TimerThread class makes it possible to schedule events to happen at a certain time in the future.
Definition: TimerThread.h:56
OpenZWave::TimerThread::TimerCallback
function< void(uint32)> TimerCallback
Definition: TimerThread.h:63
OpenZWave::Timer
Timer SubClass for automatically registering/unregistering Timer Callbacks if the instance goes out o...
Definition: TimerThread.h:129
OpenZWave
Definition: Bitfield.h:35
OpenZWave::TimerThread::TimerEventEntry
Definition: TimerThread.h:76
OpenZWave::TimerThread::TimerEventEntry::id
uint32 id
Definition: TimerThread.h:80
OpenZWave::TimerThread::TimerEventEntry::callback
TimerCallback callback
Definition: TimerThread.h:79
OpenZWave::TimerThread::TimerEventEntry::timestamp
TimeStamp timestamp
Definition: TimerThread.h:78
OpenZWave::TimerThread::TimerEventEntry::instance
Timer * instance
Definition: TimerThread.h:77