Fawkes API  Fawkes Development Version
fawkes::FawkesMainThread Class Reference

Fawkes default main thread. More...

#include <>>

Inheritance diagram for fawkes::FawkesMainThread:

List of all members.

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.
MultiLoggerlogger () const
 Get logger.

Protected Member Functions

virtual void run ()
 Stub to see name in backtrace for easier debugging.

Detailed Description

Fawkes default main thread.

This thread initializes all important stuff like the BlackBoard, handles plugins and wakes up threads at defined hooks.

Author:
Tim Niemueller

Constructor & Destructor Documentation

fawkes::FawkesMainThread::FawkesMainThread ( SQLiteConfiguration config,
MultiLogger multi_logger,
ThreadManager thread_manager,
PluginManager plugin_manager,
const char *  load_plugins,
const char *  default_plugin = 0 
)

Constructor.

Parameters:
configconfiguration to use
multi_loggerbasic multi logger to use, a network logger will be added in the ctor.
thread_managerthread manager used to wakeup threads
plugin_managerplugin manager to load the desired plugins
load_pluginsstring with comma-separated list of names of plugins to load on startup.
default_pluginadditional 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.


Member Function Documentation

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

Get logger.

Returns:
logger

Definition at line 390 of file main_thread.cpp.

void fawkes::FawkesMainThread::loop ( ) [virtual]
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.

See also:
Thread::run()

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.

Parameters:
mainloop_threadnew 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().


The documentation for this class was generated from the following files: