25#include "interface_list_maintainer.h"
27#include <core/threading/mutex_locker.h>
47BlackBoardInterfaceListMaintainer::BlackBoardInterfaceListMaintainer(
const char *n,
65 std::list<fawkes::Interface *>::iterator pif_tmp;
66 for (pif_tmp = ifs_tmp.begin(); pif_tmp != ifs_tmp.end(); ++pif_tmp) {
68 std::string id_list_tmp((*pif_tmp)->id());
69 bool is_in_list =
false;
71 for (pif_class = ifs_.begin(); pif_class != ifs_.end(); ++pif_class) {
72 std::string id_list_class((*pif_class)->id());
74 if (id_list_tmp.compare(id_list_class) == 0) {
75 blackboard_->
close(*pif_tmp);
81 ifs_.push_back((*pif_tmp));
99 for (pif = ifs_.begin(); pif != ifs_.end(); ++pif) {
103 blackboard_->
close(*pif);
114BlackBoardInterfaceListMaintainer::bb_interface_created(
const char *type,
const char *
id)
noexcept
118 pif = blackboard_->open_for_reading(type,
id);
121 logger_->log_warn(name_,
"Failed to open %s:%s: %s", type,
id, e.
what_no_backtrace());
126 bbil_add_reader_interface(pif);
127 bbil_add_writer_interface(pif);
128 blackboard_->update_listener(
this);
130 logger_->log_warn(name_,
"Failed to register for %s:%s: %s", type,
id, e.
what());
132 bbil_remove_reader_interface(pif);
133 bbil_remove_writer_interface(pif);
134 blackboard_->update_listener(
this);
135 blackboard_->close(pif);
138 name_,
"Failed to deregister %s:%s during error recovery: %s", type,
id, e.
what());
143 ifs_.push_back_locked(pif);
152BlackBoardInterfaceListMaintainer::bb_interface_writer_removed(
156 conditional_close(interface);
165BlackBoardInterfaceListMaintainer::bb_interface_reader_removed(
169 conditional_close(interface);
178BlackBoardInterfaceListMaintainer::conditional_close(
Interface *pif)
noexcept
187 logger_->log_info(name_,
"Last on %s, closing", pif->
uid());
195 std::string uid = pif->
uid();
197 bbil_remove_reader_interface(pif);
198 bbil_remove_writer_interface(pif);
199 blackboard_->update_listener(
this);
200 blackboard_->close(pif);
202 logger_->log_error(name_,
"Failed to unregister or close %s: %s", uid.c_str(), e.
what());
virtual ~BlackBoardInterfaceListMaintainer()
Destructor.
void unlock_list()
unlocks the mutex in this class
BlackBoard interface listener.
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_remove_writer_interface(Interface *interface)
Remove an interface to the writer addition/removal watch list.
void bbil_add_writer_interface(Interface *interface)
Add an interface to the writer addition/removal watch list.
void bbio_add_observed_create(const char *type_pattern, const char *id_pattern="*") noexcept
Add interface creation type to watch list.
The BlackBoard abstract class.
virtual void update_listener(BlackBoardInterfaceListener *listener, ListenerRegisterFlag flag=BBIL_FLAG_ALL)
Update BB event listener.
virtual void register_observer(BlackBoardInterfaceObserver *observer)
Register BB interface observer.
virtual std::list< Interface * > open_multiple_for_reading(const char *type_pattern, const char *id_pattern="*", const char *owner=NULL)=0
Open multiple interfaces for reading.
virtual void register_listener(BlackBoardInterfaceListener *listener, ListenerRegisterFlag flag=BBIL_FLAG_ALL)
Register BB event listener.
virtual void close(Interface *interface)=0
Close interface.
Base class for exceptions in Fawkes.
virtual const char * what() const noexcept
Get primary string.
virtual const char * what_no_backtrace() const noexcept
Get primary string (does not implicitly print the back trace).
Base class for all Fawkes BlackBoard interfaces.
const char * uid() const
Get unique identifier of interface.
unsigned int num_readers() const
Get the number of readers.
bool has_writer() const
Check if there is a writer for the interface.
virtual void unlock() const
Unlock list.
RefPtr< Mutex > mutex() const
Get access to the internal mutex.
void unlock()
Unlock the mutex.
A convenience class for universally unique identifiers (UUIDs).
Fawkes library namespace.