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 <logging/component.h>
30 #include <lua/context.h>
31 #include <lua/interface_importer.h>
33 #include <interfaces/SkillerInterface.h>
34 #include <interfaces/SkillerDebugInterface.h>
40 using namespace fawkes;
45 static int l_read_interfaces(lua_State *L)
51 static int l_write_interfaces(lua_State *L)
70 :
Thread(
"LuaAgentContinuousExecutionThread",
Thread::OPMODE_WAITFORWAKEUP),
74 if (g_agent_thread != NULL) {
75 throw Exception(
"A global thread has already been set");
77 g_agent_thread =
this;
84 g_agent_thread = NULL;
93 LuaAgentContinuousExecutionThread::init_failure_cleanup()
109 "Fawkes is no longer in a clean state. Restart!");
121 e.
append(
"Insufficient configuration for LuaAgent");
125 logger->
log_debug(
"LuaAgentContinuousExecutionThread",
"Agent: %s", __cfg_agent.c_str());
135 std::string reading_prefix =
"/luaagent/interfaces/" + __cfg_agent +
"/reading/";
136 std::string writing_prefix =
"/luaagent/interfaces/" + __cfg_agent +
"/writing/";
140 __skiller_if->
read();
142 throw Exception(
"Skiller already has an exclusive controller");
149 if (__cfg_watch_files) {
169 __lua->
set_string(
"AGENT", __cfg_agent.c_str());
171 __lua->
set_usertype(
"logger", __clog,
"ComponentLogger",
"fawkes");
174 __lua->
set_usertype(
"tf", tf_listener,
"Transformer",
"fawkes::tf");
177 __lua->
set_cfunction(
"write_interfaces", l_write_interfaces);
186 __lua_thread =
new LuaThread(__lua);
189 __ifi_mutex =
new Mutex();
191 init_failure_cleanup();
224 __skiller_if->
read();
226 if (__lua_thread && __lua_thread->failed()) {
268 __lua_thread->cancel();
269 __lua_thread->join();
275 __lua_thread->start();
284 :
Thread(
"LuaAgentContinuousExecutionThread::LuaThread",
285 Thread::OPMODE_CONTINUOUS)
300 __lua->do_string(
"agentenv.execute()");
303 logger->
log_error(name(),
"execute() failed, exception follows");