diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/action.c | 41 | ||||
| -rw-r--r-- | src/action.h | 1 | ||||
| -rw-r--r-- | src/config.c | 2 |
3 files changed, 41 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(); } diff --git a/src/action.h b/src/action.h index eb144a5..946b629 100644 --- a/src/action.h +++ b/src/action.h @@ -10,6 +10,7 @@ typedef enum { ACTION_SET_PAIR, ACTION_RUN_SYNC, ACTION_RUN_ASYNC, + ACTION_TRIGGER, } action_type_t; typedef struct { diff --git a/src/config.c b/src/config.c index 6b8fc58..86d5ac2 100644 --- a/src/config.c +++ b/src/config.c @@ -446,6 +446,8 @@ static config_status_t config_read_action(action_t *action, const char *key, con type = ACTION_RUN_SYNC; else if (!strcmp(key, "run-async")) type = ACTION_RUN_ASYNC; + else if (!strcmp(key, "trigger")) + type = ACTION_TRIGGER; else return CONFIG_UNKNOWN; |
