24#include <blackboard/interface_listener.h>
25#include <core/exceptions/system.h>
26#include <core/threading/mutex_locker.h>
27#include <interface/interface.h>
89 va_start(arg, name_format);
90 if (vasprintf(&name_, name_format, arg) == -1) {
95 bbil_queue_mutex_ =
new Mutex();
96 bbil_maps_mutex_ =
new Mutex();
104 delete bbil_queue_mutex_;
105 delete bbil_maps_mutex_;
176 Uuid instance_serial)
noexcept
189 Uuid instance_serial)
noexcept
202 Uuid instance_serial)
noexcept
215 Uuid instance_serial)
noexcept
220BlackBoardInterfaceListener::bbil_queue_add(QueueEntryType type,
222 InterfaceMap & not_in_map,
229 if (not_in_map.find(interface->
uid()) != not_in_map.end()) {
230 throw Exception(
"Interface %s already registered (%s)", interface->
uid(), hint);
233 InterfaceQueue::iterator i;
234 for (i = bbil_queue_.begin(); i != bbil_queue_.end(); ++i) {
235 if ((i->type == type) && (*(i->interface) == *interface)) {
236 bbil_queue_.erase(i);
240 QueueEntry qe = {type, op, interface};
241 bbil_queue_.push_back(qe);
250 bbil_queue_add(
DATA,
true, bbil_maps_.
data, interface,
"data");
260 throw Exception(
"Message received events can only be watched "
261 "on writing interface instances (%s)",
276 bbil_queue_add(
READER,
true, bbil_maps_.
reader, interface,
"reader");
288 bbil_queue_add(
WRITER,
true, bbil_maps_.
writer, interface,
"writer");
299 bbil_queue_add(
DATA,
false, bbil_maps_.
data, interface,
"data");
310 bbil_queue_add(
MESSAGES,
false, bbil_maps_.
messages, interface,
"messages");
321 bbil_queue_add(
READER,
false, bbil_maps_.
reader, interface,
"reader");
332 bbil_queue_add(
WRITER,
false, bbil_maps_.
writer, interface,
"writer");
336BlackBoardInterfaceListener::bbil_acquire_queue() noexcept
338 bbil_queue_mutex_->
lock();
345 bbil_maps_mutex_->lock();
347 InterfaceQueue::iterator i = bbil_queue_.begin();
348 while (i != bbil_queue_.end()) {
353 bbil_maps_.data[i->interface->uid()] = i->interface;
354 i = bbil_queue_.erase(i);
361 bbil_maps_.messages[i->interface->uid()] = i->interface;
362 i = bbil_queue_.erase(i);
369 bbil_maps_.reader[i->interface->uid()] = i->interface;
370 i = bbil_queue_.erase(i);
377 bbil_maps_.writer[i->interface->uid()] = i->interface;
378 i = bbil_queue_.erase(i);
389 bbil_maps_.data.erase(i->interface->uid());
390 i = bbil_queue_.erase(i);
397 bbil_maps_.messages.erase(i->interface->uid());
398 i = bbil_queue_.erase(i);
405 bbil_maps_.reader.erase(i->interface->uid());
406 i = bbil_queue_.erase(i);
413 bbil_maps_.writer.erase(i->interface->uid());
414 i = bbil_queue_.erase(i);
424 bbil_maps_mutex_->unlock();
425 bbil_queue_mutex_->unlock();
428const BlackBoardInterfaceListener::InterfaceMaps &
429BlackBoardInterfaceListener::bbil_acquire_maps() noexcept
431 bbil_maps_mutex_->
lock();
436BlackBoardInterfaceListener::bbil_release_maps() noexcept
438 bbil_queue_mutex_->
lock();
440 InterfaceMap::iterator i;
441 for (i = bbil_maps_.
data.begin(); i != bbil_maps_.
data.end(); ++i) {
442 QueueEntry qe = {
DATA,
true, i->second};
443 bbil_queue_.push_back(qe);
445 for (i = bbil_maps_.
messages.begin(); i != bbil_maps_.
messages.end(); ++i) {
446 QueueEntry qe = {
MESSAGES,
true, i->second};
447 bbil_queue_.push_back(qe);
449 for (i = bbil_maps_.
reader.begin(); i != bbil_maps_.
reader.end(); ++i) {
450 QueueEntry qe = {
READER,
true, i->second};
451 bbil_queue_.push_back(qe);
453 for (i = bbil_maps_.
writer.begin(); i != bbil_maps_.
writer.end(); ++i) {
454 QueueEntry qe = {
WRITER,
true, i->second};
455 bbil_queue_.push_back(qe);
458 bbil_maps_.
data.clear();
460 bbil_maps_.
reader.clear();
461 bbil_maps_.
writer.clear();
463 bbil_queue_mutex_->
unlock();
464 bbil_maps_mutex_->
unlock();
468BlackBoardInterfaceListener::bbil_find_interface(
const char *iuid, InterfaceMap &map)
470 MutexLocker lock(bbil_maps_mutex_);
471 InterfaceMap::iterator i;
472 if ((i = map.find((
char *)iuid)) != map.end()) {
488 return bbil_find_interface(iuid, bbil_maps_.data);
500 return bbil_find_interface(iuid, bbil_maps_.messages);
512 return bbil_find_interface(iuid, bbil_maps_.reader);
524 return bbil_find_interface(iuid, bbil_maps_.writer);
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.
@ WRITER
Writer event entry.
@ READER
Reader event entry.
@ 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.
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.
ListenerRegisterFlag
Flags to constrain listener registration/updates.
@ BBIL_FLAG_READER
consider reader events
@ BBIL_FLAG_DATA
consider data events
@ BBIL_FLAG_WRITER
consider writer events
@ BBIL_FLAG_MESSAGES
consider message received events
Base class for exceptions in Fawkes.
Base class for all Fawkes BlackBoard interfaces.
bool is_writer() const
Check if this is a writing instance.
const char * uid() const
Get unique identifier of interface.
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Mutex mutual exclusion lock.
void lock()
Lock this mutex.
void unlock()
Unlock the mutex.
System ran out of memory and desired operation could not be fulfilled.
A convenience class for universally unique identifiers (UUIDs).
Fawkes library namespace.
InterfaceMap writer
Writer event subscriptions.
InterfaceMap messages
Message received event subscriptions.
InterfaceMap data
Data event subscriptions.
InterfaceMap reader
Reader event subscriptions.