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 <logging/component.h> 30 #include <lua/context.h> 31 #include <lua/interface_importer.h> 33 #include <interfaces/SkillerInterface.h> 34 #include <interfaces/SkillerDebugInterface.h> 54 :
Thread(
"LuaAgentPeriodicExecutionThread",
Thread::OPMODE_WAITFORWAKEUP),
72 LuaAgentPeriodicExecutionThread::init_failure_cleanup()
88 "Fawkes is no longer in a clean state. Restart!");
100 e.
append(
"Insufficient configuration for LuaAgent");
104 logger->
log_debug(
"LuaAgentPeriodicExecutionThread",
"Agent: %s", __cfg_agent.c_str());
113 std::string reading_prefix =
"/luaagent/interfaces/" + __cfg_agent +
"/reading/";
114 std::string writing_prefix =
"/luaagent/interfaces/" + __cfg_agent +
"/writing/";
118 __skiller_if->
read();
120 throw Exception(
"Skiller already has an exclusive controller");
128 if (__cfg_watch_files) {
147 __lua->
set_string(
"AGENT", __cfg_agent.c_str());
149 __lua->
set_usertype(
"logger", __clog,
"ComponentLogger",
"fawkes");
152 __lua->
set_usertype(
"tf", tf_listener,
"Transformer",
"fawkes::tf");
162 init_failure_cleanup();
188 LuaAgentPeriodicExecutionThread::process_agdbg_messages()
194 std::string graphdir =
"TB";
196 case SkillerDebugInterface::GD_BOTTOM_TOP: graphdir =
"BT";
break;
197 case SkillerDebugInterface::GD_LEFT_RIGHT: graphdir =
"LR";
break;
198 case SkillerDebugInterface::GD_RIGHT_LEFT: graphdir =
"RL";
break;
201 __lua->
do_string(
"agentenv.set_graphdir(\"%s\")", graphdir.c_str());
203 logger->
log_warn(
"LuaAgentPeriodicExecutionThread",
"Failed to set graph direction, exception follows");
211 logger->
log_warn(
"LuaAgentPeriodicExecutionThread",
"Failed to set graph direction, exception follows");
228 process_agdbg_messages();
231 __skiller_if->
read();
237 logger->
log_error(
"LuaAgentPeriodicExecutionThread",
"Execution of %s.execute() failed, exception follows",
238 __cfg_agent.c_str());
void set_graph(const char *new_graph)
Set graph value.
SkillerDebugInterface Fawkes BlackBoard Interface.
void setup_fam(bool auto_restart, bool conc_thread)
Setup file alteration monitor.
bool msgq_empty()
Check if queue is empty.
virtual void init()
Initialize the thread.
Fawkes library namespace.
virtual bool get_bool(const char *path)=0
Get value from configuration which is of type bool.
GraphDirectionEnum graph_dir() const
Get graph_dir value.
ReleaseControlMessage Fawkes BlackBoard Interface Message.
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 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.
Clock * clock
By means of this member access to the clock is given.
Thread aspect to use blocked timing.
void msgq_pop()
Erase first message from queue.
virtual void finalize()
Finalize the thread.
Base class for exceptions in Fawkes.
Message * msgq_first()
Get the first message from the message queue.
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.
bool has_writer() const
Check if there is a writer for the interface.
void set_graph_fsm(const char *new_graph_fsm)
Set graph_fsm value.
const char * name() const
Get name of thread.
bool msgq_first_is()
Check if first message has desired type.
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.
bool is_graph_colored() const
Get graph_colored value.
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.
SetGraphColoredMessage Fawkes BlackBoard Interface Message.
unsigned int msgq_enqueue(Message *message)
Enqueue message at end of queue.
void read()
Read from all reading interfaces.
void process_fam_events()
Process FAM events.
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.
LuaAgentPeriodicExecutionThread()
Constructor.
void write()
Write all writing interfaces.
SkillerInterface Fawkes BlackBoard Interface.
virtual void loop()
Code to execute in the thread.
Configuration * config
This is the Configuration member used to access the configuration.
SetGraphDirectionMessage Fawkes BlackBoard Interface Message.
virtual Interface * open_for_writing(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for writing.
virtual ~LuaAgentPeriodicExecutionThread()
Destructor.
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.