25 #include "interface_list_maintainer.h" 27 #include <core/threading/mutex_locker.h> 64 std::list<fawkes::Interface *> ifs_tmp = blackboard_->open_multiple_for_reading(
type, pattern);
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);
114 BlackBoardInterfaceListMaintainer::bb_interface_created(
const char *
type,
const char *
id)
throw()
118 pif = blackboard_->open_for_reading(
type,
id);
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);
152 BlackBoardInterfaceListMaintainer::bb_interface_writer_removed(
fawkes::Interface *interface,
153 unsigned int instance_serial)
throw()
155 conditional_close(interface);
164 BlackBoardInterfaceListMaintainer::bb_interface_reader_removed(
fawkes::Interface *interface,
165 unsigned int instance_serial)
throw()
167 conditional_close(interface);
176 BlackBoardInterfaceListMaintainer::conditional_close(
Interface *pif)
throw()
185 logger_->log_info(name_,
"Last on %s, closing", pif->
uid());
193 std::string
uid = pif->
uid();
195 bbil_remove_reader_interface(pif);
196 bbil_remove_writer_interface(pif);
197 blackboard_->update_listener(
this);
198 blackboard_->close(pif);
200 logger_->log_error(name_,
"Failed to unregister or close %s: %s",
uid.c_str(), e.
what());
virtual void register_observer(BlackBoardInterfaceObserver *observer)
Register BB interface observer.
Fawkes library namespace.
void bbil_add_writer_interface(Interface *interface)
Add an interface to the writer addition/removal watch list.
virtual const char * what() const
Get primary string.
virtual void update_listener(BlackBoardInterfaceListener *listener, ListenerRegisterFlag flag=BBIL_FLAG_ALL)
Update BB event listener.
Base class for all Fawkes BlackBoard interfaces.
BlackBoardInterfaceListMaintainer(const char *n, BlackBoard *bb, Logger *l, const char *type, const char *pattern)
Constructor.
void bbil_remove_writer_interface(Interface *interface)
Remove an interface to the writer addition/removal watch list.
RefPtr< Mutex > mutex() const
Get access to the internal mutex.
virtual void register_listener(BlackBoardInterfaceListener *listener, ListenerRegisterFlag flag=BBIL_FLAG_ALL)
Register BB event listener.
void bbio_add_observed_create(const char *type_pattern, const char *id_pattern="*")
Add interface creation type to watch list.
virtual ~BlackBoardInterfaceListMaintainer()
Destructor.
const char * type() const
Get type of interface.
Base class for exceptions in Fawkes.
virtual void unlock() const
Unlock list.
bool has_writer() const
Check if there is a writer for the interface.
const char * uid() const
Get unique identifier of interface.
virtual const char * what_no_backtrace() const
Get primary string (does not implicitly print the back trace).
void bbil_add_reader_interface(Interface *interface)
Add an interface to the reader addition/removal watch list.
unsigned int num_readers() const
Get the number of readers.
The BlackBoard abstract class.
void bbil_remove_reader_interface(Interface *interface)
Remove an interface to the reader addition/removal watch list.
void unlock_list()
unlocks the mutex in this class
BlackBoard interface listener.
virtual void close(Interface *interface)=0
Close interface.