notifier.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __BLACKBOARD_NOTIFIER_H_
00025 #define __BLACKBOARD_NOTIFIER_H_
00026
00027 #include <blackboard/interface_listener.h>
00028 #include <blackboard/interface_observer.h>
00029
00030 #include <core/utils/rwlock_map.h>
00031
00032 #include <list>
00033 #include <string>
00034 #include <utility>
00035
00036 namespace fawkes {
00037
00038 class Interface;
00039 class Message;
00040 class Mutex;
00041 class WaitCondition;
00042
00043 class BlackBoardNotifier
00044 {
00045 public:
00046 BlackBoardNotifier();
00047 virtual ~BlackBoardNotifier();
00048
00049 void register_listener(BlackBoardInterfaceListener *listener, unsigned int flags);
00050 void unregister_listener(BlackBoardInterfaceListener *listener);
00051
00052 void register_observer(BlackBoardInterfaceObserver *observer, unsigned int flags);
00053 void unregister_observer(BlackBoardInterfaceObserver *observer);
00054
00055 void notify_of_data_change(const Interface *interface);
00056 bool notify_of_message_received(const Interface *interface, Message *message);
00057 void notify_of_interface_created(const char *type, const char *id) throw();
00058 void notify_of_interface_destroyed(const char *type, const char *id) throw();
00059 void notify_of_writer_added(const Interface *interface,
00060 unsigned int event_instance_serial) throw();
00061 void notify_of_writer_removed(const Interface *interface,
00062 unsigned int event_instance_serial) throw();
00063 void notify_of_reader_added(const Interface *interface,
00064 unsigned int event_instance_serial) throw();
00065 void notify_of_reader_removed(const Interface *interface,
00066 unsigned int event_instance_serial) throw();
00067
00068 private:
00069 typedef std::list< BlackBoardInterfaceListener * > BBilList;
00070 typedef std::map< std::string, BBilList > BBilMap;
00071
00072 typedef std::pair< bool, BlackBoardInterfaceListener *> BBilQueueEntry;
00073 typedef std::list< BBilQueueEntry > BBilQueue;
00074
00075 typedef std::map< std::string, BlackBoardInterfaceListener * > BBilMessageLockMap;
00076 typedef std::map< std::string, BlackBoardInterfaceListener * >::iterator BBilMessageLockMapIterator;
00077
00078 typedef std::pair<BlackBoardInterfaceObserver *, std::list<std::string> > BBioPair;
00079 typedef std::list< BBioPair> BBioList;
00080 typedef std::map< std::string, BBioList > BBioMap;
00081
00082
00083 typedef std::pair< unsigned int, BlackBoardInterfaceObserver *> BBioQueueEntry;
00084 typedef std::list< BBioQueueEntry > BBioQueue;
00085
00086 typedef BBilList::iterator BBilListIterator;
00087 typedef BBilMap::iterator BBilMapIterator;
00088
00089 typedef BBioList::iterator BBioListIterator;
00090 typedef BBioMap::iterator BBioMapIterator;
00091
00092 void add_listener(BlackBoardInterfaceListener *listener,
00093 BlackBoardInterfaceListener::InterfaceLockMap *im,
00094 BBilMap &ilmap);
00095
00096 void remove_listener(BlackBoardInterfaceListener *listener,
00097 Mutex *mutex, unsigned int events,
00098 BBilQueue &queue, BBilMap &ilmap);
00099 void remove_listener(BBilMap &ifmap, BlackBoardInterfaceListener *listener);
00100 void remove_message_listener(BlackBoardInterfaceListener *listener);
00101 void remove_message_listener_map(BlackBoardInterfaceListener *listener);
00102
00103 void add_observer(BlackBoardInterfaceObserver *observer,
00104 BlackBoardInterfaceObserver::ObservedInterfaceLockMap *its,
00105 BBioMap &bbiomap);
00106
00107 void remove_observer(BBioMap &iomap, BlackBoardInterfaceObserver *observer);
00108
00109 void process_writer_queue();
00110 void process_reader_queue();
00111 void process_data_queue();
00112 void process_bbio_queue();
00113
00114 BBilMap __bbil_data;
00115 BBilMap __bbil_reader;
00116 BBilMap __bbil_writer;
00117 BBilMessageLockMap __bbil_messages;
00118
00119 Mutex *__bbil_unregister_mutex;
00120 WaitCondition *__bbil_unregister_waitcond;
00121 BBilQueue __bbil_unregister_queue;
00122
00123 Mutex *__bbil_writer_mutex;
00124 WaitCondition *__bbil_writer_waitcond;
00125 unsigned int __bbil_writer_events;
00126 BBilQueue __bbil_writer_queue;
00127
00128 Mutex *__bbil_reader_mutex;
00129 WaitCondition *__bbil_reader_waitcond;
00130 unsigned int __bbil_reader_events;
00131 BBilQueue __bbil_reader_queue;
00132
00133 Mutex *__bbil_data_mutex;
00134 WaitCondition *__bbil_data_waitcond;
00135 unsigned int __bbil_data_events;
00136 BBilQueue __bbil_data_queue;
00137
00138 Mutex *__bbil_messages_mutex;
00139 WaitCondition *__bbil_messages_waitcond;
00140 unsigned int __bbil_messages_events;
00141 BBilQueue __bbil_messages_queue;
00142
00143 BBioMap __bbio_created;
00144 BBioMap __bbio_destroyed;
00145
00146 Mutex *__bbio_mutex;
00147 WaitCondition *__bbio_waitcond;
00148 unsigned int __bbio_events;
00149 BBioQueue __bbio_queue;
00150
00151 };
00152
00153 }
00154
00155 #endif