Fawkes API
Fawkes Development Version
|
Fawkes main thread. More...
#include <mainapp/main_thread.h>
Public Member Functions | |
FawkesMainThread (fawkes::ArgumentParser *argp) | |
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 (fawkes::Thread *mainloop_thread) |
Set a new main loop. | |
virtual void | add_logger (fawkes::Logger *logger) |
Add a new logger. | |
virtual void | remove_logger (fawkes::Logger *logger) |
Remove a logger. | |
Protected Member Functions | |
virtual void | run () |
Stub to see name in backtrace for easier debugging. |
Fawkes main thread.
This thread initializes all important stuff like the BlackBoard, handles plugins and wakes up threads at defined hooks.
FawkesMainThread::FawkesMainThread | ( | fawkes::ArgumentParser * | argp | ) |
Constructor.
argp | argument parser |
Definition at line 70 of file main_thread.cpp.
References fawkes::ArgumentParser::has_arg(), fawkes::ArgumentParser::arg(), fawkes::Exception::append(), fawkes::MultiLogger::set_loglevel(), fawkes::Thread::init(), fawkes::MultiLogger::log_warn(), fawkes::Configuration::load(), fawkes::SQLiteConfiguration::modified_iterator(), fawkes::SQLiteConfiguration::SQLiteValueIterator::next(), fawkes::SQLiteConfiguration::SQLiteValueIterator::get_modtype(), fawkes::SQLiteConfiguration::SQLiteValueIterator::path(), fawkes::SQLiteConfiguration::SQLiteValueIterator::get_oldvalue(), fawkes::SQLiteConfiguration::SQLiteValueIterator::get_as_string(), fawkes::MultiLogger::log_debug(), fawkes::Configuration::get_string(), fawkes::MultiLogger::log_info(), fawkes::Configuration::get_uint(), fawkes::Configuration::set_default_uint(), FawkesThreadManager::aspect_collector(), FawkesThreadManager::set_inifin(), FawkesNetworkManager::hub(), fawkes::MultiLogger::add_logger(), fawkes::AspectIniFin::set_fnet_hub(), fawkes::AspectIniFin::set_network_members(), FawkesNetworkManager::nnresolver(), FawkesNetworkManager::service_publisher(), FawkesNetworkManager::service_browser(), fawkes::AspectIniFin::set_plugin_manager(), fawkes::AspectIniFin::set_mainloop_employer(), fawkes::AspectIniFin::set_logger_employer(), fawkes::AspectIniFin::set_blocked_timing_executor(), fawkes::Thread::start(), fawkes::LocalBlackBoard::start_nethandler(), fawkes::Configuration::get_bool(), and fawkes::Thread::name().
FawkesMainThread::~FawkesMainThread | ( | ) | [virtual] |
Destructor.
Definition at line 291 of file main_thread.cpp.
void FawkesMainThread::add_logger | ( | fawkes::Logger * | logger | ) | [virtual] |
Add a new logger.
An exception should be thrown if anything prevents this from succeeding.
logger | logger to add |
Implements fawkes::LoggerEmployer.
Definition at line 405 of file main_thread.cpp.
References fawkes::MultiLogger::add_logger().
void 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 419 of file main_thread.cpp.
References FawkesThreadManager::timed_threads_exist(), fawkes::MultiLogger::log_debug(), FawkesThreadManager::wait_for_timed_threads(), fawkes::Mutex::lock(), fawkes::TimeWait::mark_start(), fawkes::Time::stamp_systime(), fawkes::Thread::set_cancel_state(), fawkes::Thread::CANCEL_DISABLED, fawkes::Thread::wakeup(), fawkes::InterruptibleBarrier::wait(), fawkes::MultiLogger::log_warn(), FawkesThreadManager::wakeup_and_wait(), fawkes::MultiLogger::log_error(), fawkes::Mutex::unlock(), fawkes::Thread::test_cancel(), FawkesThreadManager::try_recover(), fawkes::Thread::name(), fawkes::TimeWait::wait_systime(), and fawkes::Thread::yield().
void 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 363 of file main_thread.cpp.
References fawkes::ArgumentParser::has_arg(), fawkes::PluginManager::load(), fawkes::ArgumentParser::arg(), fawkes::MultiLogger::log_error(), and fawkes::PluginLoadException::plugin_name().
void FawkesMainThread::remove_logger | ( | fawkes::Logger * | logger | ) | [virtual] |
Remove a logger.
An exception should be thrown if anything prevents this from succeeding.
logger | logger to remove |
Implements fawkes::LoggerEmployer.
Definition at line 412 of file main_thread.cpp.
References fawkes::MultiLogger::remove_logger().
virtual void FawkesMainThread::run | ( | ) | [inline, protected, virtual] |
Stub to see name in backtrace for easier debugging.
Reimplemented from fawkes::Thread.
Definition at line 72 of file main_thread.h.
void FawkesMainThread::set_mainloop_thread | ( | fawkes::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 393 of file main_thread.cpp.
References fawkes::Thread::loopinterrupt_antistarve_mutex, fawkes::Mutex::lock(), fawkes::InterruptibleBarrier::interrupt(), and fawkes::Mutex::unlock().