Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * continuous_exec_thread.h - Fawkes LuaAgent: Continuous Execution Thread 00004 * 00005 * Created: Thu May 26 11:49:17 2011 00006 * Copyright 2006-2011 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. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU Library General Public License for more details. 00019 * 00020 * Read the full text in the LICENSE.GPL file in the doc directory. 00021 */ 00022 00023 #ifndef __PLUGINS_LUAAGENT_CONTINUOUS_EXEC_THREAD_H_ 00024 #define __PLUGINS_LUAAGENT_CONTINUOUS_EXEC_THREAD_H_ 00025 00026 #include <core/threading/thread.h> 00027 #include <aspect/blocked_timing.h> 00028 #include <aspect/logging.h> 00029 #include <aspect/configurable.h> 00030 #include <aspect/clock.h> 00031 #include <aspect/blackboard.h> 00032 #include <aspect/thread_producer.h> 00033 #ifdef HAVE_TF 00034 #include <aspect/tf.h> 00035 #endif 00036 #include <utils/system/fam.h> 00037 00038 #include <string> 00039 #include <cstdlib> 00040 00041 namespace fawkes { 00042 class ComponentLogger; 00043 class Mutex; 00044 class LuaContext; 00045 class LuaInterfaceImporter; 00046 class Interface; 00047 class SkillerInterface; 00048 class SkillerDebugInterface; 00049 } 00050 00051 class LuaAgentContinuousExecutionThread 00052 : public fawkes::Thread, 00053 public fawkes::BlockedTimingAspect, 00054 public fawkes::LoggingAspect, 00055 public fawkes::BlackBoardAspect, 00056 public fawkes::ConfigurableAspect, 00057 public fawkes::ClockAspect, 00058 public fawkes::ThreadProducerAspect, 00059 #ifdef HAVE_TF 00060 public fawkes::TransformAspect, 00061 #endif 00062 public fawkes::FamListener 00063 { 00064 public: 00065 LuaAgentContinuousExecutionThread(); 00066 virtual ~LuaAgentContinuousExecutionThread(); 00067 00068 virtual void init(); 00069 virtual void loop(); 00070 virtual void finalize(); 00071 00072 virtual void fam_event(const char *filename, unsigned int mask); 00073 00074 void read_interfaces(); 00075 void write_interfaces(); 00076 00077 /** Stub to see name in backtrace for easier debugging. @see Thread::run() */ 00078 protected: virtual void run() { Thread::run(); } 00079 00080 private: /* methods */ 00081 void init_failure_cleanup(); 00082 00083 class LuaThread 00084 : public Thread, 00085 public fawkes::LoggingAspect 00086 { 00087 public: 00088 LuaThread(fawkes::LuaContext *lua); 00089 virtual void loop(); 00090 00091 /** Check if LuaThread failed. 00092 * @return true if an error occured, false otherwise. */ 00093 bool failed() { return __failed; } 00094 private: 00095 fawkes::LuaContext *__lua; 00096 bool __failed; 00097 }; 00098 00099 private: /* members */ 00100 fawkes::ComponentLogger *__clog; 00101 00102 // config values 00103 std::string __cfg_agent; 00104 bool __cfg_watch_files; 00105 00106 fawkes::SkillerInterface *__skiller_if; 00107 00108 fawkes::LuaContext *__lua; 00109 fawkes::LuaInterfaceImporter *__lua_ifi; 00110 00111 fawkes::Mutex *__ifi_mutex; 00112 LuaThread *__lua_thread; 00113 }; 00114 00115 #endif