Fawkes API Fawkes Development Version

ExampleBlackBoardThread Class Reference

Simple demonstration for a thread using the BlackBoard. More...

#include <>>

Inheritance diagram for ExampleBlackBoardThread:

List of all members.

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.

Detailed Description

Simple demonstration for a thread using the BlackBoard.

Author:
Tim Niemueller

Definition at line 35 of file blackboard_thread.h.


Constructor & Destructor Documentation

ExampleBlackBoardThread::ExampleBlackBoardThread ( bool  reader)

Constructor.

Parameters:
readerset 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.


Member Function Documentation

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.

Exceptions:
Exceptionthrown if prepare_finalize() has not been called.
See also:
prepare_finalize()
cancel_finalize()

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]
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.


The documentation for this class was generated from the following files:
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends