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