Fawkes API Fawkes Development Version
notifier.h
1
2/***************************************************************************
3 * notifier.h - BlackBoard notifier
4 *
5 * Created: Mon Mar 03 23:25:57 2008
6 * Copyright 2006-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. 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#ifndef _BLACKBOARD_NOTIFIER_H_
25#define _BLACKBOARD_NOTIFIER_H_
26
27#include <blackboard/blackboard.h>
28#include <blackboard/interface_listener.h>
29#include <blackboard/interface_observer.h>
30#include <core/utils/rwlock_map.h>
31#include <utils/uuid.h>
32
33#include <list>
34#include <string>
35#include <utility>
36
37namespace fawkes {
38
39class Interface;
40class Message;
41class Mutex;
42
44{
45public:
47 virtual ~BlackBoardNotifier();
48
54
57
58 void notify_of_data_refresh(const Interface *interface, bool has_changed);
59 bool notify_of_message_received(const Interface *interface, Message *message);
60 void notify_of_interface_created(const char *type, const char *id) noexcept;
61 void notify_of_interface_destroyed(const char *type, const char *id) noexcept;
62 void notify_of_writer_added(const Interface *interface, Uuid event_instance_serial) noexcept;
63 void notify_of_writer_removed(const Interface *interface, Uuid event_instance_serial) noexcept;
64 void notify_of_reader_added(const Interface *interface, Uuid event_instance_serial) noexcept;
65 void notify_of_reader_removed(const Interface *interface, Uuid event_instance_serial) noexcept;
66
67private:
68 /// @cond INTERNALS
69 typedef struct
70 {
71 bool op;
72 std::string uid;
73 Interface * interface;
75 } BBilQueueEntry;
76 /// @endcond INTERNALS
77 typedef std::list<BBilQueueEntry> BBilQueue;
78
79 typedef std::multimap<std::string, BlackBoardInterfaceListener *> BBilMap;
80 typedef std::pair<BlackBoardInterfaceObserver *, std::list<std::string>> BBioPair;
81 typedef std::list<BBioPair> BBioList;
82 typedef std::map<std::string, BBioList> BBioMap;
83
84 // Type to observer, add flags, 0 to remove
85 typedef std::pair<unsigned int, BlackBoardInterfaceObserver *> BBioQueueEntry;
86 typedef std::list<BBioQueueEntry> BBioQueue;
87
88 typedef BBilMap::iterator BBilMapIterator;
89
90 typedef BBioList::iterator BBioListIterator;
91 typedef BBioMap::iterator BBioMapIterator;
92
93 void proc_listener_maybe_queue(bool op,
94 Interface * interface,
96 Mutex * mutex,
97 unsigned int & events,
98 BBilMap & map,
99 BBilQueue & queue,
100 const char * hint);
101
102 void add_listener(Interface *interface, BlackBoardInterfaceListener *listener, BBilMap &ilmap);
103 void remove_listener(Interface *interface, BlackBoardInterfaceListener *listener, BBilMap &ilmap);
104 void queue_listener(bool op,
105 Interface * interface,
107 BBilQueue & queue);
108
109 void add_observer(BlackBoardInterfaceObserver * observer,
111 BBioMap & bbiomap);
112
113 void remove_observer(BBioMap &iomap, BlackBoardInterfaceObserver *observer);
114
115 void process_writer_queue();
116 void process_reader_queue();
117 void process_data_queue();
118 void process_bbio_queue();
119
120 bool is_in_queue(bool op, BBilQueue &queue, const char *uid, BlackBoardInterfaceListener *bbil);
121
122 BBilMap bbil_data_;
123 BBilMap bbil_reader_;
124 BBilMap bbil_writer_;
125 BBilMap bbil_messages_;
126
127 Mutex * bbil_unregister_mutex_;
128 BBilQueue bbil_unregister_queue_;
129
130 Mutex * bbil_writer_mutex_;
131 unsigned int bbil_writer_events_;
132 BBilQueue bbil_writer_queue_;
133
134 Mutex * bbil_reader_mutex_;
135 unsigned int bbil_reader_events_;
136 BBilQueue bbil_reader_queue_;
137
138 Mutex * bbil_data_mutex_;
139 unsigned int bbil_data_events_;
140 BBilQueue bbil_data_queue_;
141
142 Mutex * bbil_messages_mutex_;
143 unsigned int bbil_messages_events_;
144 BBilQueue bbil_messages_queue_;
145
146 BBioMap bbio_created_;
147 BBioMap bbio_destroyed_;
148
149 Mutex * bbio_mutex_;
150 unsigned int bbio_events_;
151 BBioQueue bbio_queue_;
152};
153
154} // end namespace fawkes
155
156#endif
BlackBoard interface listener.
BlackBoard interface observer.
BlackBoard notifier.
Definition: notifier.h:44
BlackBoardNotifier()
Constructor.
Definition: notifier.cpp:52
void notify_of_writer_added(const Interface *interface, Uuid event_instance_serial) noexcept
Notify that writer has been added.
Definition: notifier.cpp:495
void notify_of_writer_removed(const Interface *interface, Uuid event_instance_serial) noexcept
Notify that writer has been removed.
Definition: notifier.cpp:532
void unregister_listener(BlackBoardInterfaceListener *listener)
Unregister BB interface listener.
Definition: notifier.cpp:198
void notify_of_interface_destroyed(const char *type, const char *id) noexcept
Notify that an interface has been destroyed.
Definition: notifier.cpp:436
void notify_of_reader_added(const Interface *interface, Uuid event_instance_serial) noexcept
Notify that reader has been added.
Definition: notifier.cpp:589
virtual ~BlackBoardNotifier()
Destructor.
Definition: notifier.cpp:71
void notify_of_reader_removed(const Interface *interface, Uuid event_instance_serial) noexcept
Notify that reader has been removed.
Definition: notifier.cpp:626
void notify_of_data_refresh(const Interface *interface, bool has_changed)
Notify of data change.
Definition: notifier.cpp:689
void unregister_observer(BlackBoardInterfaceObserver *observer)
Unregister BB interface observer.
Definition: notifier.cpp:373
void register_listener(BlackBoardInterfaceListener *listener, BlackBoard::ListenerRegisterFlag flag)
Register BB event listener.
Definition: notifier.cpp:87
void notify_of_interface_created(const char *type, const char *id) noexcept
Notify that an interface has been created.
Definition: notifier.cpp:401
void register_observer(BlackBoardInterfaceObserver *observer)
Register BB interface observer.
Definition: notifier.cpp:313
void update_listener(BlackBoardInterfaceListener *listener, BlackBoard::ListenerRegisterFlag flag)
Update BB event listener.
Definition: notifier.cpp:99
bool notify_of_message_received(const Interface *interface, Message *message)
Notify of message received Notify all subscribers of the given interface of an incoming message This ...
Definition: notifier.cpp:744
ListenerRegisterFlag
Flags to constrain listener registration/updates.
Definition: blackboard.h:87
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:80
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:44
Mutex mutual exclusion lock.
Definition: mutex.h:33
A convenience class for universally unique identifiers (UUIDs).
Definition: uuid.h:29
Fawkes library namespace.