From 3368a81057d4981aa259c5548050d95739d99d51 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Tue, 19 Jan 2021 14:21:00 -0500 Subject: refactor(core): Combine `is_` and `cast_` event functions. * Use a single `as_foo` generated function to conditionally return a certain event type from a generic `zmk_event_t*` pointer. --- app/include/zmk/event_manager.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'app/include/zmk') diff --git a/app/include/zmk/event_manager.h b/app/include/zmk/event_manager.h index 8fc3f19..5acb26e 100644 --- a/app/include/zmk/event_manager.h +++ b/app/include/zmk/event_manager.h @@ -39,8 +39,7 @@ struct zmk_event_subscription { struct event_type data; \ }; \ struct event_type##_event *new_##event_type(struct event_type); \ - bool is_##event_type(const zmk_event_t *eh); \ - struct event_type *cast_##event_type(const zmk_event_t *eh); \ + struct event_type *as_##event_type(const zmk_event_t *eh); \ extern const struct zmk_event_type zmk_event_##event_type; #define ZMK_EVENT_IMPL(event_type) \ @@ -54,9 +53,9 @@ struct zmk_event_subscription { ev->data = data; \ return ev; \ }; \ - bool is_##event_type(const zmk_event_t *eh) { return eh->event == &zmk_event_##event_type; }; \ - struct event_type *cast_##event_type(const zmk_event_t *eh) { \ - return &((struct event_type##_event *)eh)->data; \ + struct event_type *as_##event_type(const zmk_event_t *eh) { \ + return (eh->event == &zmk_event_##event_type) ? &((struct event_type##_event *)eh)->data \ + : NULL; \ }; #define ZMK_LISTENER(mod, cb) const struct zmk_listener zmk_listener_##mod = {.callback = cb}; -- cgit v1.2.3