Open Lighting Architecture  0.10.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
PeriodicThread.h
1 /*
2  * This library is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU Lesser General Public
4  * License as published by the Free Software Foundation; either
5  * version 2.1 of the License, or (at your option) any later version.
6  *
7  * This library is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10  * Lesser General Public License for more details.
11  *
12  * You should have received a copy of the GNU Lesser General Public
13  * License along with this library; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15  *
16  * PeriodicThread.h
17  * A thread which executes a Callback periodically.
18  * Copyright (C) 2015 Simon Newton
19  */
20 
21 #ifndef INCLUDE_OLA_THREAD_PERIODICTHREAD_H_
22 #define INCLUDE_OLA_THREAD_PERIODICTHREAD_H_
23 
24 #include <ola/Callback.h>
25 #include <ola/base/Macro.h>
26 #include <ola/thread/Thread.h>
27 #include <ola/Clock.h>
28 
29 #include <string>
30 
31 namespace ola {
32 namespace thread {
33 
37 class PeriodicThread : private Thread {
38  public:
45 
55  explicit PeriodicThread(const TimeInterval &delay,
56  PeriodicCallback *callback,
57  const Options &options = Options());
58 
64  void Stop();
65 
66  protected:
67  void *Run();
68 
69  private:
70  TimeInterval m_delay;
71  PeriodicCallback *m_callback;
72 
73  bool m_terminate;
74  ola::thread::Mutex m_mutex;
76 
77  DISALLOW_COPY_AND_ASSIGN(PeriodicThread);
78 };
79 } // namespace thread
80 } // namespace ola
81 #endif // INCLUDE_OLA_THREAD_PERIODICTHREAD_H_
Definition: Clock.h:118
void * Run()
The entry point for the new thread.
Definition: PeriodicThread.cpp:52
Callback0< bool > PeriodicCallback
The callback to run.
Definition: PeriodicThread.h:44
void Stop()
Stop the PeriodicThread.
Definition: PeriodicThread.cpp:43
A 0 argument callback which can be called multiple times.
Definition: Callback.h:129
Definition: Thread.h:52
Thread options.
Definition: Thread.h:60
Helper macros.
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
A thread which executes a Callback.
Definition: PeriodicThread.h:37
PeriodicThread(const TimeInterval &delay, PeriodicCallback *callback, const Options &options=Options())
Definition: PeriodicThread.cpp:31
Definition: Mutex.h:35
Definition: Mutex.h:75