9#ifndef GENERIC_WB_WATCHER_H
10#define GENERIC_WB_WATCHER_H
12#pragma clang diagnostic push
13#pragma clang diagnostic ignored "-Wweak-vtables"
14#pragma clang diagnostic ignored "-Wpadded"
15#pragma clang diagnostic ignored "-Wmissing-variable-declarations"
16#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
17#pragma clang diagnostic ignored "-Wunused-value"
22#ifndef WITHOUT_LIBDISPATCH
38#include <dispatch/dispatch.h>
40#define DISPATCH_QUEUE_NAME_WB "guWhiteboard"
42#ifndef DISPATCH_QUEUE_SERIAL
43#define DISPATCH_QUEUE_SERIAL NULLPTR
46#define SUBSCRIBE(wb, t, c, f) ((wb)->subscribe(t ## _WBFunctor<c>::bind(this, &f, k##t ## _v)))
48#define WBTYPES_NS CPP_WHITEBOARD_NAMESPACE::C_WBTYPES
67 callback_helper(
gu_simple_whiteboard *w,
int o,
WBFunctorBase *d, uint16_t t,
bool use_t, uint8_t gen):
wb(w),
f(d),
offs(o),
t_overwrite(t),
use_type_overwrite(use_t),
gen_to_use(gen) {}
70static void do_callback(
void *m)
107 std::list<WBFunctorBase *> _sub;
108 dispatch_group_t callback_group;
109 dispatch_queue_t callback_queue;
126 if (!(callback_group = dispatch_group_create()))
128 std::cerr <<
"Unable to create dispatch group" << std::endl;
129 throw "Whiteboard cannot create callback queue";
133 std::cerr <<
"Unable to create dispatch queue" << std::endl;
134 throw "Whiteboard cannot create dispatch queue";
138 _wbd->
callback = subscription_callback;
148 dispatch_group_wait(callback_group, DISPATCH_TIME_FOREVER);
151#if !defined(__clang__)
153#define __has_feature(x) 0
156#if !__has_feature(objc_arc)
157 dispatch_release(callback_queue);
158 dispatch_release(callback_group);
170 fprintf(stderr,
"whiteboard_watcher: Only use WB_BIND for the original Whiteboard class, for the simplewhiteboard watcher please use WB_TYPE_BIND(type const enum, function pointer). This is not optional, exiting...\n");
177 _sub.push_back(func);
201 for (std::list<WBFunctorBase *>::iterator i = _sub.begin(); i != _sub.end(); i++)
224 for (std::list<WBFunctorBase *>::iterator i = _sub.begin(); i != _sub.end(); i++)
227 int offs =
static_cast<int>(f->
type());
243 fprintf(stderr,
" @%d\n", e);
247 uint16_t t_overwrite = uint16_t(e);
249 dispatch_group_async_f(callback_group, callback_queue, h, do_callback);
259 fprintf(stderr,
" @%d\n", offs);
264 dispatch_group_async_f(callback_group, callback_queue, h, do_callback);
Base class for WBFunctor.
virtual void call(std::string s, WBMsg *m)=0
Call method for the OLD whiteboard callbacks that used WBMsg - Deprecated.
virtual guWhiteboard::wb_types type()=0
getter for the WB type
virtual uint16_t get_event_count()=0
getter for the WB event counter
virtual void set_event_count(uint16_t e)=0
setter for the WB event counter
virtual bool is_simple_wb_version()=0
is this being used by the 'simple whiteboard' or the OLD whiteboard (which is now Deprecated)
This class provides a subscription implementation for the 'simple' whiteboard, aka the 'typed' whiteb...
void receive_callback()
Internal function, this is what gets triggered by the underlying whiteboard, it then checks its list ...
void subscribe(WBFunctorBase *func)
Allows you to subscribe to a specific whiteboard type and get callbacks when that type is updated.
void unsubscribe(guWhiteboard ::wb_types t)
Stop getting callbacks for a particular whiteboard type.
whiteboard_watcher(gu_simple_whiteboard_descriptor *wbd=NULLPTR)
Constructor, sets up the dispatch queues for handling callbacks.
~whiteboard_watcher()
Destructor, release whiteboard objects and dispatch queues.
void gsw_add_wbd_signal_handler(gu_simple_whiteboard_descriptor *wbd)
add subscription signal handler
void gsw_free_whiteboard(gu_simple_whiteboard_descriptor *wbd)
free the given whiteboard descriptor
gu_simple_whiteboard_descriptor * get_local_singleton_whiteboard(void)
create a simple whiteboard for the local singleton wb pointer
int gsw_procure(gsw_sema_t sem, enum gsw_semaphores s)
grab a whiteboard semaphore
void gsw_remove_process(gu_simple_whiteboard_descriptor *wbd, const pid_t proc)
remove process for subscription signalling
int gsw_vacate(gsw_sema_t sem, enum gsw_semaphores s)
release a whiteboard semaphore
void gsw_add_process(gu_simple_whiteboard_descriptor *wbd, const pid_t proc)
add process for subscription signalling
#define GSW_TOTAL_MESSAGE_TYPES
message types (max)
@ GSW_SEM_CALLBACK
semaphore for callback data
#define kwb_reserved_SubscribeToAllTypes_v
#define DISPATCH_QUEUE_SERIAL
#define DISPATCH_QUEUE_NAME_WB
gu_simple_whiteboard_descriptor * local_whiteboard_descriptor
An internal stuct for passing callback information to dispatch queues.
WBFunctorBase * f
callback functor pointer
uint8_t gen_to_use
the message generation slot that contains the data for this callback
uint16_t t_overwrite
the type offset / enum value to 'fake' see comment for 'use_type_overwrite'
callback_helper(gu_simple_whiteboard *w, int o, WBFunctorBase *d, uint16_t t, bool use_t, uint8_t gen)
Constructor.
int offs
type offset in shared memory, aka type enum value
bool use_type_overwrite
use the type overwrite of WBFunctor (used by the simpleposter to 'fake' messages without a huge amoun...
gu_simple_whiteboard * wb
wb pointer
the actual whiteboard in shared mem
uint8_t indexes[512]
ring buffer indexes
uint16_t event_counters[512]
event counter loops
gu_simple_message messages[512][4]
the actual messages stored in the whiteboard
the underlying whiteboard object
bool exit_monitor
exit the monitor
gsw_subscription_f callback
subscription callback function
void * context
callback context
gsw_sema_t sem
semaphore to use
gu_simple_whiteboard * wb
the actual whiteboard in shared mem