Boost logo

Boost Users :

Subject: Re: [Boost-users] [MSM] state transitions and exceptions
From: Stephan Menzel (stephan.menzel_at_[hidden])
Date: 2012-03-29 15:06:16


Jurai,

On Thu, Mar 29, 2012 at 7:07 PM, Juraj Ivančić <juraj.ivancic_at_[hidden]> wrote:
> I know how you feel. MSM is an awesome library. Unfortunately compilers tend
> to disagree :)

Indeed. I am having massive trouble boost.binding the process_event()
function, which I call from within a threaded pool like thingy. It was
so bad, I had to macro wrapper functions around it. Not even the usual
static_cast trick helped. But this is something I can live with,
considering all the benefits.

> MSM has two kinds of transition functions, actions and guards. What you are
> describing above is an action, and it is not designed to prevent the
> transition. You should use a guard. Guards have a boolean return value. For
> an example see good_disk_format() function in the SimpleTutorial.cpp in the
> MSM docs.

I know about this difference. But it doesn't cover what I mean.
Exceptions as in 'exceptional situations'. Consider the socket
example. You would probably like to use a MSM to implement a protocol.
Not when you do a transition from let's say state 'Idle' to state
'Connected' you would be able to make sure everything is ready for
connection in your guard. Like checking if you have your target
endpoint and it is correct and whatever else you need. But still, your
connect() that you would inevitably have to do in the transition may
fail. Or anything else like that. In my implementation I have a lot of
guards now checking whatever could go wrong but there's no way
eliminating all possible exception courses. I have to assume
process_event() will pass the exception to the caller and the
transition will not occur but the docs are not specific about this.
Plus since I called process event indirectly via Q and the wrapper
will not know how to deal with this case. Let alone guarantee RAII in
the transition.

I believe it would be good to be able to bind an exception handler to
each transition much like the guards, and to be able to return true or
false from that handler, depending on what this function thinks if the
exception should prevent transition or not. But this is only an idea.

Cheers,
Stephan


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