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