Fawkes API  Fawkes Development Version
blocked_timing.h
1 
2 /***************************************************************************
3  * blocked_timing.h - Blocked timing aspect for Fawkes
4  *
5  * Created: Thu Jan 11 16:49:25 2007
6  * Copyright 2006-2010 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 #ifndef _ASPECT_BLOCKED_TIMING_H_
25 #define _ASPECT_BLOCKED_TIMING_H_
26 
27 #include <aspect/aspect.h>
28 #include <aspect/syncpoint.h>
29 #include <core/threading/thread_loop_listener.h>
30 
31 #include <map>
32 #include <string>
33 
34 namespace fawkes {
35 
36 /** @class BlockedTimingLoopListener
37  * Loop Listener of the BlockedTimingAspect.
38  * This loop listener immediately wakes up the thread after loop returned.
39  * The thread will then wait for the syncpoint of the next iteration.
40  * The BlockedTimingAspect cannot be derived from ThreadLoopListener because
41  * the SyncPointAspect is already derived from ThreadLoopListener and we need
42  * another listener. Therefore, use composition instead.
43  */
44 class BlockedTimingLoopListener : public ThreadLoopListener
45 {
46 public:
47  void post_loop(Thread *thread);
48 };
49 
51 {
52 public:
53  /** Type to define at which hook the thread is woken up.
54  * See FawkesMainThread for information when and in which order the hooks
55  * are called.
56  * @see FawkesMainThread::loop()
57  */
58  typedef enum {
59  WAKEUP_HOOK_PRE_LOOP, /**< before each loop */
60  WAKEUP_HOOK_SENSOR_ACQUIRE, /**< sensor acquisition thread,
61  * acquire data from sensor */
62  WAKEUP_HOOK_SENSOR_PREPARE, /**< sensor data preparation thread,
63  * convert acquired data to usable format */
64  WAKEUP_HOOK_SENSOR_PROCESS, /**< sensor data processing thread */
65  WAKEUP_HOOK_WORLDSTATE, /**< world state thread */
66  WAKEUP_HOOK_THINK, /**< think thread (agent) */
67  WAKEUP_HOOK_SKILL, /**< skill thread (skill module) */
68  WAKEUP_HOOK_ACT, /**< act thread (motor module etc.) */
69  WAKEUP_HOOK_ACT_EXEC, /**< act execution thread */
70  WAKEUP_HOOK_POST_LOOP /**< run after loop */
72 
75 
76  static const char *blocked_timing_hook_to_string(WakeupHook hook);
77 
78  static std::string blocked_timing_hook_to_start_syncpoint(WakeupHook hook);
79  static std::string blocked_timing_hook_to_end_syncpoint(WakeupHook hook);
80 
81  void init_BlockedTimingAspect(Thread *thread);
83 
85 
86  /** Translation from WakeupHooks to SyncPoints. Each WakeupHook corresponds to
87  * exactly one SyncPoint, e.g., WAKEUP_HOOK_PRE_LOOP becomes /preloop.
88  */
89  static const std::map<const WakeupHook, const std::string> hook_to_syncpoint;
90 
91 private:
92  WakeupHook wakeup_hook_;
93  BlockedTimingLoopListener *loop_listener_;
94 };
95 
96 } // end namespace fawkes
97 
98 #endif
fawkes::BlockedTimingAspect::WAKEUP_HOOK_WORLDSTATE
world state thread
Definition: blocked_timing.h:69
fawkes::BlockedTimingAspect::init_BlockedTimingAspect
void init_BlockedTimingAspect(Thread *thread)
Init BlockedTiming aspect.
Definition: blocked_timing.cpp:77
fawkes::BlockedTimingAspect::blocked_timing_hook_to_start_syncpoint
static std::string blocked_timing_hook_to_start_syncpoint(WakeupHook hook)
Get the syncpoint identifier corresponding to the start of a wakeup hook.
Definition: blocked_timing.cpp:159
fawkes::BlockedTimingAspect::WAKEUP_HOOK_SENSOR_PREPARE
sensor data preparation thread, convert acquired data to usable format
Definition: blocked_timing.h:66
fawkes::BlockedTimingAspect::finalize_BlockedTimingAspect
void finalize_BlockedTimingAspect(Thread *thread)
Finalize BlockedTiming aspect.
Definition: blocked_timing.cpp:88
fawkes::BlockedTimingAspect::hook_to_syncpoint
static const std::map< const WakeupHook, const std::string > hook_to_syncpoint
Translation from WakeupHooks to SyncPoints.
Definition: blocked_timing.h:93
fawkes::BlockedTimingAspect::WAKEUP_HOOK_THINK
think thread (agent)
Definition: blocked_timing.h:70
fawkes::BlockedTimingAspect
Definition: blocked_timing.h:54
fawkes::BlockedTimingAspect::WAKEUP_HOOK_SENSOR_PROCESS
sensor data processing thread
Definition: blocked_timing.h:68
fawkes::BlockedTimingAspect::WAKEUP_HOOK_ACT_EXEC
act execution thread
Definition: blocked_timing.h:73
fawkes
fawkes::BlockedTimingLoopListener
Definition: blocked_timing.h:48
fawkes::BlockedTimingAspect::WAKEUP_HOOK_PRE_LOOP
before each loop
Definition: blocked_timing.h:63
fawkes::BlockedTimingAspect::WAKEUP_HOOK_ACT
act thread (motor module etc.)
Definition: blocked_timing.h:72
fawkes::BlockedTimingAspect::blockedTimingAspectHook
WakeupHook blockedTimingAspectHook() const
Get the wakeup hook.
Definition: blocked_timing.cpp:99
fawkes::BlockedTimingAspect::WakeupHook
WakeupHook
Type to define at which hook the thread is woken up.
Definition: blocked_timing.h:62
fawkes::BlockedTimingLoopListener::post_loop
void post_loop(Thread *thread)
The post loop function of the BlockedTimingAspect This function is called right after the loop of the...
Definition: blocked_timing.cpp:173
fawkes::BlockedTimingAspect::BlockedTimingAspect
BlockedTimingAspect(WakeupHook wakeup_hook)
Constructor.
Definition: blocked_timing.cpp:56
fawkes::BlockedTimingAspect::blocked_timing_hook_to_end_syncpoint
static std::string blocked_timing_hook_to_end_syncpoint(WakeupHook hook)
Get the syncpoint identifier corresponding to the end of a wakeup hook.
Definition: blocked_timing.cpp:144
fawkes::Thread
Definition: thread.h:44
fawkes::BlockedTimingAspect::blocked_timing_hook_to_string
static const char * blocked_timing_hook_to_string(WakeupHook hook)
Get string for wakeup hook.
Definition: blocked_timing.cpp:109
fawkes::BlockedTimingAspect::WAKEUP_HOOK_POST_LOOP
run after loop
Definition: blocked_timing.h:74
fawkes::BlockedTimingAspect::WAKEUP_HOOK_SKILL
skill thread (skill module)
Definition: blocked_timing.h:71
fawkes::SyncPointAspect
Definition: syncpoint.h:38
fawkes::BlockedTimingAspect::WAKEUP_HOOK_SENSOR_ACQUIRE
sensor acquisition thread, acquire data from sensor
Definition: blocked_timing.h:64
fawkes::BlockedTimingAspect::~BlockedTimingAspect
virtual ~BlockedTimingAspect()
Virtual empty destructor.
Definition: blocked_timing.cpp:67