OpenZWave Library  1.6.962
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;
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 
76  {
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 
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_
Timer * instance
Definition: TimerThread.h:77
Definition: Bitfield.cpp:30
#define OPENZWAVE_EXPORT
Definition: Defs.h:52
Platform-independent definition of event objects.
Definition: Event.h:44
Internal::Platform::TimeStamp timestamp
Definition: TimerThread.h:78
The Driver class handles communication between OpenZWave and a device attached via a serial port (typ...
Definition: Driver.h:84
signed int int32
Definition: Defs.h:90
unsigned int uint32
Definition: Defs.h:91
Timer SubClass for automatically registering/unregistering Timer Callbacks if the instance goes out o...
Definition: TimerThread.h:127
Implements a platform-independent TimeStamp.
Definition: TimeStamp.h:44
uint32 id
Definition: TimerThread.h:80
Implements a platform-independent mutex–for serializing access to a shared resource.
Definition: Mutex.h:44
TimerCallback callback
Definition: TimerThread.h:79
function< void(uint32)> TimerCallback
Definition: TimerThread.h:63
The TimerThread class makes it possible to schedule events to happen at a certain time in the future.
Definition: TimerThread.h:55