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/utils/on_update_waker.h>
25 #include <blackboard/blackboard.h>
26 #include <interface/interface.h>
27 #include <interface/message.h>
28 #include <core/threading/thread.h>
29 
30 namespace fawkes {
31 #if 0 /* just to make Emacs auto-indent happy */
32 }
33 #endif
34 
35 /** @class BlackBoardOnUpdateWaker <blackboard/utils/on_update_waker.h>
36  * Wake threads when a blackboard interface is updated.
37  * This utility class registers as a BlackBoardInterfaceListener and
38  * if an update is observed it wakes the given thread.
39  * @author Tim Niemueller
40  */
41 
42 /** Constructor.
43  * @param bb blackboard to register with
44  * @param interface Interface to monitor for data updates
45  * @param thread thread to wake
46  */
48  Interface *interface,
49  Thread *thread)
50  : BlackBoardInterfaceListener("OnUpdateWaker[%s]", interface->uid()),
51  bb_(bb), thread_(thread)
52 {
53  bbil_add_data_interface(interface);
55 }
56 
57 /** Destructor.
58  * Unregisters from the blackboard.
59  */
61 {
62  bb_->unregister_listener(this);
63 }
64 
65 
66 void
68 {
69  thread_->wakeup();
70 }
71 
72 
73 } // end namespace fawkes
74 
consider data events
Definition: blackboard.h:99
Fawkes library namespace.
BlackBoardOnUpdateWaker(BlackBoard *bb, Interface *interface, Thread *thread)
Constructor.
virtual void unregister_listener(BlackBoardInterfaceListener *listener)
Unregister BB interface listener.
Definition: blackboard.cpp:218
Thread class encapsulation of pthreads.
Definition: thread.h:42
virtual ~BlackBoardOnUpdateWaker()
Destructor.
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:79
virtual void register_listener(BlackBoardInterfaceListener *listener, ListenerRegisterFlag flag=BBIL_FLAG_ALL)
Register BB event listener.
Definition: blackboard.cpp:190
void wakeup()
Wake up thread.
Definition: thread.cpp:1000
The BlackBoard abstract class.
Definition: blackboard.h:48
virtual void bb_interface_data_changed(Interface *interface)
BlackBoard data changed notification.
BlackBoard interface listener.
void bbil_add_data_interface(Interface *interface)
Add an interface to the data modification watch list.