Fawkes API  Fawkes Development Version
continuous_exec_thread.h
1 
2 /***************************************************************************
3  * continuous_exec_thread.h - Fawkes LuaAgent: Continuous Execution Thread
4  *
5  * Created: Thu May 26 11:49:17 2011
6  * Copyright 2006-2011 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.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 
23 #ifndef __PLUGINS_LUAAGENT_CONTINUOUS_EXEC_THREAD_H_
24 #define __PLUGINS_LUAAGENT_CONTINUOUS_EXEC_THREAD_H_
25 
26 #include <core/threading/thread.h>
27 #include <aspect/blocked_timing.h>
28 #include <aspect/logging.h>
29 #include <aspect/configurable.h>
30 #include <aspect/clock.h>
31 #include <aspect/blackboard.h>
32 #include <aspect/thread_producer.h>
33 #ifdef HAVE_TF
34 #include <aspect/tf.h>
35 #endif
36 #include <utils/system/fam.h>
37 
38 #include <string>
39 #include <cstdlib>
40 
41 namespace fawkes {
42  class ComponentLogger;
43  class Mutex;
44  class LuaContext;
45  class LuaInterfaceImporter;
46  class Interface;
47  class SkillerInterface;
48  class SkillerDebugInterface;
49 }
50 
52 : public fawkes::Thread,
54  public fawkes::LoggingAspect,
57  public fawkes::ClockAspect,
59 #ifdef HAVE_TF
61 #endif
62  public fawkes::FamListener
63 {
64  public:
67 
68  virtual void init();
69  virtual void loop();
70  virtual void finalize();
71 
72  virtual void fam_event(const char *filename, unsigned int mask);
73 
74  void read_interfaces();
75  void write_interfaces();
76 
77  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
78  protected: virtual void run() { Thread::run(); }
79 
80  private: /* methods */
81  void init_failure_cleanup();
82 
83  class LuaThread
84  : public Thread,
86  {
87  public:
88  LuaThread(fawkes::LuaContext *lua);
89  virtual void loop();
90 
91  /** Check if LuaThread failed.
92  * @return true if an error occured, false otherwise. */
93  bool failed() { return __failed; }
94  private:
95  fawkes::LuaContext *__lua;
96  bool __failed;
97  };
98 
99  private: /* members */
100  fawkes::ComponentLogger *__clog;
101 
102  // config values
103  std::string __cfg_agent;
104  bool __cfg_watch_files;
105 
106  fawkes::SkillerInterface *__skiller_if;
107 
108  fawkes::LuaContext *__lua;
109  fawkes::LuaInterfaceImporter *__lua_ifi;
110 
111  fawkes::Mutex *__ifi_mutex;
112  LuaThread *__lua_thread;
113 };
114 
115 #endif
Thread aspect to access to BlackBoard.
Definition: blackboard.h:34
Thread aspect that allows to obtain the current time from the clock.
Definition: clock.h:36
Fawkes library namespace.
virtual void run()
Code to execute in the thread.
Definition: thread.cpp:939
virtual void run()
Stub to see name in backtrace for easier debugging.
Thread class encapsulation of pthreads.
Definition: thread.h:42
Thread aspect to access the transform system.
Definition: tf.h:42
LuaAgent Periodic Execution Thread.
Thread aspect to use blocked timing.
Lua interface importer.
Lua C++ wrapper.
Definition: context.h:47
File Alteration Monitor Listener.
Definition: fam.h:35
Thread aspect to log output.
Definition: logging.h:35
Component logger.
Definition: component.h:35
Aspect for thread producing threads.
Thread aspect to access configuration data.
Definition: configurable.h:35
SkillerInterface Fawkes BlackBoard Interface.
Mutex mutual exclusion lock.
Definition: mutex.h:32