Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * blocked_timing.h - Blocked timing aspect for Fawkes 00004 * 00005 * Created: Thu Jan 11 16:52:28 2007 00006 * Copyright 2006-2007 Tim Niemueller [www.niemueller.de] 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. A runtime exception applies to 00014 * this software (see LICENSE.GPL_WRE file mentioned below for details). 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Library General Public License for more details. 00020 * 00021 * Read the full text in the LICENSE.GPL_WRE file in the doc directory. 00022 */ 00023 00024 #include <aspect/blocked_timing.h> 00025 #include <core/threading/thread.h> 00026 #include <core/exception.h> 00027 00028 namespace fawkes { 00029 #if 0 /* just to make Emacs auto-indent happy */ 00030 } 00031 #endif 00032 00033 /** @class BlockedTimingAspect <aspect/blocked_timing.h> 00034 * Thread aspect to use blocked timing. 00035 * The Fawkes main application provides basic means to synchronize all 00036 * running thread with respect to several given hooks (see WakeupHook). 00037 * Threads of a woken up at a particular point in time. The hooks basically 00038 * correspond to an extended sense - plan - act kind of loop. 00039 * Your thread must run in Thread::OPMODE_WAITFORWAKEUP mode, otherwise it 00040 * is not started. This is a requirement for having the BlockedTimingAspect. 00041 * 00042 * @see Thread::OpMode 00043 * @ingroup Aspects 00044 * @author Tim Niemueller 00045 */ 00046 00047 // Side note: Overriding Thread::run() can make our requirement useless, but 00048 // we believe in the best of the coder: laziness 00049 00050 /** Constructor. 00051 * This special constructor is needed to define the wakeup point. 00052 * @param wakeup_hook hook when this thread should be woken up 00053 */ 00054 BlockedTimingAspect::BlockedTimingAspect(WakeupHook wakeup_hook) 00055 { 00056 add_aspect("BlockedTimingAspect"); 00057 __wakeup_hook = wakeup_hook; 00058 } 00059 00060 00061 /** Virtual empty destructor. */ 00062 BlockedTimingAspect::~BlockedTimingAspect() 00063 { 00064 } 00065 00066 00067 /** Get the wakeup hook. 00068 * The wakeup hook defines when this thread should be woken up. This heavily 00069 * depends on the used main thread. 00070 * @return wakeup hook 00071 */ 00072 BlockedTimingAspect::WakeupHook 00073 BlockedTimingAspect::blockedTimingAspectHook() const 00074 { 00075 return __wakeup_hook; 00076 } 00077 00078 00079 /** Get string for wakeup hook. 00080 * @param hook wakeup hook to get string for 00081 * @return string representation of hook 00082 */ 00083 const char * 00084 BlockedTimingAspect::blocked_timing_hook_to_string(WakeupHook hook) 00085 { 00086 switch (hook) { 00087 case WAKEUP_HOOK_PRE_LOOP: return "WAKEUP_HOOK_PRE_LOOP"; 00088 case WAKEUP_HOOK_SENSOR_ACQUIRE: return "WAKEUP_HOOK_SENSOR_ACQUIRE"; 00089 case WAKEUP_HOOK_SENSOR_PREPARE: return "WAKEUP_HOOK_SENSOR_PREPARE"; 00090 case WAKEUP_HOOK_SENSOR_PROCESS: return "WAKEUP_HOOK_SENSOR_PROCESS"; 00091 case WAKEUP_HOOK_WORLDSTATE: return "WAKEUP_HOOK_WORLDSTATE"; 00092 case WAKEUP_HOOK_THINK: return "WAKEUP_HOOK_THINK"; 00093 case WAKEUP_HOOK_SKILL: return "WAKEUP_HOOK_SKILL"; 00094 case WAKEUP_HOOK_ACT: return "WAKEUP_HOOK_ACT"; 00095 case WAKEUP_HOOK_ACT_EXEC: return "WAKEUP_HOOK_ACT_EXEC"; 00096 case WAKEUP_HOOK_POST_LOOP: return "WAKEUP_HOOK_POST_LOOP"; 00097 default: throw Exception("Unknown blocked timing wakeup hook"); 00098 } 00099 } 00100 00101 } // end namespace fawkes