diff options
| author | Federico Angelilli <code@fedang.net> | 2024-12-07 00:41:01 +0100 |
|---|---|---|
| committer | Federico Angelilli <code@fedang.net> | 2024-12-07 00:41:01 +0100 |
| commit | fd2ef765de733fbbbb15e28c91df255da36d5338 (patch) | |
| tree | b107ca1a2e9b1b0ae1ee7534cdd4a850f52d9cb0 /src/action.c | |
| parent | 4f1c110638749f0d6941967e313bdcc28b2b3485 (diff) | |
Add trigger actiontrunk
Diffstat (limited to 'src/action.c')
| -rw-r--r-- | src/action.c | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/src/action.c b/src/action.c index 6b48c15..df6ad3a 100644 --- a/src/action.c +++ b/src/action.c @@ -51,9 +51,11 @@ bool action_perform(action_t *action, block_t *block, config_t *config) case ACTION_SET_PAIR: { assert(target != NULL); - if (!warned && target->scheme->change_fn == NULL) { - log_warn("Block '%s' does not support 'set' actions", target->label); - warned = true; + if (target->scheme->change_fn == NULL) { + if (!warned) { + log_warn("Block '%s' does not support 'set' actions", target->label); + warned = true; + } continue; } @@ -96,6 +98,39 @@ bool action_perform(action_t *action, block_t *block, config_t *config) break; } + case ACTION_TRIGGER: { + event_t event; + event_init_trigger(&event, action->label, value); + + action_t *action = target->actions[EVENT_TRIGGER]; + block_event_t event_fn = target->type == BLOCK_SPEC + ? ((block_spec_t *)target)->event_fn + : NULL; + + log_value_debug("Block received a trigger", + "s:target", target->label, + "s:origin", event.trigger.origin, + "s:payload", event.trigger.payload, + "b:action", action != NULL, + "b:callback", event_fn != NULL); + + if (event_fn != NULL) { + // FIXME + layout_t tmp = { + .block = target, + }; + + event_fn(&tmp, config, event); + log_trace("Completed event callback"); + } else if (action != NULL) { + action_perform(action, target, config); + } else { + log_warn("Block '%s' was triggered but had nothing to respond", target->label); + } + + break; + } + default: unreachable(); } |
