23 #include "continuous_exec_thread.h"
25 #include <core/exceptions/software.h>
26 #include <core/exceptions/system.h>
27 #include <core/threading/mutex.h>
28 #include <interfaces/SkillerDebugInterface.h>
29 #include <interfaces/SkillerInterface.h>
30 #include <logging/component.h>
31 #include <lua/context.h>
32 #include <lua/interface_importer.h>
43 l_read_interfaces(lua_State *L)
50 l_write_interfaces(lua_State *L)
68 :
Thread(
"LuaAgentContinuousExecutionThread",
Thread::OPMODE_WAITFORWAKEUP),
72 if (g_agent_thread != NULL) {
73 throw Exception(
"A global thread has already been set");
75 g_agent_thread =
this;
81 g_agent_thread = NULL;
89 LuaAgentContinuousExecutionThread::init_failure_cleanup()
105 "Really screwed up while finalizing, aborting cleanup. "
106 "Fawkes is no longer in a clean state. Restart!");
117 e.
append(
"Insufficient configuration for LuaAgent");
121 logger->
log_debug(
"LuaAgentContinuousExecutionThread",
"Agent: %s", cfg_agent_.c_str());
131 std::string reading_prefix =
"/luaagent/interfaces/" + cfg_agent_ +
"/reading/";
132 std::string writing_prefix =
"/luaagent/interfaces/" + cfg_agent_ +
"/writing/";
138 throw Exception(
"Skiller already has an exclusive controller");
145 if (cfg_watch_files_) {
147 lua_->
get_fam()->add_listener(
this);
164 lua_->
set_string(
"AGENT", cfg_agent_.c_str());
166 lua_->
set_usertype(
"logger", clog_,
"ComponentLogger",
"fawkes");
169 lua_->
set_usertype(
"tf", tf_listener,
"Transformer",
"fawkes::tf");
181 lua_thread_ =
new LuaThread(lua_);
184 ifi_mutex_ =
new Mutex();
186 init_failure_cleanup();
219 if (lua_thread_ && lua_thread_->failed()) {
258 lua_thread_->cancel();
265 lua_thread_->start();
273 :
Thread(
"LuaAgentContinuousExecutionThread::LuaThread",
Thread::OPMODE_CONTINUOUS)
282 LuaAgentContinuousExecutionThread::LuaThread::loop()
290 logger->
log_error(name(),
"execute() failed, exception follows");
LuaAgent Periodic Execution Thread.
LuaAgentContinuousExecutionThread()
Constructor.
void write_interfaces()
Update all reading interfaces.
virtual void fam_event(const char *filename, unsigned int mask)
Event has been raised.
virtual void init()
Initialize the thread.
virtual void finalize()
Finalize the thread.
virtual ~LuaAgentContinuousExecutionThread()
Destructor.
virtual void loop()
Code to execute in the thread.
void read_interfaces()
Update all reading interfaces.
BlackBoard * blackboard
This is the BlackBoard instance you can use to interact with the BlackBoard.
virtual Interface * open_for_reading(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for reading.
virtual void close(Interface *interface)=0
Close interface.
Thread aspect to use blocked timing.
Clock * clock
By means of this member access to the clock is given.
Configuration * config
This is the Configuration member used to access the configuration.
virtual bool get_bool(const char *path)=0
Get value from configuration which is of type bool.
virtual std::string get_string(const char *path)=0
Get value from configuration which is of type string.
Base class for exceptions in Fawkes.
void append(const char *format,...)
Append messages to the message list.
void read()
Read from BlackBoard into local copy.
bool has_writer() const
Check if there is a writer for the interface.
unsigned int msgq_enqueue(Message *message)
Enqueue message at end of queue.
virtual void log_debug(const char *component, const char *format,...)=0
Log debug message.
virtual void log_warn(const char *component, const char *format,...)=0
Log warning message.
virtual void log_error(const char *component, const char *format,...)=0
Log error message.
Logger * logger
This is the Logger member used to access the logger.
void setup_fam(bool auto_restart, bool conc_thread)
Setup file alteration monitor.
void restart()
Restart Lua.
void add_cpackage_dir(const char *path, bool prefix=false)
Add a Lua C package directory.
void set_start_script(const char *start_script)
Set start script.
RefPtr< FileAlterationMonitor > get_fam() const
Get file alteration monitor.
void set_usertype(const char *name, void *data, const char *type_name, const char *name_space=0)
Assign usertype to global variable.
void add_package_dir(const char *path, bool prefix=false)
Add a Lua package directory.
void set_cfunction(const char *name, lua_CFunction f)
Assign cfunction to global variable.
void do_string(const char *format,...)
Execute string.
void set_string(const char *name, const char *value)
Assign string to global variable.
void add_package(const char *package)
Add a default package.
void add_interface(std::string varname, Interface *interface)
Add a single interface to be pushed to the context.
void push_interfaces()
Push interfaces to Lua environment.
void read_from_buffer()
Update interfaces from internal buffers.
void read_to_buffer()
Read from all reading interfaces into a buffer.
void open_writing_interfaces(std::string &prefix)
Open interfaces for writing.
void write()
Write all writing interfaces.
void open_reading_interfaces(std::string &prefix)
Open interfaces for reading.
virtual void log_error(const char *component, const char *format,...)
Log error message.
Mutex mutual exclusion lock.
void lock()
Lock this mutex.
void unlock()
Unlock the mutex.
AcquireControlMessage Fawkes BlackBoard Interface Message.
ReleaseControlMessage Fawkes BlackBoard Interface Message.
SkillerInterface Fawkes BlackBoard Interface.
uint32_t exclusive_controller() const
Get exclusive_controller value.
virtual void add(ThreadList &tl)=0
Add multiple threads.
virtual void remove(ThreadList &tl)=0
Remove multiple threads.
ThreadCollector * thread_collector
Thread collector.
Thread class encapsulation of pthreads.
void set_prepfin_conc_loop(bool concurrent=true)
Set concurrent execution of prepare_finalize() and loop().
const char * name() const
Get name of thread.
Fawkes library namespace.