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  */
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 */
71  } WakeupHook;
72 
73  BlockedTimingAspect(WakeupHook wakeup_hook);
74  virtual ~BlockedTimingAspect();
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
act thread (motor module etc.)
void finalize_BlockedTimingAspect(Thread *thread)
Finalize BlockedTiming aspect.
static const std::map< const WakeupHook, const std::string > hook_to_syncpoint
Translation from WakeupHooks to SyncPoints.
sensor data preparation thread, convert acquired data to usable format
Fawkes library namespace.
void init_BlockedTimingAspect(Thread *thread)
Init BlockedTiming aspect.
Thread class encapsulation of pthreads.
Definition: thread.h:45
static std::string blocked_timing_hook_to_start_syncpoint(WakeupHook hook)
Get the syncpoint identifier corresponding to the start of a wakeup hook.
Thread aspect to acces to SyncPoints Give this aspect to your thread to manage SyncPoints,...
Definition: syncpoint.h:34
Thread aspect to use blocked timing.
static std::string blocked_timing_hook_to_end_syncpoint(WakeupHook hook)
Get the syncpoint identifier corresponding to the end of a wakeup hook.
WakeupHook
Type to define at which hook the thread is woken up.
void post_loop(Thread *thread)
The post loop function of the BlockedTimingAspect This function is called right after the loop of the...
static const char * blocked_timing_hook_to_string(WakeupHook hook)
Get string for wakeup hook.
Loop Listener of the BlockedTimingAspect.
Thread loop listener interface.
virtual ~BlockedTimingAspect()
Virtual empty destructor.
BlockedTimingAspect(WakeupHook wakeup_hook)
Constructor.
WakeupHook blockedTimingAspectHook() const
Get the wakeup hook.
sensor acquisition thread, acquire data from sensor