Fawkes API  Fawkes Development Version
blackboard_thread.cpp
1 
2 /***************************************************************************
3  * blackboard_thread.cpp - Fawkes Example Plugin BlackBoard Thread
4  *
5  * Created: Wed Jun 20 16:37:40 2007
6  * Copyright 2007-2008 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 
23 #include <interfaces/TestInterface.h>
24 #include <plugins/examples/basics/blackboard_thread.h>
25 
26 using namespace fawkes;
27 
28 /** @class ExampleBlackBoardThread <plugins/examples/basics/blackboard_thread.h>
29  * Simple demonstration for a thread using the BlackBoard.
30  *
31  * @author Tim Niemueller
32  */
33 
34 /** Constructor.
35  * @param reader set to true, to make this bb thread to open the test interface
36  * read-only, false to open it as a writer
37  */
39 : Thread("ExampleBlackBoardThread", Thread::OPMODE_WAITFORWAKEUP),
40  BlockedTimingAspect(BlockedTimingAspect::WAKEUP_HOOK_THINK)
41 {
42  this->reader = reader;
43 }
44 
45 /** Destructor. */
47 {
48 }
49 
50 void
52 {
53  logger->log_debug(name(), "Closing test interface");
54  try {
55  blackboard->close(test_interface);
56  } catch (Exception &e) {
57  logger->log_error(name(), "Could not close kicker interface");
58  logger->log_error(name(), e);
59  }
60 }
61 
62 /** Initialize thread.
63  * Here, the device and the BB-interface are opened.
64  */
65 void
67 {
68  logger->log_debug(name(), "Opening test interface");
69  try {
70  if (reader) {
71  test_interface = blackboard->open_for_reading<TestInterface>("Test");
72  } else {
73  test_interface = blackboard->open_for_writing<TestInterface>("Test");
74  }
75  } catch (Exception &e) {
76  e.append("Opening test interface for writing failed");
77  throw;
78  }
79 }
80 
81 /** Thread loop.
82  * Parse messages from the interface and update values in the interface.
83  */
84 void
86 {
87  // nothin'
88 }
ExampleBlackBoardThread::init
virtual void init()
Initialize thread.
Definition: blackboard_thread.cpp:66
ExampleBlackBoardThread::loop
virtual void loop()
Thread loop.
Definition: blackboard_thread.cpp:85
fawkes::BlockedTimingAspect
Thread aspect to use blocked timing.
Definition: blocked_timing.h:51
fawkes::Thread::name
const char * name() const
Get name of thread.
Definition: thread.h:100
ExampleBlackBoardThread::finalize
virtual void finalize()
Finalize the thread.
Definition: blackboard_thread.cpp:51
fawkes::Exception::append
void append(const char *format,...)
Append messages to the message list.
Definition: exception.cpp:333
fawkes::LoggingAspect::logger
Logger * logger
This is the Logger member used to access the logger.
Definition: logging.h:41
fawkes::BlackBoard::close
virtual void close(Interface *interface)=0
Close interface.
fawkes::Logger::log_error
virtual void log_error(const char *component, const char *format,...)=0
Log error message.
ExampleBlackBoardThread::ExampleBlackBoardThread
ExampleBlackBoardThread(bool reader)
Constructor.
Definition: blackboard_thread.cpp:38
fawkes
Fawkes library namespace.
fawkes::Thread
Thread class encapsulation of pthreads.
Definition: thread.h:46
fawkes::BlackBoardAspect::blackboard
BlackBoard * blackboard
This is the BlackBoard instance you can use to interact with the BlackBoard.
Definition: blackboard.h:44
ExampleBlackBoardThread::~ExampleBlackBoardThread
virtual ~ExampleBlackBoardThread()
Destructor.
Definition: blackboard_thread.cpp:46
fawkes::BlackBoard::open_for_reading
virtual Interface * open_for_reading(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for reading.
fawkes::TestInterface
TestInterface Fawkes BlackBoard Interface.
Definition: TestInterface.h:34
fawkes::Logger::log_debug
virtual void log_debug(const char *component, const char *format,...)=0
Log debug message.
fawkes::BlackBoard::open_for_writing
virtual Interface * open_for_writing(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for writing.
fawkes::Exception
Base class for exceptions in Fawkes.
Definition: exception.h:36