23 #include "exec_thread.h" 24 #include "skiller_feature.h" 26 #include <core/exceptions/software.h> 27 #include <core/exceptions/system.h> 28 #include <core/threading/mutex.h> 29 #include <logging/component.h> 30 #ifdef SKILLER_TIMETRACKING 31 # include <utils/time/tracker.h> 34 #include <lua/context.h> 36 #include <interfaces/SkillerInterface.h> 37 #include <interfaces/SkillerDebugInterface.h> 58 :
Thread(
"SkillerExecutionThread",
Thread::OPMODE_WAITFORWAKEUP),
78 e.
append(
"Insufficient configuration for Skiller");
82 logger->
log_debug(
"SkillerExecutionThread",
"Skill space: %s", __cfg_skillspace.c_str());
93 if (__cfg_watch_files) {
94 __lua->setup_fam(
true,
false);
97 __lua->add_package_dir(LUADIR,
true);
98 __lua->add_cpackage_dir(LUALIBDIR,
true);
100 __lua->add_package(
"fawkesutils");
101 __lua->add_package(
"fawkesconfig");
102 __lua->add_package(
"fawkeslogging");
103 __lua->add_package(
"fawkesinterface");
104 __lua->add_package(
"fawkesblackboard");
106 __lua->add_package(
"fawkestf");
111 __lua->set_string(
"SKILLSPACE", __cfg_skillspace.c_str());
112 __lua->set_string(
"LUADIR", LUADIR);
113 __lua->set_usertype(
"config",
config,
"Configuration",
"fawkes");
114 __lua->set_usertype(
"logger", __clog,
"ComponentLogger",
"fawkes");
115 __lua->set_usertype(
"clock",
clock,
"Clock",
"fawkes");
116 __lua->set_usertype(
"blackboard", __bbo,
"BlackBoard",
"fawkes");
118 __lua->set_usertype(
"tf", tf_listener,
"Transformer",
"fawkes::tf");
121 __lua->create_table();
122 __lua->set_global(
"features_env_template");
124 std::list<SkillerFeature *>::iterator f;
125 for (f = __features.begin(); f != __features.end(); ++f) {
126 (*f)->init_lua_context(__lua);
129 __lua->set_finalization_calls(
"skiller.fawkes.finalize()",
130 "skiller.fawkes.finalize_prepare()",
131 "skiller.fawkes.finalize_cancel()");
133 __lua->set_start_script(LUADIR
"/skiller/fawkes/start.lua");
135 __lua->add_watcher(
this);
160 std::list<SkillerFeature *>::iterator f;
161 for (f = __features.begin(); f != __features.end(); ++f) {
162 (*f)->finalize_lua_context(__lua);
179 __features.push_back(feature);
189 std::list<SkillerFeature *>::iterator f;
190 for (f = __features.begin(); f != __features.end(); ++f) {
191 (*f)->init_lua_context(context);
195 __lua->
do_string(
"return fawkes.interface_initializer.finalize_prepare()");
203 std::string type, id;
204 Interface::parse_uid(__lua->
to_string(-2), type, id);
205 context->
do_string(
"require(\"interfaces.%s\")", type.c_str());
213 context->
set_global(
"interfaces_writing_preload");
219 unsigned int instance_serial)
throw()
221 __skiller_if_removed_readers.
push_locked(instance_serial);
232 __skiller_if_removed_readers.
lock();
233 while (! __skiller_if_removed_readers.empty()) {
234 __lua->
do_string(
"skiller.fawkes.notify_reader_removed(%u)", __skiller_if_removed_readers.front());
235 __skiller_if_removed_readers.pop();
237 __skiller_if_removed_readers.
unlock();
virtual ~SkillerExecutionThread()
Destructor.
virtual void loop()
Code to execute in the thread.
void unlock() const
Unlock list.
SkillerExecutionThread()
Constructor.
void bb_interface_reader_removed(fawkes::Interface *interface, unsigned int instance_serial)
A reading instance has been closed for a watched interface.
Fawkes library namespace.
virtual bool get_bool(const char *path)=0
Get value from configuration which is of type bool.
void pop(int n)
Pop value(s) from stack.
virtual void unregister_listener(BlackBoardInterfaceListener *listener)
Unregister BB interface listener.
Thread class encapsulation of pthreads.
void remove_watcher(LuaContextWatcher *watcher)
Remove a context watcher.
Base class for all Fawkes BlackBoard interfaces.
Logger * logger
This is the Logger member used to access the logger.
void set_table(int t_index=-3)
Set value of a table.
Clock * clock
By means of this member access to the clock is given.
Thread aspect to use blocked timing.
virtual void register_listener(BlackBoardInterfaceListener *listener, ListenerRegisterFlag flag=BBIL_FLAG_ALL)
Register BB event listener.
void lua_restarted(fawkes::LuaContext *context)
Lua restart event.
void push_nil()
Push nil on top of stack.
Base class for exceptions in Fawkes.
void do_string(const char *format,...)
Execute string.
BlackBoard that traces interface ownership.
void push_usertype(void *data, const char *type_name, const char *name_space=0)
Push usertype on top of stack.
void add_skiller_feature(SkillerFeature *feature)
Add a skiller feature.
void push_string(const char *value)
Push string on top of stack.
void process_fam_events()
Process FAM events.
void bbil_add_reader_interface(Interface *interface)
Add an interface to the reader addition/removal watch list.
virtual void init()
Initialize the thread.
virtual void log_debug(const char *component, const char *format,...)=0
Log debug message.
void push_locked(const Type &x)
Push element to queue with lock protection.
virtual Interface * open_for_reading(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for reading.
void lock() const
Lock queue.
bool table_next(int idx)
Iterate to next entry of table.
SkillerInterface Fawkes BlackBoard Interface.
Skiller feature base class.
virtual void finalize()
Finalize the thread.
void set_global(const char *name)
Set a global value.
void create_table(int narr=0, int nrec=0)
Create a table on top of the stack.
Configuration * config
This is the Configuration member used to access the configuration.
void * to_usertype(int idx)
Retrieve stack value as a tolua++ user type.
const char * to_string(int idx)
Retrieve stack value as string.
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 interface listener.
BlackBoard * blackboard
This is the BlackBoard instance you can use to interact with the BlackBoard.
virtual void close(Interface *interface)=0
Close interface.