Maki
Loading...
Searching...
No Matches
Pre- and Post-Processing Hooks

You can ask maki::machine to call hooks before or after it processes specific events.

These hooks are configured by calling overloads and variants of the following functions:

The pre hook is useful when you need to define a reaction to an event that is independent from the active states. For example:

// Always log alerts
.pre_processing_hook_e<alert_event>([](const alert_event& evt)
{
log_warning("Alert! ", evt.reason);
})

The post hook can be used to handle the case where an event hasn't triggered any transition (neither external nor local). For example:

// Notify client when reboot request is rejected
.post_processing_hook_mep<client_reboot_request>([](
auto& mach,
const client_reboot_request& event,
const bool processed)
{
if (!processed)
{
mach.context().server.send_to(
event.client_id,
"Can't reboot right now");
}
})

You can add as many hook as you want for different event types or event type sets.