Fawkes API
Fawkes Development Version
on_update_waker.cpp
1
2
/***************************************************************************
3
* on_update_waker.h - wake a thread whenever an interface is updated
4
*
5
* Created: Thu Dec 06 14:27:00 2012
6
* Copyright 2012 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. A runtime exception applies to
14
* this software (see LICENSE.GPL_WRE file mentioned below for details).
15
*
16
* This program is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU Library General Public License for more details.
20
*
21
* Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22
*/
23
24
#include <blackboard/blackboard.h>
25
#include <blackboard/utils/on_update_waker.h>
26
#include <core/threading/thread.h>
27
#include <interface/interface.h>
28
#include <interface/message.h>
29
30
namespace
fawkes
{
31
32
/** @class BlackBoardOnUpdateWaker <blackboard/utils/on_update_waker.h>
33
* Wake threads when a blackboard interface is updated.
34
* This utility class registers as a BlackBoardInterfaceListener and
35
* if an update is observed it wakes the given thread.
36
* @author Tim Niemueller
37
*/
38
39
/** Constructor.
40
* @param bb blackboard to register with
41
* @param interface Interface to monitor for data updates
42
* @param thread thread to wake
43
*/
44
BlackBoardOnUpdateWaker::BlackBoardOnUpdateWaker
(BlackBoard *bb,
45
Interface * interface,
46
Thread * thread)
47
: BlackBoardInterfaceListener(
"OnUpdateWaker[%s]"
, interface->uid()), bb_(bb), thread_(thread)
48
{
49
bbil_add_data_interface(interface);
50
bb_->register_listener(
this
,
BlackBoard::BBIL_FLAG_DATA
);
51
}
52
53
/** Destructor.
54
* Unregisters from the blackboard.
55
*/
56
BlackBoardOnUpdateWaker::~BlackBoardOnUpdateWaker
()
57
{
58
bb_->
unregister_listener
(
this
);
59
}
60
61
void
62
BlackBoardOnUpdateWaker::bb_interface_data_changed
(
Interface
*interface)
throw
()
63
{
64
thread_->wakeup();
65
}
66
67
}
// end namespace fawkes
fawkes::BlackBoard::BBIL_FLAG_DATA
consider data events
Definition:
blackboard.h:91
fawkes::BlackBoard::unregister_listener
virtual void unregister_listener(BlackBoardInterfaceListener *listener)
Unregister BB interface listener.
Definition:
blackboard.cpp:215
fawkes::BlackBoardOnUpdateWaker::~BlackBoardOnUpdateWaker
virtual ~BlackBoardOnUpdateWaker()
Destructor.
Definition:
on_update_waker.cpp:60
fawkes
fawkes::Interface
Definition:
interface.h:77
fawkes::BlackBoardOnUpdateWaker::bb_interface_data_changed
virtual void bb_interface_data_changed(Interface *interface)
BlackBoard data changed notification.
Definition:
on_update_waker.cpp:66
fawkes::BlackBoardOnUpdateWaker::BlackBoardOnUpdateWaker
BlackBoardOnUpdateWaker(BlackBoard *bb, Interface *interface, Thread *thread)
Constructor.
Definition:
on_update_waker.cpp:48
src
libs
blackboard
utils
on_update_waker.cpp
Generated by
1.8.16