Fawkes API  Fawkes Development Version
interface_listener.h
1 
2 /***************************************************************************
3  * interface_listener.h - BlackBoard event listener
4  *
5  * Created: Wed Nov 07 23:55:53 2007 (Saw Ella for the first time)
6  * Copyright 2007-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_INTERFACE_LISTENER_H_
25 #define _BLACKBOARD_INTERFACE_LISTENER_H_
26 
27 #include <blackboard/blackboard.h>
28 #include <core/utils/lock_queue.h>
29 #include <utils/misc/string_compare.h>
30 
31 #include <list>
32 #include <map>
33 #include <string>
34 
35 namespace fawkes {
36 
37 class Interface;
38 class Message;
39 class BlackBoardNotifier;
40 
42 {
43  friend BlackBoardNotifier;
44 
45 public:
46  /** Queue entry type. */
47  typedef enum {
48  DATA = 0, ///< Data changed event entry
49  MESSAGES = 1, ///< Message received event entry
50  READER = 2, ///< Reader event entry
51  WRITER = 3 ///< Writer event entry
53 
54  /** Queue entry type. */
55  typedef struct
56  {
57  QueueEntryType type; ///< What type this entry concerns
58  bool op; ///< true to add, false to remove
59  Interface * interface; ///< interface this entry concerns
60  } QueueEntry;
61 
62  /** Queue of additions/removal of interfaces. */
63  typedef std::list<QueueEntry> InterfaceQueue;
64 
65  /** Map of currently active event subscriptions. */
66  typedef std::map<std::string, Interface *> InterfaceMap;
67 
68  /** Structure to hold maps for active subscriptions. */
69  typedef struct
70  {
71  InterfaceMap data; ///< Data event subscriptions
72  InterfaceMap messages; ///< Message received event subscriptions
73  InterfaceMap reader; ///< Reader event subscriptions
74  InterfaceMap writer; ///< Writer event subscriptions
75  } InterfaceMaps;
76 
77  BlackBoardInterfaceListener(const char *name_format, ...);
79 
80  const char *bbil_name() const;
81 
82  virtual void bb_interface_data_refreshed(Interface *interface) noexcept;
83  virtual void bb_interface_data_changed(Interface *interface) noexcept;
84  virtual bool bb_interface_message_received(Interface *interface, Message *message) noexcept;
85  virtual void bb_interface_writer_added(Interface *interface, Uuid instance_serial) noexcept;
86  virtual void bb_interface_writer_removed(Interface *interface, Uuid instance_serial) noexcept;
87  virtual void bb_interface_reader_added(Interface *interface, Uuid instance_serial) noexcept;
88  virtual void bb_interface_reader_removed(Interface *interface, Uuid instance_serial) noexcept;
89 
90 protected:
91  void bbil_add_data_interface(Interface *interface);
92  void bbil_add_message_interface(Interface *interface);
93  void bbil_add_reader_interface(Interface *interface);
94  void bbil_add_writer_interface(Interface *interface);
95 
96  void bbil_remove_data_interface(Interface *interface);
98  void bbil_remove_reader_interface(Interface *interface);
99  void bbil_remove_writer_interface(Interface *interface);
100 
101  Interface *bbil_data_interface(const char *iuid) noexcept;
102  Interface *bbil_message_interface(const char *iuid) noexcept;
103  Interface *bbil_reader_interface(const char *iuid) noexcept;
104  Interface *bbil_writer_interface(const char *iuid) noexcept;
105 
106 private:
107  void bbil_queue_add(QueueEntryType type,
108  bool op,
109  InterfaceMap & not_in_map,
110  Interface * interface,
111  const char * hint);
112  Interface *bbil_find_interface(const char *iuid, InterfaceMap &map);
113 
114  const InterfaceQueue &bbil_acquire_queue() noexcept;
115  void bbil_release_queue(BlackBoard::ListenerRegisterFlag flag) noexcept;
116 
117  const InterfaceMaps &bbil_acquire_maps() noexcept;
118  void bbil_release_maps() noexcept;
119 
120 private:
121  Mutex *bbil_queue_mutex_;
122  Mutex *bbil_maps_mutex_;
123 
124  InterfaceMaps bbil_maps_;
125  InterfaceQueue bbil_queue_;
126 
127  char *name_;
128 };
129 
130 } // end namespace fawkes
131 
132 #endif
BlackBoard interface listener.
Interface * bbil_reader_interface(const char *iuid) noexcept
Get interface instance for given UID.
virtual void bb_interface_writer_added(Interface *interface, Uuid instance_serial) noexcept
A writing instance has been opened for a watched interface.
@ MESSAGES
Message received event entry.
@ DATA
Data changed event entry.
void bbil_add_reader_interface(Interface *interface)
Add an interface to the reader addition/removal watch list.
void bbil_remove_reader_interface(Interface *interface)
Remove an interface to the reader addition/removal watch list.
void bbil_add_message_interface(Interface *interface)
Add an interface to the message received watch list.
void bbil_remove_writer_interface(Interface *interface)
Remove an interface to the writer addition/removal watch list.
std::map< std::string, Interface * > InterfaceMap
Map of currently active event subscriptions.
virtual bool bb_interface_message_received(Interface *interface, Message *message) noexcept
BlackBoard message received notification.
virtual void bb_interface_data_refreshed(Interface *interface) noexcept
BlackBoard data refreshed notification.
Interface * bbil_message_interface(const char *iuid) noexcept
Get interface instance for given UID.
void bbil_remove_message_interface(Interface *interface)
Remove an interface to the message received watch list.
virtual void bb_interface_data_changed(Interface *interface) noexcept
BlackBoard data changed notification.
void bbil_add_writer_interface(Interface *interface)
Add an interface to the writer addition/removal watch list.
virtual void bb_interface_writer_removed(Interface *interface, Uuid instance_serial) noexcept
A writing instance has been closed for a watched interface.
virtual void bb_interface_reader_added(Interface *interface, Uuid instance_serial) noexcept
A reading instance has been opened for a watched interface.
const char * bbil_name() const
Get BBIL name.
Interface * bbil_writer_interface(const char *iuid) noexcept
Get interface instance for given UID.
std::list< QueueEntry > InterfaceQueue
Queue of additions/removal of interfaces.
void bbil_remove_data_interface(Interface *interface)
Remove an interface to the data modification watch list.
virtual void bb_interface_reader_removed(Interface *interface, Uuid instance_serial) noexcept
A reading instance has been closed for a watched interface.
Interface * bbil_data_interface(const char *iuid) noexcept
Get interface instance for given UID.
void bbil_add_data_interface(Interface *interface)
Add an interface to the data modification watch list.
BlackBoardInterfaceListener(const char *name_format,...)
Constructor.
virtual ~BlackBoardInterfaceListener()
Destructor.
BlackBoard notifier.
Definition: notifier.h:44
The BlackBoard abstract class.
Definition: blackboard.h:46
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.
Structure to hold maps for active subscriptions.
InterfaceMap writer
Writer event subscriptions.
InterfaceMap messages
Message received event subscriptions.
InterfaceMap data
Data event subscriptions.
InterfaceMap reader
Reader event subscriptions.
QueueEntryType type
What type this entry concerns.
Interface * interface
interface this entry concerns