Fawkes API
Fawkes Development Version
|
23 #include "exec_thread.h"
25 #include "skiller_feature.h"
27 #include <core/exceptions/software.h>
28 #include <core/exceptions/system.h>
29 #include <core/threading/mutex.h>
30 #include <logging/component.h>
31 #ifdef SKILLER_TIMETRACKING
32 # include <utils/time/tracker.h>
35 #include <interfaces/SkillerDebugInterface.h>
36 #include <interfaces/SkillerInterface.h>
37 #include <lua/context.h>
57 :
Thread(
"SkillerExecutionThread",
Thread::OPMODE_WAITFORWAKEUP),
75 e.
append(
"Insufficient configuration for Skiller");
79 logger->
log_debug(
"SkillerExecutionThread",
"Skill space: %s", cfg_skillspace_.c_str());
90 if (cfg_watch_files_) {
91 lua_->setup_fam(
true,
false);
94 lua_->add_package_dir(LUADIR,
true);
95 lua_->add_cpackage_dir(LUALIBDIR,
true);
97 lua_->add_package(
"fawkesutils");
98 lua_->add_package(
"fawkesconfig");
99 lua_->add_package(
"fawkeslogging");
100 lua_->add_package(
"fawkesinterface");
101 lua_->add_package(
"fawkesblackboard");
103 lua_->add_package(
"fawkestf");
108 lua_->set_string(
"SKILLSPACE", cfg_skillspace_.c_str());
109 lua_->set_string(
"LUADIR", LUADIR);
110 lua_->set_usertype(
"config",
config,
"Configuration",
"fawkes");
111 lua_->set_usertype(
"logger", clog_,
"ComponentLogger",
"fawkes");
112 lua_->set_usertype(
"clock",
clock,
"Clock",
"fawkes");
113 lua_->set_usertype(
"blackboard", bbo_,
"BlackBoard",
"fawkes");
115 lua_->set_usertype(
"tf", tf_listener,
"Transformer",
"fawkes::tf");
118 lua_->create_table();
119 lua_->set_global(
"features_env_template");
121 std::list<SkillerFeature *>::iterator f;
122 for (f = features_.begin(); f != features_.end(); ++f) {
123 (*f)->init_lua_context(lua_);
126 lua_->set_finalization_calls(
"skiller.fawkes.finalize()",
127 "skiller.fawkes.finalize_prepare()",
128 "skiller.fawkes.finalize_cancel()");
130 lua_->set_start_script(LUADIR
"/skiller/fawkes/start.lua");
132 lua_->add_watcher(
this);
155 std::list<SkillerFeature *>::iterator f;
156 for (f = features_.begin(); f != features_.end(); ++f) {
157 (*f)->finalize_lua_context(lua_);
173 features_.push_back(feature);
182 std::list<SkillerFeature *>::iterator f;
183 for (f = features_.begin(); f != features_.end(); ++f) {
184 (*f)->init_lua_context(context);
188 lua_->
do_string(
"return fawkes.interface_initializer.finalize_prepare()");
196 std::string type, id;
197 Interface::parse_uid(lua_->
to_string(-2), type,
id);
198 context->
do_string(
"require(\"interfaces.%s\")", type.c_str());
206 context->
set_global(
"interfaces_writing_preload");
211 unsigned int instance_serial)
throw()
213 skiller_if_removed_readers_.push_locked(instance_serial);
223 skiller_if_removed_readers_.
lock();
224 while (!skiller_if_removed_readers_.empty()) {
225 lua_->
do_string(
"skiller.fawkes.notify_reader_removed(%u)",
226 skiller_if_removed_readers_.front());
227 skiller_if_removed_readers_.pop();
229 skiller_if_removed_readers_.
unlock();
void set_table(int t_index=-3)
Set value of a table.
void push_usertype(void *data, const char *type_name, const char *name_space=0)
Push usertype on top of stack.
virtual void register_listener(BlackBoardInterfaceListener *listener, ListenerRegisterFlag flag=BBIL_FLAG_ALL)
Register BB event listener.
SkillerExecutionThread()
Constructor.
void bb_interface_reader_removed(fawkes::Interface *interface, unsigned int instance_serial)
A reading instance has been closed for a watched interface.
void do_string(const char *format,...)
Execute string.
virtual bool get_bool(const char *path)=0
Get value from configuration which is of type bool.
void push_string(const char *value)
Push string on top of stack.
void create_table(int narr=0, int nrec=0)
Create a table on top of the stack.
virtual void unregister_listener(BlackBoardInterfaceListener *listener)
Unregister BB interface listener.
BlackBoard interface listener.
Thread aspect to use blocked timing.
void * to_usertype(int idx)
Retrieve stack value as a tolua++ user type.
Clock * clock
By means of this member access to the clock is given.
void append(const char *format,...)
Append messages to the message list.
const char * to_string(int idx)
Retrieve stack value as string.
Logger * logger
This is the Logger member used to access the logger.
virtual void close(Interface *interface)=0
Close interface.
void add_skiller_feature(SkillerFeature *feature)
Add a skiller feature.
Fawkes library namespace.
void lua_restarted(fawkes::LuaContext *context)
Lua restart event.
void pop(int n)
Pop value(s) from stack.
Base class for all Fawkes BlackBoard interfaces.
Configuration * config
This is the Configuration member used to access the configuration.
SkillerInterface Fawkes BlackBoard Interface.
void process_fam_events()
Process FAM events.
virtual void init()
Initialize the thread.
void lock() const
Lock queue.
Skiller feature base class.
BlackBoard that traces interface ownership.
virtual void loop()
Code to execute in the thread.
Thread class encapsulation of pthreads.
BlackBoard * blackboard
This is the BlackBoard instance you can use to interact with the BlackBoard.
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 bbil_add_reader_interface(Interface *interface)
Add an interface to the reader addition/removal watch list.
virtual void log_debug(const char *component, const char *format,...)=0
Log debug message.
void push_nil()
Push nil on top of stack.
void remove_watcher(LuaContextWatcher *watcher)
Remove a context watcher.
virtual ~SkillerExecutionThread()
Destructor.
virtual void finalize()
Finalize the thread.
void set_global(const char *name)
Set a global value.
void unlock() const
Unlock list.
Base class for exceptions in Fawkes.
bool table_next(int idx)
Iterate to next entry of table.