Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Can you know upfront if an event can be processed? #590

Open
diiigle opened this issue Aug 17, 2023 · 0 comments
Open

[Question] Can you know upfront if an event can be processed? #590

diiigle opened this issue Aug 17, 2023 · 0 comments

Comments

@diiigle
Copy link

diiigle commented Aug 17, 2023

The return value of process_event is already nice to determine if an event has been processed or silently dropped.

bool sm::process_event(event)

When working with user interfaces though, you would like to know upfront what events are currently possible (to grey impossible ones out).

Is there a way to iterate over currently possible events?

sm.visit_current_events([](auto& event){ })

or have a way to test specific events without calling the action?

bool sm::can_process_event(event)

The latter could be achieved with same shared context and guards that would block if you are currently in "query mode". I am just wondering if there could be a reusable way of implementing it, without overloading all guards.

Edit: I did some digging and found

sml/include/boost/sml.hpp

Lines 2558 to 2564 in 58536b9

constexpr bool execute(const TEvent &event, SM &sm, TDeps &deps, TSubs &subs, typename SM::state_t &, Ts &&...) {
if (call<TEvent, args_t<G, TEvent>, typename SM::logger_t>::execute(g, event, sm, deps, subs)) {
call<TEvent, args_t<A, TEvent>, typename SM::logger_t>::execute(a, event, sm, deps, subs);
return true;
}
return false;
}

So an implementation of can_process_event could call this function with another template parameter, that would prevent calling the action a (call<TEvent, args_t<A, TEvent>,), whereas a call through process_event would allow it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant