From 66f5ee2744c6961b387d865dbad2e0e301f65872 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Fri, 23 Sep 2016 06:04:20 -0500 Subject: [PATCH] Added callback operations to event class This adds a C++ style function API that allows the event class to be easily passed as an argument to existing callback based APIs. Added functions: void Event::call(args...) void Event::operator()(args...) static void Event::thunk(void *, args...) --- Event.h | 156 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) diff --git a/Event.h b/Event.h index c9daa61..dd574c5 100644 --- a/Event.h +++ b/Event.h @@ -188,6 +188,32 @@ class Event { return _event->id; } + /** Posts an event onto the underlying event queue, returning void + * + * @param a0..a4 Arguments to pass to the event + */ + void call() { + int id = post(); + MBED_ASSERT(id); + } + + /** Posts an event onto the underlying event queue, returning void + * + * @param a0..a4 Arguments to pass to the event + */ + void operator()() { + return call(); + } + + /** Static thunk for passing as C-style function + * + * @param func Event to call passed as a void pointer + * @param a0..a4 Arguments to pass to the event + */ + static void thunk(void *func) { + return static_cast(func)->call(); + } + /** Cancels the most recently posted event * * Attempts to cancel the most recently posted event. It is safe to call @@ -381,6 +407,32 @@ class Event { return _event->id; } + /** Posts an event onto the underlying event queue, returning void + * + * @param a0..a4 Arguments to pass to the event + */ + void call(A0 a0) { + int id = post(a0); + MBED_ASSERT(id); + } + + /** Posts an event onto the underlying event queue, returning void + * + * @param a0..a4 Arguments to pass to the event + */ + void operator()(A0 a0) { + return call(a0); + } + + /** Static thunk for passing as C-style function + * + * @param func Event to call passed as a void pointer + * @param a0..a4 Arguments to pass to the event + */ + static void thunk(void *func, A0 a0) { + return static_cast(func)->call(a0); + } + /** Cancels the most recently posted event * * Attempts to cancel the most recently posted event. It is safe to call @@ -574,6 +626,32 @@ class Event { return _event->id; } + /** Posts an event onto the underlying event queue, returning void + * + * @param a0..a4 Arguments to pass to the event + */ + void call(A0 a0, A1 a1) { + int id = post(a0, a1); + MBED_ASSERT(id); + } + + /** Posts an event onto the underlying event queue, returning void + * + * @param a0..a4 Arguments to pass to the event + */ + void operator()(A0 a0, A1 a1) { + return call(a0, a1); + } + + /** Static thunk for passing as C-style function + * + * @param func Event to call passed as a void pointer + * @param a0..a4 Arguments to pass to the event + */ + static void thunk(void *func, A0 a0, A1 a1) { + return static_cast(func)->call(a0, a1); + } + /** Cancels the most recently posted event * * Attempts to cancel the most recently posted event. It is safe to call @@ -767,6 +845,32 @@ class Event { return _event->id; } + /** Posts an event onto the underlying event queue, returning void + * + * @param a0..a4 Arguments to pass to the event + */ + void call(A0 a0, A1 a1, A2 a2) { + int id = post(a0, a1, a2); + MBED_ASSERT(id); + } + + /** Posts an event onto the underlying event queue, returning void + * + * @param a0..a4 Arguments to pass to the event + */ + void operator()(A0 a0, A1 a1, A2 a2) { + return call(a0, a1, a2); + } + + /** Static thunk for passing as C-style function + * + * @param func Event to call passed as a void pointer + * @param a0..a4 Arguments to pass to the event + */ + static void thunk(void *func, A0 a0, A1 a1, A2 a2) { + return static_cast(func)->call(a0, a1, a2); + } + /** Cancels the most recently posted event * * Attempts to cancel the most recently posted event. It is safe to call @@ -960,6 +1064,32 @@ class Event { return _event->id; } + /** Posts an event onto the underlying event queue, returning void + * + * @param a0..a4 Arguments to pass to the event + */ + void call(A0 a0, A1 a1, A2 a2, A3 a3) { + int id = post(a0, a1, a2, a3); + MBED_ASSERT(id); + } + + /** Posts an event onto the underlying event queue, returning void + * + * @param a0..a4 Arguments to pass to the event + */ + void operator()(A0 a0, A1 a1, A2 a2, A3 a3) { + return call(a0, a1, a2, a3); + } + + /** Static thunk for passing as C-style function + * + * @param func Event to call passed as a void pointer + * @param a0..a4 Arguments to pass to the event + */ + static void thunk(void *func, A0 a0, A1 a1, A2 a2, A3 a3) { + return static_cast(func)->call(a0, a1, a2, a3); + } + /** Cancels the most recently posted event * * Attempts to cancel the most recently posted event. It is safe to call @@ -1153,6 +1283,32 @@ class Event { return _event->id; } + /** Posts an event onto the underlying event queue, returning void + * + * @param a0..a4 Arguments to pass to the event + */ + void call(A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) { + int id = post(a0, a1, a2, a3, a4); + MBED_ASSERT(id); + } + + /** Posts an event onto the underlying event queue, returning void + * + * @param a0..a4 Arguments to pass to the event + */ + void operator()(A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) { + return call(a0, a1, a2, a3, a4); + } + + /** Static thunk for passing as C-style function + * + * @param func Event to call passed as a void pointer + * @param a0..a4 Arguments to pass to the event + */ + static void thunk(void *func, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) { + return static_cast(func)->call(a0, a1, a2, a3, a4); + } + /** Cancels the most recently posted event * * Attempts to cancel the most recently posted event. It is safe to call