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

bad naming for eventless transitions #40

Open
jp-embedded opened this issue Jan 2, 2018 · 5 comments
Open

bad naming for eventless transitions #40

jp-embedded opened this issue Jan 2, 2018 · 5 comments
Assignees

Comments

@jp-embedded
Copy link
Owner

'sc::state::unconditional' is bad naming. The transition is not unconditional, but eventless. Consider to change this to for example 'sc::state::eventless' or 'sc::state::none'

@jp-embedded jp-embedded self-assigned this Jan 2, 2018
@ringlej
Copy link
Contributor

ringlej commented Feb 15, 2018

Agreed. It seems silly to have:

template<> bool sc::transition_actions<&sc::state::unconditional, sc::state_A>::condition(sc::data_model& m);

Seems oxymoronic :)
What kind of usecase is this meant for?

@jp-embedded
Copy link
Owner Author

jp-embedded commented Feb 16, 2018

Well, your example condition's transition is both target less and event less. I don't have a use case in mind for this. However, in the timer switch example, there is a condition for a transition which does have a target but no event:

template<> bool sc::transition_actions<&sc::state::unconditional, sc::state_on, sc::state_off>::condition(sc::data_model &m)
{
	return m.user->timer >= 5;
}

This will transition from state_on to state_off when m.user->timer >= 5

@ringlej
Copy link
Contributor

ringlej commented Feb 16, 2018

Oh I see. So, the use case is when you want a guard condition to be evaluated upon any event that may occur in the source state. I wouldn’t say that this is really eventless. An event has to occur, but you just don’t care which event it is. I’d offer the suggestion to call this sc::state::any_event and to use this also as the default argument to dispatch

void dispatch(event e = &state::any_event)
{
	bool cont = dispatch_event(e);
	while (cont) {
		if ((cont = dispatch_event(&state::initial)));
		else if ((cont = dispatch_event(&state::any_event)));
		else if (model.event_queue.size()) cont = dispatch_event(model.event_queue.front()), model.event_queue.pop(), cont |= !model.event_queue.empty();
		else break;
	}
}

If you like this, I'd be happy to prepare a PR

@sstiller
Copy link
Contributor

sstiller commented Oct 5, 2018

I think, sc::state::eventless is a good name because "eventless" is also used in the scxml standard.

But it's a little bit worse:
If you have multiple eventless transitions with same source and target state, the generated code can not be compiled.
An example:

<?xml version="1.0" encoding="UTF-8"?>
<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" binding="early" name="cond" datamodel="cplusplus">
    <state id="State_1">
        <transition type="external" target="State_2" cond="isOn"/>
        <transition type="external" target="State_2" cond="isOn2"/>
    </state>
    <state id="State_2"/>
    <datamodel>
        <data id="bool isOn" expr="false"/>
        <data id="bool isOn2" expr="false"/>
    </datamodel>
</scxml>

cond.h:176:17: error: redefinition of ‘bool sc_cond::transition_actions<E, S, D0>::condition(sc_cond::data_model&) [with sc_cond::state* (sc_cond::state::* E)(sc_cond&) = &sc_cond::state::unconditional; S = sc_cond::state_State_1; D0 = sc_cond::state_State_2]’
 template<> bool sc_cond::transition_actions<&sc_cond::state::unconditional, sc_cond::state_State_1, sc_cond::state_State_2>::condition(sc_cond::data_model &m)
                 ^~~~~~~
cond.h:169:17: note: ‘bool sc_cond::transition_actions<E, S, D0>::condition(sc_cond::data_model&) [with sc_cond::state* (sc_cond::state::* E)(sc_cond&) = &sc_cond::state::unconditional; S = sc_cond::state_State_1; D0 = sc_cond::state_State_2]’ previously declared here
 template<> bool sc_cond::transition_actions<&sc_cond::state::unconditional, sc_cond::state_State_1, sc_cond::state_State_2>::condition(sc_cond::data_model &m)

I think, if the condition is defined in the scxml, an eventless transition should get some kind of identifier (simple counter).

@jp-embedded
Copy link
Owner Author

Thanks for your observation :-)
I will look into this. Your suggested solution is also what I think could be a solution.
Transitions are made unique using S, D and E (source state, destination state and event), but as you show, this is not enough. The same problem will exists for transitions which have an event if S, D & E are equal.

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

3 participants