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>
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) {
151 __lua->
get_fam()->add_listener(
this);
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)
295 LuaAgentContinuousExecutionThread::LuaThread::loop()
303 logger->
log_error(name(),
"execute() failed, exception follows");
void restart()
Restart Lua.
virtual void init()
Initialize the thread.
void setup_fam(bool auto_restart, bool conc_thread)
Setup file alteration monitor.
uint32_t exclusive_controller() const
Get exclusive_controller value.
virtual void log_error(const char *component, const char *format,...)
Log error message.
virtual void remove(ThreadList &tl)=0
Remove multiple threads.
Fawkes library namespace.
virtual bool get_bool(const char *path)=0
Get value from configuration which is of type bool.
void unlock()
Unlock the mutex.
void read_to_buffer()
Read from all reading interfaces into a buffer.
void write_interfaces()
Update all reading interfaces.
void set_cfunction(const char *name, lua_CFunction f)
Assign cfunction to global variable.
void add_cpackage_dir(const char *path)
Add a Lua C package directory.
ReleaseControlMessage Fawkes BlackBoard Interface Message.
void read_interfaces()
Update all reading interfaces.
Thread class encapsulation of pthreads.
void set_prepfin_conc_loop(bool concurrent=true)
Set concurrent execution of prepare_finalize() and loop().
virtual ~LuaAgentContinuousExecutionThread()
Destructor.
void open_writing_interfaces(std::string &prefix)
Open interfaces for writing.
Logger * logger
This is the Logger member used to access the logger.
AcquireControlMessage Fawkes BlackBoard Interface Message.
void add_package(const char *package)
Add a default package.
ThreadCollector * thread_collector
Thread collector.
LuaAgent Periodic Execution Thread.
Clock * clock
By means of this member access to the clock is given.
bool has_writer() const
Check if there is a writer for the interface.
Thread aspect to use blocked timing.
Base class for exceptions in Fawkes.
void read()
Read from BlackBoard into local copy.
void do_string(const char *format,...)
Execute string.
void open_reading_interfaces(std::string &prefix)
Open interfaces for reading.
virtual void fam_event(const char *filename, unsigned int mask)
Event has been raised.
void read_from_buffer()
Update interfaces from internal buffers.
virtual void log_warn(const char *component, const char *format,...)=0
Log warning message.
void set_usertype(const char *name, void *data, const char *type_name, const char *name_space=0)
Assign usertype to global variable.
virtual void log_error(const char *component, const char *format,...)=0
Log error message.
virtual void add(ThreadList &tl)=0
Add multiple threads.
virtual void finalize()
Finalize the thread.
const char * name() const
Get name of thread.
void set_string(const char *name, const char *value)
Assign string to global variable.
void add_interface(std::string varname, Interface *interface)
Add a single interface to be pushed to the context.
RefPtr< FileAlterationMonitor > get_fam() const
Get file alteration monitor.
unsigned int msgq_enqueue(Message *message)
Enqueue message at end of queue.
virtual void loop()
Code to execute in the thread.
virtual void log_debug(const char *component, const char *format,...)=0
Log debug message.
void set_start_script(const char *start_script)
Set start script.
virtual Interface * open_for_reading(const char *interface_type, const char *identifier)=0
Open interface for reading.
void write()
Write all writing interfaces.
SkillerInterface Fawkes BlackBoard Interface.
LuaAgentContinuousExecutionThread()
Constructor.
void lock()
Lock this mutex.
Mutex mutual exclusion lock.
void add_package_dir(const char *path)
Add a Lua package directory.
Configuration * config
This is the Configuration member used to access the configuration.
void push_interfaces()
Push interfaces to Lua environment.
void append(const char *format,...)
Append messages to the message list.
virtual std::string get_string(const char *path)=0
Get value from configuration which is of type string.
BlackBoard * blackboard
This is the BlackBoard instance you can use to interact with the BlackBoard.
virtual void close(Interface *interface)=0
Close interface.