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

Sending event to orthgonal region #181

Closed
GuiCodron opened this issue Jun 25, 2018 · 1 comment
Closed

Sending event to orthgonal region #181

GuiCodron opened this issue Jun 25, 2018 · 1 comment

Comments

@GuiCodron
Copy link
Contributor

Hello, I'm looking into sml and find it really good, however there is one UML feature I can't get to work. It's posting event from one orthogonal region to another.

This example show me trying to accomplish that:

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

namespace sml = boost::sml;

namespace {

// ACTION

struct ge1 {};
struct ge2 {};

struct o1 {
    struct e1{};
    struct e2{};
auto operator()() const noexcept {
    using namespace sml;
    return make_transition_table(
        (*"s1"_s) + event<e2> = "s2"_s
        , "s1"_s  + event<ge1> / [](
            std::cout << "o1: s1 -> s2\n";
            sml::back::process<ge2> process_event){process_event(ge2{});
         }
        , "s2"_s  + event<ge2> = "s1"_s
    );
}
};

struct o2 {
    struct e1{};
    struct e2{};

auto operator()() const noexcept {
    using namespace sml;
    return make_transition_table(
        (*"s1"_s) + event<e2> = "s2"_s
        , "s1"_s + event<ge2> / [] {std::cout << "o2: s1 -> s2\n";} = "s2"_s
        , "s1"_s + event<e2> / [] {std::cout << "o2: s1 -> s2\n";} = "s2"_s
    );
}
};


struct main_state {
    struct e1{};
    struct e2{};


    auto operator()() const noexcept {
        using namespace sml;
        return make_transition_table(
            (*state<o1>) + on_entry<sml::initial> / [this]{ std::cout << " o1 init\n"; }
            ,(*state<o2>) + on_entry<sml::initial> / [this]{ std::cout << " o2 init\n"; }
        );
    }
};


}

int main(int argv, char** argc) {

    my_logger logger;

    sml::sm<main_state, sml::defer_queue<std::queue>, sml::process_queue<std::queue>, sml::logger<my_logger>> sm(logger);

    using namespace sml;
    sm.process_event(ge1{});

}

In this example, I try to send a ge2 event from orthogonal region o1 to orthogonal region o2, however, the the process_event function does not affect the full state machine but only the sub_machine defined by o1. This is the same if o1 is a composite state of main_state, the event does not reach main_state but affect only the o1 sub_state_machine.

Does someone know a may to send event from a sub_state to the main state machine or from an orthogonal region to another orthogonal region?

At first, I tried to use process(o2::e2{}) in an action of o1, but the compilation failed saying that this type of event couldn't be casted into a known event of the o1 sub_state_machine.
Wouldn't it be interesting to have this event checking at compilation time for event not handled by the state machine?

Thanks for your awesome job Kris!

@kris-jusiak
Copy link
Collaborator

Fixed by #302

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

2 participants