gusimplewhiteboard
whiteboard_watcher Class Reference

This class provides a subscription implementation for the 'simple' whiteboard, aka the 'typed' whiteboard. More...

#include <guwhiteboardwatcher.h>

Collaboration diagram for whiteboard_watcher:

Public Member Functions

 whiteboard_watcher (gu_simple_whiteboard_descriptor *wbd=NULLPTR)
 Constructor, sets up the dispatch queues for handling callbacks. More...
 
 ~whiteboard_watcher ()
 Destructor, release whiteboard objects and dispatch queues. More...
 
void subscribe (WBFunctorBase *func)
 Allows you to subscribe to a specific whiteboard type and get callbacks when that type is updated. More...
 
void unsubscribe (guWhiteboard ::wb_types t)
 Stop getting callbacks for a particular whiteboard type. More...
 
void receive_callback ()
 Internal function, this is what gets triggered by the underlying whiteboard, it then checks its list of subscribed types and issues callback functions to subscribed modules. More...
 

Detailed Description

This class provides a subscription implementation for the 'simple' whiteboard, aka the 'typed' whiteboard.

This class allows you to 'subscribe' to changes on the Whiteboard. Specifically call you can call the subscribe method, with the desired 'type' and a callback pointer. This class will monitor any subscribed 'types' and call the callback functions when the data related to those 'types' is updated. To be clear, callbacks will be issued if the data is updated on the Whiteboard, even if it is the same data. The act of the data being posted to the Whiteboard is what triggers callbacks. This is designed for event-triggered systems and different data fetching methods should be used for time-triggered systems.

Examples

A SUBSCRIBE macro is defined for convenience

wb = new whiteboard_watcher(); //create the watcher object
//wb = whiteboard_watcher
//Say = the WB type to subscribe to
//GUNaoSpeech = the class the callback belongs to
//GUNaoSpeech::whiteboard_callback = the callback function
SUBSCRIBE(wb, Say, GUNaoSpeech, GUNaoSpeech::whiteboard_callback);

The long form of the subscribe looks like this:

wb = new whiteboard_watcher(); //create the watcher object
((wb)->subscribe(Say_WBFunctor<GUNaoSpeech>::bind(this, &GUNaoSpeech::whiteboard_callback, kSay_v)));

Definition at line 104 of file guwhiteboardwatcher.h.

Constructor & Destructor Documentation

◆ whiteboard_watcher()

whiteboard_watcher::whiteboard_watcher ( gu_simple_whiteboard_descriptor wbd = NULLPTR)
inline

Constructor, sets up the dispatch queues for handling callbacks.

Parameters
wbdYou can pass a specific pointer to a whiteboard object if you wish. By default a pointer to the default whiteboard is used.

Definition at line 117 of file guwhiteboardwatcher.h.

References gsw_whiteboard_s::callback, gsw_whiteboard_s::context, DISPATCH_QUEUE_NAME_WB, DISPATCH_QUEUE_SERIAL, and get_local_singleton_whiteboard().

◆ ~whiteboard_watcher()

whiteboard_watcher::~whiteboard_watcher ( )
inline

Destructor, release whiteboard objects and dispatch queues.

Definition at line 144 of file guwhiteboardwatcher.h.

References gsw_whiteboard_s::callback, gsw_whiteboard_s::exit_monitor, and gsw_free_whiteboard().

Member Function Documentation

◆ receive_callback()

void whiteboard_watcher::receive_callback ( )
inline

Internal function, this is what gets triggered by the underlying whiteboard, it then checks its list of subscribed types and issues callback functions to subscribed modules.

Definition at line 219 of file guwhiteboardwatcher.h.

References gsw_simple_whiteboard_s::event_counters, WBFunctorBase::get_event_count(), gsw_procure(), GSW_SEM_CALLBACK, GSW_TOTAL_MESSAGE_TYPES, gsw_simple_whiteboard_s::indexes, kwb_reserved_SubscribeToAllTypes_v, gsw_whiteboard_s::sem, WBFunctorBase::type(), and gsw_whiteboard_s::wb.

◆ subscribe()

void whiteboard_watcher::subscribe ( WBFunctorBase func)
inline

Allows you to subscribe to a specific whiteboard type and get callbacks when that type is updated.

You will still get a callback if the type is updated and the data didn't change.

Parameters
functhe callback container object. I suggest using the macro SUBSCRIBE (see example at the top of this file)

Definition at line 166 of file guwhiteboardwatcher.h.

References gsw_simple_whiteboard_s::event_counters, gsw_add_process(), gsw_add_wbd_signal_handler(), gsw_procure(), GSW_SEM_CALLBACK, GSW_TOTAL_MESSAGE_TYPES, gsw_vacate(), WBFunctorBase::is_simple_wb_version(), kwb_reserved_SubscribeToAllTypes_v, gsw_whiteboard_s::sem, WBFunctorBase::set_event_count(), WBFunctorBase::type(), and gsw_whiteboard_s::wb.

Referenced by WBSubscriber::WBSubscriber().

◆ unsubscribe()

void whiteboard_watcher::unsubscribe ( guWhiteboard ::wb_types  t)
inline

Stop getting callbacks for a particular whiteboard type.

Parameters
tthe type to unsubscribe from

Definition at line 197 of file guwhiteboardwatcher.h.

References gsw_procure(), gsw_remove_process(), GSW_SEM_CALLBACK, gsw_vacate(), gsw_whiteboard_s::sem, WBFunctorBase::type(), and WBTYPES_NS.

Referenced by WBSubscriber::~WBSubscriber().


The documentation for this class was generated from the following file: