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);
168 __lua->
set_string(
"AGENT", __cfg_agent.c_str());
170 __lua->
set_usertype(
"logger", __clog,
"ComponentLogger",
"fawkes");
173 __lua->
set_usertype(
"tf", tf_listener,
"Transformer",
"fawkes::tf");
176 __lua->
set_cfunction(
"write_interfaces", l_write_interfaces);
185 __lua_thread =
new LuaThread(__lua);
188 __ifi_mutex =
new Mutex();
190 init_failure_cleanup();
223 __skiller_if->
read();
225 if (__lua_thread && __lua_thread->failed()) {
267 __lua_thread->cancel();
268 __lua_thread->join();
274 __lua_thread->start();
283 :
Thread(
"LuaAgentContinuousExecutionThread::LuaThread",
284 Thread::OPMODE_CONTINUOUS)
294 LuaAgentContinuousExecutionThread::LuaThread::loop()
void restart()
Restart Lua.
Thread(const char *name)
Constructor.
virtual void init()
Initialize the thread.
void setup_fam(bool auto_restart, bool conc_thread)
Setup file alteration monitor.
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.
ReleaseControlMessage Fawkes BlackBoard Interface Message.
void read_interfaces()
Update all reading interfaces.
void add_package_dir(const char *path, bool prefix=false)
Add a Lua package directory.
uint32_t exclusive_controller() const
Get exclusive_controller value.
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.
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.
bool has_writer() const
Check if there is a writer for the interface.
void read_from_buffer()
Update interfaces from internal buffers.
const char * name() const
Get name of thread.
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.
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.
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.
virtual Interface * open_for_reading(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for reading.
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.
void write()
Write all writing interfaces.
SkillerInterface Fawkes BlackBoard Interface.
LuaAgentContinuousExecutionThread()
Constructor.
void lock()
Lock this mutex.
Mutex mutual exclusion lock.
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.
RefPtr< FileAlterationMonitor > get_fam() const
Get file alteration monitor.
virtual void close(Interface *interface)=0
Close interface.