sml icon indicating copy to clipboard operation
sml copied to clipboard

Exlicit Entry example needed

Open davidfrulm opened this issue 5 years ago • 6 comments

I am unsure about the "Explicit Entry" syntax. I tried several variations but none of them seems to make any practical difference.

Code below presents one of these variations:

#include <boost/sml.hpp> #include #include

namespace sml = boost::sml;

struct e1 {};

struct sub { static constexpr auto ss1 = sml::state; static constexpr auto ss2 = sml::state;

auto operator()()
{
    using namespace sml;
    return make_transition_table(
        *ss1 + on_entry<_> / [] { std::cout << "sub<ss1>::on_entry" << std::endl; }
        ,ss2 + on_entry<_> / [] { std::cout << "sub<ss2>::on_entry" << std::endl; }
    );
}

};

struct parent { static constexpr auto ps1 = sml::state; static constexpr auto ps2 = sml::state;

auto operator()()
{
    using namespace sml;
    return make_transition_table(
        *ps1 + on_entry<_> / [] { std::cout << "parent<ps1>::on_entry" << std::endl; }
        ,ps1 + event<e1> / [] { std::cout << "parent<ps1>::event<e1>" << std::endl; } = sub::ss2
        ,ps2 + on_entry<_> / [] { std::cout << "parent<ps2>::on_entry" << std::endl; }
    );
}

};

int main() { sml::sm sm{}; sm.process_event(e1{}); assert(sm.is<decltype(sml::state)>(sub::ss1)); // should be sub::ss2 instead }

Outcome is something like:

parent::on_entry parent::event Final state is sub::ss1.

My expectation would have been this instead:

parent::on_entry parent::event parent::on_entry sub::on_entry Final state is sub::ss2.

Last, a question about the syntax in the example for representing states. My understanding is that:

  • SML Actions/Guards are stateless
  • SML FSM itself is stateful But what about the state classes that are defined for the FSM itself? Are stateless or stateful? Meaning, would a "static" definition work for multiple FSM instantiations?

davidfrulm avatar Sep 28 '19 04:09 davidfrulm

Explicit entry is not supported by SML.

Therefore I would say this is not a non-issue and can be closed.

Rijom avatar Sep 11 '20 19:09 Rijom

@davidfrulm have a look at https://github.com/erikzenker/hsm it supports explicit entry action. An example can be found here https://github.com/erikzenker/hsm/blob/master/test/integration/entry_exit_pseudo_states.cpp#L63

erikzenker avatar Sep 12 '20 17:09 erikzenker

Explicit entry is not supported by SML.

Therefore I would say this is not a non-issue and can be closed.

Explicit entry/exit is SUPPORTED by SML.

Watch the presentation https://boost-ext.github.io/sml/embo-2018/#/5/4

I am plus the author of the topic.

A good example is needed.

heretic13 avatar Oct 01 '21 09:10 heretic13

Is it? I can't find it in the presentation you linked.

Rijom avatar Oct 01 '21 10:10 Rijom

Is it? I can't find it in the presentation you linked.

Slide 6.5

heretic13 avatar Oct 01 '21 10:10 heretic13

image

Oh I see - thanks. But are the slides correct? Have you ever seen code that implements it?

I'm very surprised by this claim because that's a feature I've been missing for a long time. So far I've always been using workarounds to achieve direct entry/exit behaviour. E.g. see this discussion here: https://github.com/boost-ext/sml/issues/185#issuecomment-473380556

Maybe @krzysztof-jusiak can clarify.

Rijom avatar Oct 01 '21 13:10 Rijom