OpenZWave Library
1.6.1392
cpp
src
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>
33
using
std::bind;
34
using
std::function;
35
#else
36
#include <tr1/functional>
37
using
std::tr1::bind;
38
using
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
46
namespace
OpenZWave
47
{
48
class
Driver;
49
namespace
Internal
50
{
51
class
Timer;
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
Internal::Platform::TimeStamp
timestamp
;
79
TimerCallback
callback
;
80
uint32
id
;
81
};
82
88
static
void
TimerThreadEntryPoint(
Internal::Platform::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(
Internal::Platform::Event
* _exitEvent);
112
114
list<TimerEventEntry *> m_timerEventList;
115
116
Internal::Platform::Event
* m_timerEvent;
// Event to signal new timed action requested
117
Internal::Platform::Mutex
* m_timerMutex;
// Serialize access to class members
118
int32
m_timerTimeout;
// Time in milliseconds to wait until next event
119
};
120
127
class
OPENZWAVE_EXPORT
Timer
128
{
129
public
:
134
Timer
(
Driver
*_driver);
139
Timer
();
143
~
Timer
();
150
TimerThread::TimerEventEntry
* TimerSetEvent(
int32
_milliseconds,
TimerThread::TimerCallback
_callback,
uint32
id
);
154
void
TimerDelEvents();
159
void
TimerDelEvent(
TimerThread::TimerEventEntry
*te);
164
void
TimerDelEvent(
uint32
id
);
165
170
void
SetDriver(
Driver
*_driver);
175
void
TimerFireEvent(
TimerThread::TimerEventEntry
*te);
176
private
:
177
Driver
* m_driver;
178
list<TimerThread::TimerEventEntry *> m_timerEventList;
179
180
};
181
}
// namespace Internal
182
}
// namespace OpenZWave
183
184
#endif // _TIMERTHREAD_H_
uint32
unsigned int uint32
Definition:
Defs.h:91
OpenZWave::Internal::TimerThread::TimerCallback
function< void(uint32)> TimerCallback
Definition:
TimerThread.h:63
OpenZWave::Internal::TimerThread::TimerEventEntry
Definition:
TimerThread.h:76
OpenZWave::Internal::TimerThread::TimerEventEntry::id
uint32 id
Definition:
TimerThread.h:80
OpenZWave::Internal::Platform::TimeStamp
Implements a platform-independent TimeStamp.
Definition:
TimeStamp.h:45
OpenZWave::Internal::Platform::Event
Platform-independent definition of event objects.
Definition:
Event.h:45
int32
signed int int32
Definition:
Defs.h:90
OpenZWave::Internal::TimerThread::TimerEventEntry::callback
TimerCallback callback
Definition:
TimerThread.h:79
OpenZWave::Internal::TimerThread::TimerEventEntry::timestamp
Internal::Platform::TimeStamp timestamp
Definition:
TimerThread.h:78
OpenZWave::Internal::Platform::Mutex
Implements a platform-independent mutex–for serializing access to a shared resource.
Definition:
Mutex.h:45
Event.h
OpenZWave::Internal::Timer
Timer SubClass for automatically registering/unregistering Timer Callbacks if the instance goes out o...
Definition:
TimerThread.h:128
OpenZWave::Internal::TimerThread::TimerEventEntry::instance
Timer * instance
Definition:
TimerThread.h:77
Mutex.h
OPENZWAVE_EXPORT
#define OPENZWAVE_EXPORT
Definition:
Defs.h:52
OpenZWave::Driver
The Driver class handles communication between OpenZWave and a device attached via a serial port (typ...
Definition:
Driver.h:85
OpenZWave::Internal::TimerThread
The TimerThread class makes it possible to schedule events to happen at a certain time in the future.
Definition:
TimerThread.h:56
Defs.h
TimeStamp.h
OpenZWave
Definition:
Bitfield.cpp:31
Generated on Thu Jul 30 2020 00:00:00 for OpenZWave Library by
1.8.20