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 
31 #include <core/utils/rwlock_map.h>
32 
33 #include <list>
34 #include <string>
35 #include <utility>
36 
37 namespace fawkes {
38 
39 class Interface;
40 class Message;
41 class Mutex;
42 
44 {
45  public:
47  virtual ~BlackBoardNotifier();
48 
54 
57 
58  void notify_of_data_change(const Interface *interface);
59  bool notify_of_message_received(const Interface *interface, Message *message);
60  void notify_of_interface_created(const char *type, const char *id) throw();
61  void notify_of_interface_destroyed(const char *type, const char *id) throw();
62  void notify_of_writer_added(const Interface *interface,
63  unsigned int event_instance_serial) throw();
64  void notify_of_writer_removed(const Interface *interface,
65  unsigned int event_instance_serial) throw();
66  void notify_of_reader_added(const Interface *interface,
67  unsigned int event_instance_serial) throw();
68  void notify_of_reader_removed(const Interface *interface,
69  unsigned int event_instance_serial) throw();
70 
71  private:
72  /// @cond INTERNALS
73  typedef struct {
74  bool op;
75  std::string uid;
76  Interface * interface;
77  BlackBoardInterfaceListener * listener;
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, Interface *interface,
98  Mutex *mutex, unsigned int &events,
99  BBilMap &map, BBilQueue &queue,
100  const char *hint);
101 
102  void add_listener(Interface *interface, BlackBoardInterfaceListener *listener,
103  BBilMap &ilmap);
104  void remove_listener(Interface *interface, BlackBoardInterfaceListener *listener,
105  BBilMap &ilmap);
106  void queue_listener(bool op, Interface *interface,
107  BlackBoardInterfaceListener *listener, BBilQueue &queue);
108 
109 
110 
111  void add_observer(BlackBoardInterfaceObserver *observer,
113  BBioMap &bbiomap);
114 
115  void remove_observer(BBioMap &iomap, BlackBoardInterfaceObserver *observer);
116 
117  void process_writer_queue();
118  void process_reader_queue();
119  void process_data_queue();
120  void process_bbio_queue();
121 
122  bool is_in_queue(bool op, BBilQueue &queue, const char *uid,
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 
158 } // end namespace fawkes
159 
160 #endif
void notify_of_reader_added(const Interface *interface, unsigned int event_instance_serial)
Notify that reader has been added.
Definition: notifier.cpp:559
ListenerRegisterFlag
Flags to constrain listener registration/updates.
Definition: blackboard.h:98
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:44
void notify_of_interface_created(const char *type, const char *id)
Notify that an interface has been created.
Definition: notifier.cpp:368
void update_listener(BlackBoardInterfaceListener *listener, BlackBoard::ListenerRegisterFlag flag)
Update BB event listener.
Definition: notifier.cpp:103
void notify_of_writer_added(const Interface *interface, unsigned int event_instance_serial)
Notify that writer has been added.
Definition: notifier.cpp:463
Fawkes library namespace.
BlackBoardNotifier()
Constructor.
Definition: notifier.cpp:54
void notify_of_writer_removed(const Interface *interface, unsigned int event_instance_serial)
Notify that writer has been removed.
Definition: notifier.cpp:501
void unregister_observer(BlackBoardInterfaceObserver *observer)
Unregister BB interface observer.
Definition: notifier.cpp:341
BlackBoard notifier.
Definition: notifier.h:43
void notify_of_data_change(const Interface *interface)
Notify of data change.
Definition: notifier.cpp:660
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:79
void unregister_listener(BlackBoardInterfaceListener *listener)
Unregister BB interface listener.
Definition: notifier.cpp:180
void notify_of_interface_destroyed(const char *type, const char *id)
Notify that an interface has been destroyed.
Definition: notifier.cpp:403
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:714
virtual ~BlackBoardNotifier()
Destructor.
Definition: notifier.cpp:74
void register_observer(BlackBoardInterfaceObserver *observer)
Register BB interface observer.
Definition: notifier.cpp:279
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:597
void register_listener(BlackBoardInterfaceListener *listener, BlackBoard::ListenerRegisterFlag flag)
Register BB event listener.
Definition: notifier.cpp:90
BlackBoard interface listener.