diff options
author | Pete Johanson <peter@peterjohanson.com> | 2021-01-18 00:35:56 -0500 |
---|---|---|
committer | Pete Johanson <peter@peterjohanson.com> | 2021-01-20 07:06:11 -0500 |
commit | 3fe2acc2d191006fa6309191ee99b2e4e249ed08 (patch) | |
tree | 4994508fdc58daee4629c671e07e689b6332bd32 /app/src/event_manager.c | |
parent | 003db892adadb7b760f43411d7154fe60bf3556d (diff) |
refactor(core): Extra event payloads to own types, refactor API.
* Make it easier to use *just* event payloads by defining the data,
and then having event manager macros generate "wrapper structs"
* Improve is_*/cast_* APIs to hide details of full event struct.
* Create `zmk_event_t` typedef to pass to event handlers.
* Bring event names inline w/ consistent `zmk_` prefix.
Diffstat (limited to 'app/src/event_manager.c')
-rw-r--r-- | app/src/event_manager.c | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/app/src/event_manager.c b/app/src/event_manager.c index 872f5c8..0399ca8 100644 --- a/app/src/event_manager.c +++ b/app/src/event_manager.c @@ -17,7 +17,7 @@ extern struct zmk_event_type *__event_type_end[]; extern struct zmk_event_subscription __event_subscriptions_start[]; extern struct zmk_event_subscription __event_subscriptions_end[]; -int zmk_event_manager_handle_from(struct zmk_event_header *event, uint8_t start_index) { +int zmk_event_manager_handle_from(zmk_event_t *event, uint8_t start_index) { int ret = 0; uint8_t len = __event_subscriptions_end - __event_subscriptions_start; for (int i = start_index; i < len; i++) { @@ -48,12 +48,9 @@ release: return ret; } -int zmk_event_manager_raise(struct zmk_event_header *event) { - return zmk_event_manager_handle_from(event, 0); -} +int zmk_event_manager_raise(zmk_event_t *event) { return zmk_event_manager_handle_from(event, 0); } -int zmk_event_manager_raise_after(struct zmk_event_header *event, - const struct zmk_listener *listener) { +int zmk_event_manager_raise_after(zmk_event_t *event, const struct zmk_listener *listener) { uint8_t len = __event_subscriptions_end - __event_subscriptions_start; for (int i = 0; i < len; i++) { struct zmk_event_subscription *ev_sub = __event_subscriptions_start + i; @@ -68,8 +65,7 @@ int zmk_event_manager_raise_after(struct zmk_event_header *event, return -EINVAL; } -int zmk_event_manager_raise_at(struct zmk_event_header *event, - const struct zmk_listener *listener) { +int zmk_event_manager_raise_at(zmk_event_t *event, const struct zmk_listener *listener) { uint8_t len = __event_subscriptions_end - __event_subscriptions_start; for (int i = 0; i < len; i++) { struct zmk_event_subscription *ev_sub = __event_subscriptions_start + i; @@ -84,6 +80,6 @@ int zmk_event_manager_raise_at(struct zmk_event_header *event, return -EINVAL; } -int zmk_event_manager_release(struct zmk_event_header *event) { +int zmk_event_manager_release(zmk_event_t *event) { return zmk_event_manager_handle_from(event, event->last_listener_index + 1); } |