Fawkes API  Fawkes Development Version
sensor_thread.cpp
1 
2 /***************************************************************************
3  * sensor_thread.cpp - Pan/tilt plugin sensor thread
4  *
5  * Created: Thu Jun 18 19:01:59 2009
6  * Copyright 2006-2009 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 
23 #include "sensor_thread.h"
24 #include "act_thread.h"
25 
26 using namespace fawkes;
27 
28 /** @class PanTiltSensorThread "sensor_thread.h"
29  * Katana sensor thread.
30  * This thread integrates into the Fawkes main loop at the SENSOR hook and
31  * triggers the act threads to retrieve and write new sensor data.
32  * @author Tim Niemueller
33  */
34 
35 /** Constructor. */
37  : Thread("PanTiltSensorThread", Thread::OPMODE_WAITFORWAKEUP),
38  BlockedTimingAspect(BlockedTimingAspect::WAKEUP_HOOK_SENSOR_ACQUIRE)
39 {
40 }
41 
42 
43 /** Add an act thread.
44  * @param act_thread to add
45  */
46 void
48 {
49  __act_threads.push_back(act_thread);
50 }
51 
52 
53 void
55 {
56  for (__ati = __act_threads.begin(); __ati != __act_threads.end(); ++__ati) {
57  try {
58  (*__ati)->update_sensor_values();
59  } catch (Exception &e) {
60  logger->log_warn(name(), "Act thread %s threw an exception when updating sensor values",
61  (*__ati)->name());
62  logger->log_warn(name(), e);
63  }
64  }
65 }
virtual void loop()
Code to execute in the thread.
Fawkes library namespace.
Thread class encapsulation of pthreads.
Definition: thread.h:42
Logger * logger
This is the Logger member used to access the logger.
Definition: logging.h:44
Thread aspect to use blocked timing.
Base class for exceptions in Fawkes.
Definition: exception.h:36
void add_act_thread(PanTiltActThread *act_thread)
Add an act thread.
const char * name() const
Get name of thread.
Definition: thread.h:95
virtual void log_warn(const char *component, const char *format,...)=0
Log warning message.
Pan/tilt act thread.
Definition: act_thread.h:36
PanTiltSensorThread()
Constructor.