C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

State machine framework with dynamic configurability

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Dave
Guest





PostPosted: Thu Jun 23, 2005 11:12 pm    Post subject: State machine framework with dynamic configurability Reply with quote



Hi all,
I'm working on a project to improving a legacy software on Unix which
has a flat state machine with hundreds of states in it. I'm looking for
a state machine framework that supports nested states, guards, entry,
exit and preferrably other state machine features such as concurrent
state transitions, orthorgonal states, shallow/deep histories. Another
requirement is that the state machine framework should be dynamically
configurable, say in my main program I have 3 states, and i can build a
shared object which defines a state machine as a sub-state machine for
one of the states in the main program. All these should be achieved
without recompiling the main program.

I looked into the boost statechart library and dug up the thread that
Andreas Huber started when the idea to create boost statechart was
first hatched. The only problem is that the library wasn't designed
with dynamic configurability in mind, so it doesn't suit my needs.

I also looked into the quantum platform, etc framework, but I have
trouble finding documentation (perhaps I need to buy the book?)

I've also tried a statechart modelling tool called SmartState and used
it to generate a state machine but the state machine features supported
are limited and I have some reservations about the design of the state
machine framework that the tool generates

So.. my question is: is there any other state machine framework that is
dynamically configurable and support the most of the state machine
features mentioned above?

any help is welcome, thanks in advance

newbie


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Cyril
Guest





PostPosted: Fri Jun 24, 2005 3:35 pm    Post subject: Re: State machine framework with dynamic configurability Reply with quote



I know I'm not answering to your question. Anyway, I think you should
have a look at:
http://www.codeproject.com/ce/dev_embed_statemachine.asp

Sincerely,
Cyril


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Andreas Huber
Guest





PostPosted: Wed Jul 06, 2005 9:59 am    Post subject: Re: State machine framework with dynamic configurability Reply with quote



Hi Dave

Sorry for the late reply, I was on holiday.

Dave wrote:
[snip]
Quote:
Another requirement is that the state machine framework
should be dynamically configurable, say in my main program I have 3
states, and i can build a shared object which defines a state machine
as a sub-state machine for one of the states in the main program. All
these should be achieved without recompiling the main program.

A very limited form of dynamic configurability is possible with
Boost.Statechart: You can implement the main FSM in the main exe and to
customize by dynamically loading dlls. Of course, for this to work you'd
need to know the points of customization beforehand.
A related FAQ item can be found here:

http://tinyurl.com/ak239

Quote:
I looked into the boost statechart library and dug up the thread that
Andreas Huber started when the idea to create boost statechart was
first hatched. The only problem is that the library wasn't designed
with dynamic configurability in mind, so it doesn't suit my needs.

Out of curiosity: Would you care to describe what kind of application
you need such a library for? When I researched the requirements for
Boost.Statechart I came to the conclusion that *full* dynamic
configurability is needed only *very* rarely in conjunction with the
full FSM feature set. One good example of such an app would be a program
that allows people to design an FSM and study its behavior graphically,
e.g. for educational purposes.

[snip]
Quote:
So.. my question is: is there any other state machine framework that
is dynamically configurable and support the most of the state machine
features mentioned above?

FWIW, I've had a look at quite a few freely available FSM libraries.
None of them does even come close to satisfying your requirements. I
can't say whether any of the commercial products do what you want.

Regards,

--
Andreas Huber

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


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
borg@swirve.com
Guest





PostPosted: Wed Jul 06, 2005 1:29 pm    Post subject: Re: State machine framework with dynamic configurability Reply with quote

Hi Andreas,

I was also considering a dynamic FSM as part of a mini interpreted
language implemented using the Boost.Spirit framework. The language
would allow users to specify states and state transitions as part of
the scripting language that would subsequently run in a small VM. I
haven't started yet, but was also wondering if I could use the Boost
statechart library in any way.

Regards,
Adrian


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Dave
Guest





PostPosted: Wed Jul 06, 2005 10:07 pm    Post subject: Re: State machine framework with dynamic configurability Reply with quote

Thanks but I have trouble accessing the link...


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Dave
Guest





PostPosted: Wed Jul 06, 2005 10:31 pm    Post subject: Re: State machine framework with dynamic configurability Reply with quote

the FAQ illustrates how to modify the existing layout of an FSM, but I
doubt whether it would be possible to implement the main FSM in the
main exe and then dynamically load dlls to add inner/sub-states to
existing states; since the state transition/reactions have to be
specified as template parameters.

Quote:
Out of curiosity: Would you care to describe what kind of application you need such a library for?

This is probably off-topic for this ng but I'll provide my reasons so
you can decide if they're reasonable or not.

The application I mentioned original post is a call control
application, in fact several of them. (Naturally each application is
maintained by a group of developers) Each of the applications has a
flat Fsm with many states. My goal is to design a framework that has a
main Fsm that is common to all the call control applications (with
points of customization pre-defined) and then dynamically load DLLs to
customize the behavior (by adding inner/sub-states) of the Fsm. The
obvious advantage of doing so would be code reuse. Another reason to do
so is that if a customization for a specific customer is needed (say
add a few states to the fsm), only a few DLLs need to be
modified/added, whereas in the existing design the main application has
to be modified and recompiled. In this way the customization may be
done by a developer who does not have full access to the source
code/statechart, all he/she needs to know is the interface of the
"point of customization".

Dynamic configurabliity aside, the application I'm working on is a call
control application, so I only need one instance of the state machine,
one instance of each state and use context objects to store state
information for each call. When I skimmed through the statechart
tutorial I see that the "Entry" and "Exit" functions are implemented
using the constructor and destructor of the simple_state class, so I
suppose that each state object is constructed when entered and
destructed when exited. I'm not sure.. if a state is entered and exited
repeatedly, say in the stopwatch example, whether the object
construction/destruction incurs an unecessary cost. If I'm wrong,
please correct me.

If there's a free Fsm libary (not licensed under GPL) that satisfies my
requirements that would be great, but I would also consider commercial
products. Yet I'm under the impression that commerial Fsm libaries
usually come with graphical UML editors... right now I'm stuck with
Rational Rose 98 (old version), so the new tool would have to be able
to import UML diagrams drawn using Rational Rose 98. One good thing
about Rational Rose is that the saved files are pretty human readable
so I can just write a script to parse the state chart specifications
and generate code that uses some Fsm libarary (say boost statechart).
Of course another alternative would be rely on the UML editor to
generate frameowrk code for me but I would still have to make some
modifications to archive dynamic configurability.

thanks

Dave
- I'm a novice please be nice :-)


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Andreas Huber
Guest





PostPosted: Wed Jul 06, 2005 10:32 pm    Post subject: Re: State machine framework with dynamic configurability Reply with quote

Hi Adrian

Quote:
I was also considering a dynamic FSM as part of a mini interpreted
language implemented using the Boost.Spirit framework. The language
would allow users to specify states and state transitions as part of
the scripting language that would subsequently run in a small VM. I
haven't started yet, but was also wondering if I could use the Boost
statechart library in any way.

Unlikely, given that "interpreted" is a firm requirement (otherwise you
could have your program generate C++ code, compile it and run the
resulting exe). IOW, as soon as the statechart layout is fully variable
depending on user input, you absolutely need full dynamic
configurability. This is not supported by Boost.Statechart.

Regards,

--
Andreas Huber

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


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Andreas Huber
Guest





PostPosted: Fri Jul 08, 2005 1:06 am    Post subject: Re: State machine framework with dynamic configurability Reply with quote

The answer to this post is rather OT for this newsgroup as it discusses
the properties of a library instead of general C++. The answer has
therefore been posted to the much more appropriate boost user group:

http://thread.gmane.org/gmane.comp.lib.boost.user/11953

--
Andreas Huber

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


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Alan Chen
Guest





PostPosted: Fri Jul 08, 2005 1:15 am    Post subject: Re: State machine framework with dynamic configurability Reply with quote

Did you see the message on that thread that mentions the Boost Graph
library. I think the BGL would handle your dynamic requirement quite
well; as well as your guard, entry, exit conditions, and nested states
reasonably well. However, it would take a little work to implement
concurrent, orthogonal state transitions...


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Dave
Guest





PostPosted: Thu Jul 14, 2005 5:35 pm    Post subject: Re: State machine framework with dynamic configurability Reply with quote

I agree that the thread is rather OT for this newsgroup now.. but I've
been unable to post follow-ups to that boost user group, I got rejected
saying I'm not authorized to post to that list and I've tried multiple
times with different email addresses. Hence I'll post my follow-up here
so the discussion could continue.

Quote:
Why do you think that the transition/reaction specification interface is a
problem? The FAQ item shows that you can have a base FSM that uses a virtual
function to delay the decision where to transit from a given state (Idle) when
a specific event occurs (EvStart). The base FSM (PumpBase) would be compiled
into the main exe. If you want to modify the behavior in a dll, all you need
to do is to derive from the base FSM and inside the virtual function override
you transit to the desired state.
Of course, for all this to work the main exe would need to have a means of
constructing an object of the derived class (MyPump) that was loaded from the
dll. This is easy enough to do with a factory.

You're right, it's possible to do so. I have yet to spend more time on
writing
test programs but right now I see some limitations.

Say for the PumpBase example, the designer of the main Fsm decides to
allow
customization for the Idle state and Running state. In the example
illustrated
in the FAQ a MyRunning state (and inner states added to it) is defined
and the
MyPump Fsm derives from PumpBase to specify a state transition to the
new
MyRunning state.

Suppose now I want to add some inner states for the Idle state. I can
define a
new MyIdle state but I cannot make it the initial state of MyPump since
Idle was
specified as a template parameter in PumpBase and MyPump derives from
PumpBase.

Let's put that aside and now let's suppose there's a third state in
PumpBase
Fsm: Stopped, and a state transition from Running to Stopped is
triggered by
event EvStop. and the following "point of customization" is defined in
PumpBase

virtual sc::result react(Running& running, const EvStop &) const;

To add inner states to Stopped I can define MyStopped and have MyPump
transition
from Running to MyStopped. However in MyPump Running is replaced by
MyRunning,
so I need to have my own react method to transit to MyStopped, and I'm
not even
using the "point of customization" in PumpBase because it has a
different
signature. Up till now it looks like I'm defining a new Fsm to replace
PumpBase
rather than customizing it.

All this is fine if PumpBase has few states. Yet consider the case when
2
developers work on PumpBase, one responsible for customizing the
Running state,
the other for customizing the Stopped state. The developers should be
able to
work on the state machine without knowing each other. Yet as I've
illustrated
above, there can only be one MyPump class and whoever writes that class
has to
be aware of the MyRunning and MyStopped class and write the react
functions
accordingly.

btw, I think there's a typo in the FAQ code snippet.
"sc::custom_reaction<
EvStart >" should not be the third template argument for struct Idle.

Quote:
Maybe there's just a terminology misunderstanding but I don't see the benefit
of the context object. In fact, the use of a context object here looks like a
common antipattern, a "winnebago" object (stolen from Jeff Garland). You'll
find more on this here (search for the first occurrence of "heuristic" and
read what follows):

http://lists.boost.org/MailArchives/boost/msg79540.php

Yes the term is confusing since context has a different meaning in
boost statechart, maybe I could call it a session object.

Yes it is an antipattern if the object requires modification everytime
a new
field is needed, but with a property map the new field can simply be
inserted
into the map. Moreover, since a state class is destroyed after a state
is
exited, any state information stored within that state is lost.
Information that
needs to persist throughout the execution of the state machine has to
be stored
in the state machine class, which in effect becomes the winnebago
object.

thanks

Dave


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.