Fawkes API  Fawkes Development Version
blocked_timing.cpp
1 
2 /***************************************************************************
3  * blocked_timing.h - Blocked timing aspect for Fawkes
4  *
5  * Created: Thu Jan 11 16:52:28 2007
6  * Copyright 2006-2007 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. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #include <aspect/blocked_timing.h>
25 #include <core/threading/thread.h>
26 #include <core/exception.h>
27 
28 namespace fawkes {
29 #if 0 /* just to make Emacs auto-indent happy */
30 }
31 #endif
32 
33 /** @class BlockedTimingAspect <aspect/blocked_timing.h>
34  * Thread aspect to use blocked timing.
35  * The Fawkes main application provides basic means to synchronize all
36  * running thread with respect to several given hooks (see WakeupHook).
37  * Threads of a woken up at a particular point in time. The hooks basically
38  * correspond to an extended sense - plan - act kind of loop.
39  * Your thread must run in Thread::OPMODE_WAITFORWAKEUP mode, otherwise it
40  * is not started. This is a requirement for having the BlockedTimingAspect.
41  *
42  * @see Thread::OpMode
43  * @ingroup Aspects
44  * @author Tim Niemueller
45  */
46 
47 // Side note: Overriding Thread::run() can make our requirement useless, but
48 // we believe in the best of the coder: laziness
49 
50 /** Constructor.
51  * This special constructor is needed to define the wakeup point.
52  * @param wakeup_hook hook when this thread should be woken up
53  */
55 {
56  add_aspect("BlockedTimingAspect");
57  __wakeup_hook = wakeup_hook;
58 }
59 
60 
61 /** Virtual empty destructor. */
63 {
64 }
65 
66 
67 /** Get the wakeup hook.
68  * The wakeup hook defines when this thread should be woken up. This heavily
69  * depends on the used main thread.
70  * @return wakeup hook
71  */
74 {
75  return __wakeup_hook;
76 }
77 
78 
79 /** Get string for wakeup hook.
80  * @param hook wakeup hook to get string for
81  * @return string representation of hook
82  */
83 const char *
85 {
86  switch (hook) {
87  case WAKEUP_HOOK_PRE_LOOP: return "WAKEUP_HOOK_PRE_LOOP";
88  case WAKEUP_HOOK_SENSOR_ACQUIRE: return "WAKEUP_HOOK_SENSOR_ACQUIRE";
89  case WAKEUP_HOOK_SENSOR_PREPARE: return "WAKEUP_HOOK_SENSOR_PREPARE";
90  case WAKEUP_HOOK_SENSOR_PROCESS: return "WAKEUP_HOOK_SENSOR_PROCESS";
91  case WAKEUP_HOOK_WORLDSTATE: return "WAKEUP_HOOK_WORLDSTATE";
92  case WAKEUP_HOOK_THINK: return "WAKEUP_HOOK_THINK";
93  case WAKEUP_HOOK_SKILL: return "WAKEUP_HOOK_SKILL";
94  case WAKEUP_HOOK_ACT: return "WAKEUP_HOOK_ACT";
95  case WAKEUP_HOOK_ACT_EXEC: return "WAKEUP_HOOK_ACT_EXEC";
96  case WAKEUP_HOOK_POST_LOOP: return "WAKEUP_HOOK_POST_LOOP";
97  default: throw Exception("Unknown blocked timing wakeup hook");
98  }
99 }
100 
101 } // end namespace fawkes
act thread (motor module etc.)
sensor data preparation thread, convert acquired data to usable format
Fawkes library namespace.
void add_aspect(const char *name)
Add an aspect to a thread.
Definition: aspect.cpp:52
WakeupHook
Type to define at which hook the thread is woken up.
Base class for exceptions in Fawkes.
Definition: exception.h:36
static const char * blocked_timing_hook_to_string(WakeupHook hook)
Get string for wakeup hook.
virtual ~BlockedTimingAspect()
Virtual empty destructor.
BlockedTimingAspect(WakeupHook wakeup_hook)
Constructor.
WakeupHook blockedTimingAspectHook() const
Get the wakeup hook.
sensor acquisition thread, acquire data from sensor