24 #include <blackboard/interface_listener.h> 25 #include <core/exceptions/system.h> 26 #include <core/threading/mutex_locker.h> 27 #include <interface/interface.h> 91 va_start(arg, name_format);
92 if (vasprintf(&__name, name_format, arg) == -1) {
97 __bbil_queue_mutex =
new Mutex();
98 __bbil_maps_mutex =
new Mutex();
107 delete __bbil_queue_mutex;
108 delete __bbil_maps_mutex;
167 unsigned int instance_serial)
throw()
181 unsigned int instance_serial)
throw()
195 unsigned int instance_serial)
throw()
209 unsigned int instance_serial)
throw()
215 BlackBoardInterfaceListener::bbil_queue_add(
QueueEntryType type,
bool op,
223 if (not_in_map.find(interface->
uid()) != not_in_map.end() ) {
224 throw Exception(
"Interface %s already registered (%s)",
225 interface->
uid(), hint);
228 InterfaceQueue::iterator i;
229 for (i = __bbil_queue.begin(); i != __bbil_queue.end(); ++i) {
230 if ((i->type == type) && (*(i->interface) == *interface)) {
231 __bbil_queue.erase(i);
236 __bbil_queue.push_back(qe);
246 bbil_queue_add(
DATA,
true, __bbil_maps.
data, interface,
"data");
256 throw Exception(
"Message received events can only be watched " 257 "on writing interface instances (%s)", interface->
uid());
259 bbil_queue_add(
MESSAGES,
true, __bbil_maps.
messages, interface,
"messages");
272 bbil_queue_add(
READER,
true, __bbil_maps.
reader, interface,
"reader");
285 bbil_queue_add(
WRITER,
true, __bbil_maps.
writer, interface,
"writer");
298 bbil_queue_add(
DATA,
false, __bbil_maps.
data, interface,
"data");
309 bbil_queue_add(
MESSAGES,
false, __bbil_maps.
messages, interface,
"messages");
321 bbil_queue_add(
READER,
false, __bbil_maps.
reader, interface,
"reader");
333 bbil_queue_add(
WRITER,
false, __bbil_maps.
writer, interface,
"writer");
338 BlackBoardInterfaceListener::bbil_acquire_queue()
throw()
340 __bbil_queue_mutex->
lock();
347 __bbil_maps_mutex->
lock();
349 InterfaceQueue::iterator i = __bbil_queue.begin();
350 while (i != __bbil_queue.end()) {
355 __bbil_maps.
data[i->interface->uid()] = i->interface;
356 i = __bbil_queue.erase(i);
362 __bbil_maps.
messages[i->interface->uid()] = i->interface;
363 i = __bbil_queue.erase(i);
369 __bbil_maps.
reader[i->interface->uid()] = i->interface;
370 i = __bbil_queue.erase(i);
376 __bbil_maps.
writer[i->interface->uid()] = i->interface;
377 i = __bbil_queue.erase(i);
389 __bbil_maps.
data.erase(i->interface->uid());
390 i = __bbil_queue.erase(i);
396 __bbil_maps.
messages.erase(i->interface->uid());
397 i = __bbil_queue.erase(i);
403 __bbil_maps.
reader.erase(i->interface->uid());
404 i = __bbil_queue.erase(i);
410 __bbil_maps.
writer.erase(i->interface->uid());
411 i = __bbil_queue.erase(i);
422 __bbil_maps_mutex->
unlock();
423 __bbil_queue_mutex->
unlock();
428 BlackBoardInterfaceListener::bbil_acquire_maps()
throw()
430 __bbil_maps_mutex->
lock();
435 BlackBoardInterfaceListener::bbil_release_maps()
throw()
437 __bbil_queue_mutex->
lock();
439 InterfaceMap::iterator i;
440 for (i = __bbil_maps.
data.begin(); i != __bbil_maps.
data.end(); ++i) {
442 __bbil_queue.push_back(qe);
444 for (i = __bbil_maps.
messages.begin(); i != __bbil_maps.
messages.end(); ++i) {
446 __bbil_queue.push_back(qe);
448 for (i = __bbil_maps.
reader.begin(); i != __bbil_maps.
reader.end(); ++i) {
450 __bbil_queue.push_back(qe);
452 for (i = __bbil_maps.
writer.begin(); i != __bbil_maps.
writer.end(); ++i) {
454 __bbil_queue.push_back(qe);
457 __bbil_maps.
data.clear();
459 __bbil_maps.
reader.clear();
460 __bbil_maps.
writer.clear();
462 __bbil_queue_mutex->
unlock();
463 __bbil_maps_mutex->
unlock();
468 BlackBoardInterfaceListener::bbil_find_interface(
const char *iuid,
472 InterfaceMap::iterator i;
473 if ((i = map.find((
char *)iuid)) != map.end()) {
490 return bbil_find_interface(iuid, __bbil_maps.
data);
503 return bbil_find_interface(iuid, __bbil_maps.
messages);
516 return bbil_find_interface(iuid, __bbil_maps.
reader);
529 return bbil_find_interface(iuid, __bbil_maps.
writer);
ListenerRegisterFlag
Flags to constrain listener registration/updates.
Interface * bbil_reader_interface(const char *iuid)
Get interface instance for given UID.
virtual bool bb_interface_message_received(Interface *interface, Message *message)
BlackBoard message received notification.
Base class for all messages passed through interfaces in Fawkes BlackBoard.
InterfaceMap messages
Message received event subscriptions.
InterfaceMap writer
Writer event subscriptions.
Fawkes library namespace.
void unlock()
Unlock the mutex.
virtual ~BlackBoardInterfaceListener()
Destructor.
Structure to hold maps for active subscriptions.
void bbil_add_writer_interface(Interface *interface)
Add an interface to the writer addition/removal watch list.
virtual void bb_interface_reader_removed(Interface *interface, unsigned int instance_serial)
A reading instance has been closed for a watched interface.
Interface * bbil_message_interface(const char *iuid)
Get interface instance for given UID.
Message received event entry.
InterfaceMap data
Data event subscriptions.
Base class for all Fawkes BlackBoard interfaces.
void bbil_remove_writer_interface(Interface *interface)
Remove an interface to the writer addition/removal watch list.
consider message received events
void bbil_remove_message_interface(Interface *interface)
Remove an interface to the message received watch list.
virtual void bb_interface_data_changed(Interface *interface)
BlackBoard data changed notification.
Base class for exceptions in Fawkes.
InterfaceMap reader
Reader event subscriptions.
BlackBoardInterfaceListener(const char *name_format,...)
Constructor.
QueueEntryType
Queue entry type.
const char * uid() const
Get unique identifier of interface.
void bbil_remove_data_interface(Interface *interface)
Remove an interface to the data modification watch list.
bool is_writer() const
Check if this is a writing instance.
void bbil_add_reader_interface(Interface *interface)
Add an interface to the reader addition/removal watch list.
std::list< QueueEntry > InterfaceQueue
Queue of additions/removal of interfaces.
Interface * bbil_data_interface(const char *iuid)
Get interface instance for given UID.
Interface * bbil_writer_interface(const char *iuid)
Get interface instance for given UID.
virtual void bb_interface_reader_added(Interface *interface, unsigned int instance_serial)
A reading instance has been opened for a watched interface.
virtual void bb_interface_writer_added(Interface *interface, unsigned int instance_serial)
A writing instance has been opened for a watched interface.
Data changed event entry.
void lock()
Lock this mutex.
virtual void bb_interface_writer_removed(Interface *interface, unsigned int instance_serial)
A writing instance has been closed for a watched interface.
const char * bbil_name() const
Get BBIL name.
Mutex mutual exclusion lock.
std::map< std::string, Interface * > InterfaceMap
Map of currently active event subscriptions.
void bbil_add_message_interface(Interface *interface)
Add an interface to the message received watch list.
void bbil_remove_reader_interface(Interface *interface)
Remove an interface to the reader addition/removal watch list.
System ran out of memory and desired operation could not be fulfilled.
void bbil_add_data_interface(Interface *interface)
Add an interface to the data modification watch list.