Discussion:
[statechart] Passing parameters from event to State Local Storage
Christophe Bourez
2010-05-06 07:56:00 UTC
Permalink
I need to maintain a parameter into the state local storage. This
parameter is initially contained in the event that causes the transition to
the target state. I give hereafter a small illustrative example.

typename sc = boost::statechart;

class EvTest : public sc::event<EvTest>
{
public:
EvTest(std::size_t val) : value(val) {}
std::size_t getValue() const { return this->value; }
private:
std::size_t value;
};

class MyStateMachine;
class StSource;
class StTarget;

class StSource : public sc::simple_state<StSource, MyStateMachine>
{
public:
typedef sc::custom_reaction<EvTest> reactions;

sc::result react(const EvTest &event)
{
// How to pass event.getValue() to the target state ?
transit<StTarget>();
}
};

class StTarget : public sc::simple_state<StTarget, MyStateMachine>
{
public:
StTarget(std::size_t val) : val(value) {}
private:
std::size_t value;
};

Thanks,
Christophe
Felipe Magno de Almeida
2010-05-06 17:00:59 UTC
Permalink
Post by Christophe Bourez
I need to maintain a parameter into the state local storage. This
parameter is initially contained in the event that causes the transition to
the target state. I give hereafter a small illustrative example.
typename sc = boost::statechart;
class EvTest : public sc::event<EvTest>
{
EvTest(std::size_t val) : value(val) {}
std::size_t getValue() const { return this->value; }
std::size_t value;
};
class MyStateMachine;
class StSource;
class StTarget;
class StSource : public sc::simple_state<StSource, MyStateMachine>
{
typedef sc::custom_reaction<EvTest> reactions;
sc::result react(const EvTest &event)
{
// How to pass event.getValue() to the target state ?
transit<StTarget>();
}
};
class StTarget : public sc::simple_state<StTarget, MyStateMachine>
{
StTarget(std::size_t val) : val(value) {}
std::size_t value;
};
I have a patch using boost.fusion to allow this. It works this way:

class StSource : public sc::simple_state<StSource, MyStateMachine>
{
public:
typedef sc::custom_reaction<EvTest> reactions;
sc::result react(const EvTest &event)
{
// How to pass event.getValue() to the target state ?
transit<StTarget>(event.value); // pass arguments to target
// state constructor
}
};

Does Boost have interest in this?
Post by Christophe Bourez
Thanks,
Christophe
Regards,
--
Felipe Magno de Almeida
Andreas Huber
2010-05-07 10:36:44 UTC
Permalink
Hi Felipe
Post by Christophe Bourez
class StSource : public sc::simple_state<StSource, MyStateMachine>
{
typedef sc::custom_reaction<EvTest> reactions;
sc::result react(const EvTest &event)
{
// How to pass event.getValue() to the target state ?
transit<StTarget>(event.value); // pass arguments to target
// state constructor
}
};
Does Boost have interest in this?
Yes, definitely!

Thanks,
--
Andreas Huber

When replying by private email, please remove the words spam and trap
from the address shown in the header.
Andreas Huber
2010-05-07 10:57:24 UTC
Permalink
Hi Christophe
Post by Christophe Bourez
I need to maintain a parameter into the state local storage. This
parameter is initially contained in the event that causes the transition to
the target state. I give hereafter a small illustrative example.
The "problem" with passing event data to a constructor of a destination
state is hinted at here (item 3):

<http://www.boost.org/doc/libs/1_42_0/libs/statechart/doc/future_and_history.html>

Nevertheless, the triggering_event() function is available in >=1.42 (but
only documented in >=1.43). Also, I'll definitely look at Felipe's patch.

HTH,
--
Andreas Huber

When replying by private email, please remove the words spam and trap
from the address shown in the header.
Igor R.
2010-08-05 16:10:20 UTC
Permalink
Hello,
Post by Andreas Huber
The "problem" with passing event data to a constructor of a destination
<http://www.boost.org/doc/libs/1_42_0/libs/statechart/doc/future_and_history.html>
Nevertheless, the triggering_event() function is available in >=1.42 (but
only documented in >=1.43).
Also, I'll definitely look at Felipe's patch.
Was there any progress with this patch, i.e. is it possible in the current
version to pass arbitrary arguments to a state constructor?
If not, what's the recommended workaround? To share data through the
outermost state?

Thanks!
--
View this message in context: http://old.nabble.com/-statechart--Passing-parameters-from-event-to-State-Local-Storage-tp28473717p29356365.html
Sent from the Boost - Users mailing list archive at Nabble.com.
Andreas Huber
2010-08-05 21:10:05 UTC
Permalink
Post by Igor R.
Was there any progress with this patch, i.e. is it possible in the current
version to pass arbitrary arguments to a state constructor?
Unfortunately not, I have not heard anything from Felipe. I personally don't
see a good way how this can be implemented, so I'm really interested in his
approach.
Post by Igor R.
If not, what's the recommended workaround? To share data through the
outermost state?
Either that, or:
1) Repost the event in the transition and have an in_state_reaction
(triggered by the same event) store whatever you need (typesafe), or
2) use triggering_event()
<http://www.boost.org/doc/libs/1_43_0/libs/statechart/doc/reference.html#triggering_event0>
(not typesafe)

HTH,
--
Andreas Huber

When replying by private email, please remove the words spam and trap
from the address shown in the header.
ksl
2016-11-16 14:24:50 UTC
Permalink
Post by Andreas Huber
1) Repost the event in the transition and have an in_state_reaction
(triggered by the same event) store whatever you need (typesafe), or
Please can you provide an example.



--
View this message in context: http://boost.2283326.n4.nabble.com/statechart-Passing-parameters-from-event-to-State-Local-Storage-tp2590845p4689947.html
Sent from the Boost - Users mailing list archive at Nabble.com.

Continue reading on narkive:
Loading...