Fawkes API
Fawkes Development Version
|
Synchronize two interfaces. More...
#include "sync_listener.h"
Public Member Functions | |
SyncInterfaceListener (fawkes::Logger *logger, fawkes::Interface *reader, fawkes::Interface *writer, fawkes::BlackBoard *reader_bb, fawkes::BlackBoard *writer_bb) | |
Constructor. More... | |
virtual | ~SyncInterfaceListener () |
Destructor. More... | |
virtual bool | bb_interface_message_received (fawkes::Interface *interface, fawkes::Message *message) throw () |
BlackBoard message received notification. More... | |
virtual void | bb_interface_data_changed (fawkes::Interface *interface) throw () |
BlackBoard data changed notification. More... | |
![]() | |
BlackBoardInterfaceListener (const char *name_format,...) | |
Constructor. More... | |
virtual | ~BlackBoardInterfaceListener () |
Destructor. More... | |
const char * | bbil_name () const |
Get BBIL name. More... | |
virtual void | bb_interface_writer_added (Interface *interface, unsigned int instance_serial) throw () |
A writing instance has been opened for a watched interface. More... | |
virtual void | bb_interface_writer_removed (Interface *interface, unsigned int instance_serial) throw () |
A writing instance has been closed for a watched interface. More... | |
virtual void | bb_interface_reader_added (Interface *interface, unsigned int instance_serial) throw () |
A reading instance has been opened for a watched interface. More... | |
virtual void | bb_interface_reader_removed (Interface *interface, unsigned int instance_serial) throw () |
A reading instance has been closed for a watched interface. More... | |
Additional Inherited Members | |
![]() | |
enum | QueueEntryType { DATA = 0, MESSAGES = 1, READER = 2, WRITER = 3 } |
Queue entry type. More... | |
typedef std::list< QueueEntry > | InterfaceQueue |
Queue of additions/removal of interfaces. More... | |
typedef std::map< std::string, Interface * > | InterfaceMap |
Map of currently active event subscriptions. More... | |
![]() | |
void | bbil_add_data_interface (Interface *interface) |
Add an interface to the data modification watch list. More... | |
void | bbil_add_message_interface (Interface *interface) |
Add an interface to the message received watch list. More... | |
void | bbil_add_reader_interface (Interface *interface) |
Add an interface to the reader addition/removal watch list. More... | |
void | bbil_add_writer_interface (Interface *interface) |
Add an interface to the writer addition/removal watch list. More... | |
void | bbil_remove_data_interface (Interface *interface) |
Remove an interface to the data modification watch list. More... | |
void | bbil_remove_message_interface (Interface *interface) |
Remove an interface to the message received watch list. More... | |
void | bbil_remove_reader_interface (Interface *interface) |
Remove an interface to the reader addition/removal watch list. More... | |
void | bbil_remove_writer_interface (Interface *interface) |
Remove an interface to the writer addition/removal watch list. More... | |
Interface * | bbil_data_interface (const char *iuid) throw () |
Get interface instance for given UID. More... | |
Interface * | bbil_message_interface (const char *iuid) throw () |
Get interface instance for given UID. More... | |
Interface * | bbil_reader_interface (const char *iuid) throw () |
Get interface instance for given UID. More... | |
Interface * | bbil_writer_interface (const char *iuid) throw () |
Get interface instance for given UID. More... | |
Synchronize two interfaces.
This class synchronizes two interfaces, a reading and a writing instance of the same type. To accomplish this it listens for data changed and message events and forwards them as appropriate to "the other side".
Definition at line 33 of file sync_listener.h.
SyncInterfaceListener::SyncInterfaceListener | ( | fawkes::Logger * | logger, |
fawkes::Interface * | reader, | ||
fawkes::Interface * | writer, | ||
fawkes::BlackBoard * | reader_bb, | ||
fawkes::BlackBoard * | writer_bb | ||
) |
Constructor.
Automatically registers the listener with the (two) blackboards as appropriate. It also automatically unregisters in the destructor.
logger | logger to write informational output to |
reader | reading interface instance |
writer | writing interface instance of the same type as reader |
reader_bb | the BlackBoard instance the reading instance has been created on |
writer_bb | the BlackBoard instance the writing instance has been created on |
Definition at line 49 of file sync_listener.cpp.
References fawkes::BlackBoardInterfaceListener::bbil_add_data_interface(), fawkes::BlackBoardInterfaceListener::bbil_add_message_interface(), and fawkes::BlackBoard::register_listener().
|
virtual |
Destructor.
Definition at line 71 of file sync_listener.cpp.
References fawkes::BlackBoard::unregister_listener().
|
virtual |
BlackBoard data changed notification.
This is called whenever the data in an interface that you registered for is modified. This happens if a writer calls the Interface::write() method.
interface | interface instance that you supplied to bbil_add_data_interface() |
Reimplemented from fawkes::BlackBoardInterfaceListener.
Definition at line 106 of file sync_listener.cpp.
References fawkes::BlackBoardInterfaceListener::bbil_name(), fawkes::Interface::copy_values(), fawkes::Logger::log_error(), fawkes::Interface::read(), and fawkes::Interface::write().
|
virtual |
BlackBoard message received notification.
This is called whenever a message is received for this interface. This method is only called for writing instances of an interface, never on reading instances. If you have processed the message already, you can order that the message is not enqueued by returning false. Returning true will enqueue the message as usual. You should only do very (very!) quick tasks directly in this method, as it is out of the regular thread context and can harm performance of other plugins and the system as a whole. Note that if you decide to return false the message is not referenced. If you want to keep it longer you have to ref() it by yourself. An example where this would really make sense is a "STOP" message for the motor, which needs to be processed ASAP and maybe even waiting a couple of miliseconds for the next cycle is not acceptable.
interface | interface instance that you supplied to bbil_add_message_interface() |
message | the message that was sent |
Reimplemented from fawkes::BlackBoardInterfaceListener.
Definition at line 79 of file sync_listener.cpp.
References fawkes::BlackBoardInterfaceListener::bbil_name(), fawkes::Message::clone(), fawkes::Message::id(), fawkes::Logger::log_error(), fawkes::Interface::msgq_enqueue(), fawkes::RefCount::ref(), fawkes::Message::set_hops(), and fawkes::RefCount::unref().