Fawkes API
Fawkes Development Version
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
All
Classes
Namespaces
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
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 <plugins/examples/basics/blackboard_thread.h>
24
#include <interfaces/TestInterface.h>
25
26
using namespace
fawkes;
27
28
29
/** @class ExampleBlackBoardThread <plugins/examples/basics/blackboard_thread.h>
30
* Simple demonstration for a thread using the BlackBoard.
31
*
32
* @author Tim Niemueller
33
*/
34
35
36
/** Constructor.
37
* @param reader set to true, to make this bb thread to open the test interface
38
* read-only, false to open it as a writer
39
*/
40
ExampleBlackBoardThread::ExampleBlackBoardThread
(
bool
reader)
41
:
Thread
(
"ExampleBlackBoardThread"
,
Thread
::OPMODE_WAITFORWAKEUP),
42
BlockedTimingAspect
(
BlockedTimingAspect
::WAKEUP_HOOK_THINK)
43
{
44
this->reader = reader;
45
}
46
47
48
/** Destructor. */
49
ExampleBlackBoardThread::~ExampleBlackBoardThread
()
50
{
51
}
52
53
54
void
55
ExampleBlackBoardThread::finalize
()
56
{
57
logger
->
log_debug
(
name
(),
"Closing test interface"
);
58
try
{
59
blackboard
->
close
(test_interface);
60
}
catch
(
Exception
&e) {
61
logger
->
log_error
(
name
(),
"Could not close kicker interface"
);
62
logger
->
log_error
(
name
(), e);
63
}
64
}
65
66
67
/** Initialize thread.
68
* Here, the device and the BB-interface are opened.
69
*/
70
void
71
ExampleBlackBoardThread::init
()
72
{
73
logger
->
log_debug
(
name
(),
"Opening test interface"
);
74
try
{
75
if
( reader ) {
76
test_interface =
blackboard
->
open_for_reading
<
TestInterface
>(
"Test"
);
77
}
else
{
78
test_interface =
blackboard
->
open_for_writing
<
TestInterface
>(
"Test"
);
79
}
80
}
catch
(
Exception
& e) {
81
e.
append
(
"Opening test interface for writing failed"
);
82
throw
;
83
}
84
}
85
86
/** Thread loop.
87
* Parse messages from the interface and update values in the interface.
88
*/
89
void
90
ExampleBlackBoardThread::loop
()
91
{
92
// nothin'
93
}
src
plugins
examples
basics
blackboard_thread.cpp
Generated by
1.8.1.2