Fawkes API Fawkes Development Version
timer_thread.h
1
2/***************************************************************************
3 * timer_thread.h - timer thread
4 *
5 * Created: Mon Aug 13 16:17:47 2018
6 * Copyright 2006-2018 Tim Niemueller [www.niemueller.de]
7 ****************************************************************************/
8
9/* This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Library General Public License for more details.
18 *
19 * Read the full text in the LICENSE.GPL file in the doc directory.
20 */
21
22#ifndef __PLUGINS_PLEXIL_TIMER_THREAD_H_
23#define __PLUGINS_PLEXIL_TIMER_THREAD_H_
24
25#include <aspect/clock.h>
26#include <core/threading/thread.h>
27
29{
30public:
32 virtual ~PlexilTimerThread();
33
34 virtual void loop();
35
36 /** Callback listener pure virtual class. */
38 {
39 public:
40 /** Called for timer events. */
41 virtual void timer_event() = 0;
42 };
43
44 void start_timer(CallbackListener *listener, const fawkes::Time &wait_until);
45 void abort_timer();
46
47 /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
48protected:
49 virtual void
51 {
52 Thread::run();
53 }
54
55private:
56 fawkes::Mutex * mutex_;
57 fawkes::WaitCondition *waitcond_;
58
59 CallbackListener *listener_;
60 fawkes::Time queued_wait_until_;
61 bool aborted_;
62};
63
64#endif
Callback listener pure virtual class.
Definition: timer_thread.h:38
virtual void timer_event()=0
Called for timer events.
Timer support class.
Definition: timer_thread.h:29
void start_timer(CallbackListener *listener, const fawkes::Time &wait_until)
Start timer non-blocking.
virtual void run()
Stub to see name in backtrace for easier debugging.
Definition: timer_thread.h:50
void abort_timer()
Abort a currently running timer.
virtual void loop()
Code to execute in the thread.
PlexilTimerThread()
Constructor.
virtual ~PlexilTimerThread()
Empty destructor.
Mutex mutual exclusion lock.
Definition: mutex.h:33
Thread class encapsulation of pthreads.
Definition: thread.h:46
A class for handling time.
Definition: time.h:93
Wait until a given condition holds.