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_;
160 unsigned int instance_serial)
throw()
173 unsigned int instance_serial)
throw()
186 unsigned int instance_serial)
throw()
199 unsigned int instance_serial)
throw()
204 BlackBoardInterfaceListener::bbil_queue_add(QueueEntryType type,
206 InterfaceMap & not_in_map,
213 if (not_in_map.find(interface->
uid()) != not_in_map.end()) {
214 throw Exception(
"Interface %s already registered (%s)", interface->
uid(), hint);
217 InterfaceQueue::iterator i;
218 for (i = bbil_queue_.begin(); i != bbil_queue_.end(); ++i) {
219 if ((i->type == type) && (*(i->interface) == *interface)) {
220 bbil_queue_.erase(i);
224 QueueEntry qe = {type, op, interface};
225 bbil_queue_.push_back(qe);
234 bbil_queue_add(
DATA,
true, bbil_maps_.
data, interface,
"data");
244 throw Exception(
"Message received events can only be watched " 245 "on writing interface instances (%s)",
260 bbil_queue_add(
READER,
true, bbil_maps_.
reader, interface,
"reader");
272 bbil_queue_add(
WRITER,
true, bbil_maps_.
writer, interface,
"writer");
283 bbil_queue_add(
DATA,
false, bbil_maps_.
data, interface,
"data");
294 bbil_queue_add(
MESSAGES,
false, bbil_maps_.
messages, interface,
"messages");
305 bbil_queue_add(
READER,
false, bbil_maps_.
reader, interface,
"reader");
316 bbil_queue_add(
WRITER,
false, bbil_maps_.
writer, interface,
"writer");
320 BlackBoardInterfaceListener::bbil_acquire_queue() throw()
322 bbil_queue_mutex_->
lock();
329 bbil_maps_mutex_->lock();
331 InterfaceQueue::iterator i = bbil_queue_.begin();
332 while (i != bbil_queue_.end()) {
337 bbil_maps_.data[i->interface->uid()] = i->interface;
338 i = bbil_queue_.erase(i);
345 bbil_maps_.messages[i->interface->uid()] = i->interface;
346 i = bbil_queue_.erase(i);
353 bbil_maps_.reader[i->interface->uid()] = i->interface;
354 i = bbil_queue_.erase(i);
361 bbil_maps_.writer[i->interface->uid()] = i->interface;
362 i = bbil_queue_.erase(i);
373 bbil_maps_.data.erase(i->interface->uid());
374 i = bbil_queue_.erase(i);
381 bbil_maps_.messages.erase(i->interface->uid());
382 i = bbil_queue_.erase(i);
389 bbil_maps_.reader.erase(i->interface->uid());
390 i = bbil_queue_.erase(i);
397 bbil_maps_.writer.erase(i->interface->uid());
398 i = bbil_queue_.erase(i);
408 bbil_maps_mutex_->unlock();
409 bbil_queue_mutex_->unlock();
412 const BlackBoardInterfaceListener::InterfaceMaps &
413 BlackBoardInterfaceListener::bbil_acquire_maps() throw()
415 bbil_maps_mutex_->
lock();
420 BlackBoardInterfaceListener::bbil_release_maps() throw()
422 bbil_queue_mutex_->
lock();
424 InterfaceMap::iterator i;
425 for (i = bbil_maps_.
data.begin(); i != bbil_maps_.
data.end(); ++i) {
426 QueueEntry qe = {
DATA,
true, i->second};
427 bbil_queue_.push_back(qe);
429 for (i = bbil_maps_.
messages.begin(); i != bbil_maps_.
messages.end(); ++i) {
430 QueueEntry qe = {
MESSAGES,
true, i->second};
431 bbil_queue_.push_back(qe);
433 for (i = bbil_maps_.
reader.begin(); i != bbil_maps_.
reader.end(); ++i) {
434 QueueEntry qe = {
READER,
true, i->second};
435 bbil_queue_.push_back(qe);
437 for (i = bbil_maps_.
writer.begin(); i != bbil_maps_.
writer.end(); ++i) {
438 QueueEntry qe = {
WRITER,
true, i->second};
439 bbil_queue_.push_back(qe);
442 bbil_maps_.
data.clear();
444 bbil_maps_.
reader.clear();
445 bbil_maps_.
writer.clear();
447 bbil_queue_mutex_->
unlock();
448 bbil_maps_mutex_->
unlock();
452 BlackBoardInterfaceListener::bbil_find_interface(
const char *iuid, InterfaceMap &map)
454 MutexLocker lock(bbil_maps_mutex_);
455 InterfaceMap::iterator i;
456 if ((i = map.find((
char *)iuid)) != map.end()) {
472 return bbil_find_interface(iuid, bbil_maps_.data);
484 return bbil_find_interface(iuid, bbil_maps_.messages);
496 return bbil_find_interface(iuid, bbil_maps_.reader);
508 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.
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.
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.
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.