Fawkes API
Fawkes Development Version
|
23 #include "periodic_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>
52 :
Thread(
"LuaAgentPeriodicExecutionThread",
Thread::OPMODE_WAITFORWAKEUP),
68 LuaAgentPeriodicExecutionThread::init_failure_cleanup()
85 "Really screwed up while finalizing, aborting cleanup. "
86 "Fawkes is no longer in a clean state. Restart!");
97 e.
append(
"Insufficient configuration for LuaAgent");
101 logger->
log_debug(
"LuaAgentPeriodicExecutionThread",
"Agent: %s", cfg_agent_.c_str());
110 std::string reading_prefix =
"/luaagent/interfaces/" + cfg_agent_ +
"/reading/";
111 std::string writing_prefix =
"/luaagent/interfaces/" + cfg_agent_ +
"/writing/";
117 throw Exception(
"Skiller already has an exclusive controller");
125 if (cfg_watch_files_) {
144 lua_->
set_string(
"AGENT", cfg_agent_.c_str());
146 lua_->
set_usertype(
"logger", clog_,
"ComponentLogger",
"fawkes");
149 lua_->
set_usertype(
"tf", tf_listener,
"Transformer",
"fawkes::tf");
159 init_failure_cleanup();
183 LuaAgentPeriodicExecutionThread::process_agdbg_messages()
190 std::string graphdir =
"TB";
192 case SkillerDebugInterface::GD_BOTTOM_TOP: graphdir =
"BT";
break;
193 case SkillerDebugInterface::GD_LEFT_RIGHT: graphdir =
"LR";
break;
194 case SkillerDebugInterface::GD_RIGHT_LEFT: graphdir =
"RL";
break;
197 lua_->
do_string(
"agentenv.set_graphdir(\"%s\")", graphdir.c_str());
200 "Failed to set graph direction, exception follows");
210 "Failed to set graph direction, exception follows");
226 process_agdbg_messages();
236 "Execution of %s.execute() failed, exception follows",
bool msgq_first_is()
Check if first message has desired type.
void msgq_pop()
Erase first message from queue.
bool msgq_empty()
Check if queue is empty.
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.
void set_graph(const char *new_graph)
Set graph value.
void do_string(const char *format,...)
Execute string.
void read()
Read from BlackBoard into local copy.
virtual bool get_bool(const char *path)=0
void set_graph_fsm(const char *new_graph_fsm)
Set graph_fsm value.
virtual void init()
Initialize the thread.
LuaAgentPeriodicExecutionThread()
Constructor.
const char * name() const
bool is_graph_colored() const
Get graph_colored value.
void read()
Read from all reading interfaces.
virtual void loop()
Code to execute in the thread.
GraphDirectionEnum graph_dir() const
Get graph_dir value.
virtual ~LuaAgentPeriodicExecutionThread()
Destructor.
void append(const char *format,...)
Append messages to the message list.
virtual void close(Interface *interface)=0
virtual void log_error(const char *component, const char *format,...)=0
virtual void log_warn(const char *component, const char *format,...)=0
virtual void finalize()
Finalize the thread.
bool has_writer() const
Check if there is a writer for the interface.
void process_fam_events()
Process FAM events.
void open_writing_interfaces(std::string &prefix)
Open interfaces for writing.
void setup_fam(bool auto_restart, bool conc_thread)
Setup file alteration monitor.
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.
void add_package(const char *package)
Add a default package.
virtual std::string get_string(const char *path)=0
virtual Interface * open_for_reading(const char *interface_type, const char *identifier, const char *owner=NULL)=0
void add_cpackage_dir(const char *path, bool prefix=false)
Add a Lua C package directory.
void push_interfaces()
Push interfaces to Lua environment.
unsigned int msgq_enqueue(Message *message)
Enqueue message at end of queue.
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.
Message * msgq_first()
Get the first message from the message queue.
virtual void log_debug(const char *component, const char *format,...)=0
virtual Interface * open_for_writing(const char *interface_type, const char *identifier, const char *owner=NULL)=0