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");
void restart()
Restart Lua.
virtual void init()
Initialize the thread.
void setup_fam(bool auto_restart, bool conc_thread)
Setup file alteration monitor.
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.
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.