Fawkes API Fawkes Development Version
|
Simple demonstration for a thread using the BlackBoard. More...
#include <>>
Public Member Functions | |
ExampleBlackBoardThread (bool reader) | |
Constructor. | |
virtual | ~ExampleBlackBoardThread () |
Destructor. | |
virtual void | finalize () |
Finalize the thread. | |
virtual void | init () |
Initialize thread. | |
virtual void | loop () |
Thread loop. |
Simple demonstration for a thread using the BlackBoard.
Definition at line 35 of file blackboard_thread.h.
ExampleBlackBoardThread::ExampleBlackBoardThread | ( | bool | reader | ) |
Constructor.
reader | set to true, to make this bb thread to open the test interface read-only, false to open it as a writer |
Definition at line 40 of file blackboard_thread.cpp.
ExampleBlackBoardThread::~ExampleBlackBoardThread | ( | ) | [virtual] |
Destructor.
Definition at line 49 of file blackboard_thread.cpp.
void ExampleBlackBoardThread::finalize | ( | ) | [virtual] |
Finalize the thread.
This method is executed just before the thread is canceled and destroyed. It is always preceeded by a call to prepare_finalize(). If this is not the case this is a failure. The condition can be checked with the boolean variable finalize_prepared.
This method is meant to be used in conjunction with aspects and to cover thread inter-dependencies. This routine MUST bring the thread into a safe state such that it may be canceled and destroyed afterwards. If there is any reason that this cannot happen make your prepare_finalize() reports so.
This method is called by the thread manager just before the thread is being cancelled. Here you can do whatever steps are necessary just before the thread is cancelled. Note that you thread is still running and might be in the middle of a loop, so it is not a good place to give up on all resources used. Mind segmentation faults that could happen. Protect the area with a mutex that you lock at the beginning of your loop and free in the end, and that you lock at the beginning of finalize and then never unlock. Also not that the finalization may be canceled afterwards. The next thing that happens is that either the thread is canceled and destroyed or that the finalization is canceled and the thread has to run again.
Finalize is called on a thread just before it is deleted. It is guaranteed to be called on a fully initialized thread (if no exception is thrown in init()) (this guarantee holds in the Fawkes framework).
The default implementation does nothing besides throwing an exception if prepare_finalize() has not been called.
Exception | thrown if prepare_finalize() has not been called. |
Reimplemented from fawkes::Thread.
Definition at line 55 of file blackboard_thread.cpp.
References fawkes::BlackBoardAspect::blackboard, fawkes::BlackBoard::close(), fawkes::Logger::log_debug(), fawkes::Logger::log_error(), fawkes::LoggingAspect::logger, and fawkes::Thread::name().
void ExampleBlackBoardThread::init | ( | ) | [virtual] |
Initialize thread.
Here, the device and the BB-interface are opened.
Reimplemented from fawkes::Thread.
Definition at line 71 of file blackboard_thread.cpp.
References fawkes::Exception::append(), fawkes::BlackBoardAspect::blackboard, fawkes::Logger::log_debug(), fawkes::LoggingAspect::logger, fawkes::Thread::name(), fawkes::BlackBoard::open_for_reading(), and fawkes::BlackBoard::open_for_writing().
void ExampleBlackBoardThread::loop | ( | ) | [virtual] |
Thread loop.
Parse messages from the interface and update values in the interface.
Reimplemented from fawkes::Thread.
Definition at line 90 of file blackboard_thread.cpp.