Fawkes API
Fawkes Development Version
|
Fawkes default main thread. More...
#include <>>
Classes | |
class | Runner |
Utility class to run the main thread. More... | |
Public Member Functions | |
FawkesMainThread (SQLiteConfiguration *config, MultiLogger *multi_logger, ThreadManager *thread_manager, PluginManager *plugin_manager, const char *load_plugins, const char *default_plugin=0) | |
Constructor. | |
virtual | ~FawkesMainThread () |
Destructor. | |
virtual void | once () |
Execute an action exactly once. | |
virtual void | loop () |
Code to execute in the thread. | |
virtual void | set_mainloop_thread (Thread *mainloop_thread) |
Set a new main loop. | |
void | full_start () |
Start the thread and wait until once() completes. | |
MultiLogger * | logger () const |
Get logger. | |
Protected Member Functions | |
virtual void | run () |
Stub to see name in backtrace for easier debugging. |
Fawkes default main thread.
This thread initializes all important stuff like the BlackBoard, handles plugins and wakes up threads at defined hooks.
fawkes::FawkesMainThread::FawkesMainThread | ( | SQLiteConfiguration * | config, |
MultiLogger * | multi_logger, | ||
ThreadManager * | thread_manager, | ||
PluginManager * | plugin_manager, | ||
const char * | load_plugins, | ||
const char * | default_plugin = 0 |
||
) |
Constructor.
config | configuration to use |
multi_logger | basic multi logger to use, a network logger will be added in the ctor. |
thread_manager | thread manager used to wakeup threads |
plugin_manager | plugin manager to load the desired plugins |
load_plugins | string with comma-separated list of names of plugins to load on startup. |
default_plugin | additional default plugin name |
Definition at line 73 of file main_thread.cpp.
References fawkes::Clock::instance(), fawkes::Configuration::get_uint(), fawkes::MultiLogger::log_info(), fawkes::Configuration::get_bool(), fawkes::MultiLogger::log_debug(), and fawkes::Thread::name().
fawkes::FawkesMainThread::~FawkesMainThread | ( | ) | [virtual] |
Destructor.
Definition at line 143 of file main_thread.cpp.
void fawkes::FawkesMainThread::full_start | ( | ) |
Start the thread and wait until once() completes.
This is useful to assure that all plugins are loaded before assuming that startup is complete.
Definition at line 198 of file main_thread.cpp.
References fawkes::Thread::start(), and fawkes::Barrier::wait().
MultiLogger * fawkes::FawkesMainThread::logger | ( | ) | const |
void fawkes::FawkesMainThread::loop | ( | ) | [virtual] |
Code to execute in the thread.
Implement this method to hold the code you want to be executed continously. If you do not implement this method, the default is that the thread will exit. This is useful if you choose to only implement once().
Reimplemented from fawkes::Thread.
Definition at line 273 of file main_thread.cpp.
References fawkes::ThreadManager::timed_threads_exist(), fawkes::MultiLogger::log_debug(), fawkes::ThreadManager::wait_for_timed_threads(), fawkes::PluginManager::lock(), fawkes::TimeWait::mark_start(), fawkes::Time::stamp_systime(), fawkes::Thread::set_cancel_state(), fawkes::Thread::CANCEL_DISABLED, fawkes::Mutex::lock(), fawkes::Thread::wakeup(), fawkes::InterruptibleBarrier::wait(), fawkes::MultiLogger::log_warn(), fawkes::BlockedTimingAspect::WAKEUP_HOOK_PRE_LOOP, fawkes::BlockedTimingAspect::WAKEUP_HOOK_SENSOR_ACQUIRE, fawkes::BlockedTimingAspect::WAKEUP_HOOK_SENSOR_PREPARE, fawkes::BlockedTimingAspect::WAKEUP_HOOK_SENSOR_PROCESS, fawkes::BlockedTimingAspect::WAKEUP_HOOK_WORLDSTATE, fawkes::BlockedTimingAspect::WAKEUP_HOOK_THINK, fawkes::BlockedTimingAspect::WAKEUP_HOOK_SKILL, fawkes::BlockedTimingAspect::WAKEUP_HOOK_ACT, fawkes::BlockedTimingAspect::WAKEUP_HOOK_ACT_EXEC, fawkes::BlockedTimingAspect::WAKEUP_HOOK_POST_LOOP, fawkes::Mutex::unlock(), fawkes::Thread::test_cancel(), fawkes::ThreadManager::try_recover(), fawkes::PluginManager::unlock(), fawkes::TimeWait::wait_systime(), and fawkes::Thread::yield().
void fawkes::FawkesMainThread::once | ( | ) | [virtual] |
Execute an action exactly once.
This code is executed once and only once right after the thread is started before loop() is called. This is useful if you want to implement an one-shot background job. Just implement once() and leave once() untouched. Start the thread and detach it and it will just do its job and then die automatically. If you use set_delete_on_exit(true) even the Thread instance will be automatically deleted.
Reimplemented from fawkes::Thread.
Definition at line 210 of file main_thread.cpp.
References fawkes::PluginManager::load(), fawkes::MultiLogger::log_error(), fawkes::PluginLoadException::plugin_name(), and fawkes::Barrier::wait().
virtual void fawkes::FawkesMainThread::run | ( | ) | [inline, protected, virtual] |
Stub to see name in backtrace for easier debugging.
Reimplemented from fawkes::Thread.
Definition at line 96 of file main_thread.h.
void fawkes::FawkesMainThread::set_mainloop_thread | ( | Thread * | mainloop_thread | ) | [virtual] |
Set a new main loop.
Set the main loop. An exception should be thrown if anything prevents this from happening successful.
mainloop_thread | new main loop thread. The caller of this method must ensure that the thread operates in wait-for-wakeup mode and executes the main loop as its loop() method (i.e. the thread must have a properly initialized MainLoopAspect). |
Implements fawkes::MainLoopEmployer.
Definition at line 261 of file main_thread.cpp.
References fawkes::Thread::loopinterrupt_antistarve_mutex, fawkes::Mutex::lock(), fawkes::InterruptibleBarrier::interrupt(), and fawkes::Mutex::unlock().