Boost logo

Boost Users :

Subject: Re: [Boost-users] [statechart] Substates in dll
From: Andreas Huber (ahd6974-spamboostorgtrap_at_[hidden])
Date: 2009-07-11 05:18:28


Hi Bill

> Is there any way to partition a state machine using boost::statechart such
> that the main state machine is in one dll, and its substates (and possibly
> their substates) are in separate dll's?

Yes, that's possible, with one restriction: The inner initial state of each
state must be in the same dll as the state itself, see below.

> It would seem that this would create a cyclic dependency.

The cyclic dependency only exists between the state and its inner initial
state. The state does not need to have any knowledge of all its other inner
states.

> Suppose you have
> e.g. a simple statechart called MyStatechart containing an initial state
> State1 which transitions to State2 in response to some event. Is it
> possible
> to implement MyStatechart and State1 in MyStatechart.dll, and State2 in
> State2.dll?

It seems this should be possible. A prerequisite is that the transition from
State1 to State2 must not be implemented with an ordinary sc::transition<>
but with a sc::custom_reaction<>. By doing that, you are able to move the
knowledge of the target state from the declaration (hpp file) to an ordinary
function (which can reside in a cpp file), see

<http://www.boost.org/doc/libs/1_39_0/libs/statechart/doc/tutorial.html#SpreadingAStateMachineOverMultipleTranslationUnits>

for more information. Now, in order to really break the cycle, the
*implementation* of State1::react should reside in State2.dll. Don't know
whether that suits your needs, if not feel free to follow-up.

> Since the code for State1 will need to reference State2 (in order to
> transition to it), MyStatechart.dll will have a dependency on State2.dll.
> But since State2 is contained in MyStatechart, its type will have to look
> something like
>
> struct State2: sc::state<State2, MyStatechart>
> {
> //...
> };
>
> which means that State2.dll will have a dependency on MyStatechart.dll.

No, IIUC. It should be enough when MyStatechart.dll and State2.dll include
the same header, e.g. MyStatechart.hpp. You might want to have a look at the
TuTest*.* files in the test directory. These do not implement your use case,
but at least illustrate how the importing/exporting required by some
platforms can be done.

HTH,

-- 
Andreas Huber
When replying by private email, please remove the words spam and trap
from the address shown in the header. 

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net