Book a Demo

Author Topic: State internal transitions  (Read 7146 times)

deefer

  • EA User
  • **
  • Posts: 98
  • Karma: +0/-0
    • View Profile
State internal transitions
« on: October 28, 2009, 12:30:40 am »
Hi
is there the possibility to specify internal transitions in a state as described in this article?
http://www.embedded.com/215801390?pgno=5

Note that they are different from self-transitions.
Many thanks,
Davide

Makulik

  • EA User
  • **
  • Posts: 400
  • Karma: +0/-0
    • View Profile
Re: State internal transitions
« Reply #1 on: October 28, 2009, 01:04:16 am »
Hi Davide,

Yes it's possible. Firstly internal transitions are occuring in a compound (composite) states' interior. A self transition is shown as a state external path, that's what makes up the semantical difference in an UML state diagram in general.
What else are you missing in EA's representation of state transitions? May be I can give you more hints if you're more precise (didn't read the whole article you have mentioned for now).

HTH
Günther

deefer

  • EA User
  • **
  • Posts: 98
  • Karma: +0/-0
    • View Profile
Re: State internal transitions
« Reply #2 on: October 28, 2009, 01:11:23 am »
Hi Günther,

as far as I've undertood, the one you have described is self-transition which is different from the internal transition because in the first one teh entry/exit actions are always executed, while in the second one they are not.

I was thinking that perhaps what I need is to specify a do action, stereotyped by <<signal>>... the name of the action would be the name of the signal (trigger).
What do you think about it?
Davide

Makulik

  • EA User
  • **
  • Posts: 400
  • Karma: +0/-0
    • View Profile
Re: State internal transitions
« Reply #3 on: October 28, 2009, 03:58:34 am »
Hi Davide,

What I have described is the difference of internal and external state transitions as they're shown in fig. 2.7 of your article.
I think you should consider the states' do action as the event processing loop that triggers the internal transitions as defined in the (composite) states interior, and not as being the transition itself. The only exception I know for state diagrams to go to an internal state directly from an external transition path (without passing through the entry action(s)) is to resume a state history.
Somehow entry, exit and do can be also considered as state internal transitions (with a number of actions attached), but there are no signals/events specified to trigger them, but only the states/state machines general behavior does so.
UML 2.1 allows the notational (short) form of specifying internal transitions as shown in the articles figure 2.8. With EA you can achieve that notation specifying a state operation, typing the event name instead of the preselectable do/entry/exit 'Action'. But I don't know how these can be bound to any event specified for the modeled state machine.
The equivalent thing (as in the keyboard sample) can be expressed having a single internal state 'wait_for_kbd_event' inside the 'default' and 'caps_locked' states, with a self transition triggered by a 'ANY_KEY' event and the appropriate actions attached to it. OK, the short form is more useful for this, I agree.

HTH
Günther

g.makulik

  • EA User
  • **
  • Posts: 355
  • Karma: +0/-0
    • View Profile
Re: State internal transitions
« Reply #4 on: October 28, 2009, 06:51:33 am »
Hi again,

I've just checked what EA's standard C++ code generation template does with do actions, and found that the specified operations will be executed just before triggering any events. Have to check further what will be generated for internal transition notation as I have described it in my recent post.
So hold on ...

WBR
Günther
Using EA9.3, UML2.3, C++, linux, my brain, http://makulik.github.com/sttcl/

deefer

  • EA User
  • **
  • Posts: 98
  • Karma: +0/-0
    • View Profile
Re: State internal transitions
« Reply #5 on: October 28, 2009, 08:22:37 pm »
Hi Günther
thanks for your help !

I've tryed with the code generation but EA doesn't manage the internal transition notation of the example... it treats it like a normal do operation...  :(

Since it seems you are very familiar with state machines (which I'm not  :-/), I would like to ask you some clarification on signals to classes and state machines:

Lets say that my class has a state machine, and I define transitions in the state machine triggered by triggers.

How should I model the triggers in the interfaces provided by the class? How the trigger information can be conveyed down to the state machine?

Many thanks
Davide

Makulik

  • EA User
  • **
  • Posts: 400
  • Karma: +0/-0
    • View Profile
Re: State internal transitions
« Reply #6 on: October 28, 2009, 10:51:43 pm »
Hi davide,

I think that the 'triggers' (events, signals) that can be received by a state machine class setup an interface with either operations for each accepted event (e.g. handleXYZ(), where XYZ is the name of the event), or a more common single operation that determines what actual event occurred by its parameters. This interface will be the main client interface to interact with the state machine.
I would recommend you to have a look at the GoF State design pattern, which gives a quite good approach how to handle state machines with an OO design IMHO.

Note that EA's code generation doesn't follow this approach, but just does more or less the good old dumb switch/case monolithic state machine realization that's known well, but has it's certain drawbacks.

If you leave your email in my message box, I can give you some more material about this topic, since I'm currently developing a (C++) state machine framework based on the State design pattern in my spare time.

WBR
Günther

g.makulik

  • EA User
  • **
  • Posts: 355
  • Karma: +0/-0
    • View Profile
Re: State internal transitions
« Reply #7 on: October 29, 2009, 11:59:52 am »
Hi Davide,

That article you found is a really really good one.
Stick with it ...

WBR
Günther
Using EA9.3, UML2.3, C++, linux, my brain, http://makulik.github.com/sttcl/

ersteslicht

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: State internal transitions
« Reply #8 on: October 31, 2009, 09:40:57 pm »
Hi Günter,
i am not familiar with statemachines and code generation. i learned how Gof State Design Pattern works and EA has another template. I dont understand the pattern they use. can you tel me how i have to start? and i coundt find any simple example. for example, 1 class and 2 states that i learn how should i work with the generated code. can you send me a very simple example?
best,
ersteslicht

g.makulik

  • EA User
  • **
  • Posts: 355
  • Karma: +0/-0
    • View Profile
Re: State internal transitions
« Reply #9 on: November 01, 2009, 10:12:51 am »
Hi ersteslicht,

The pattern of EA FSM code generation uses, is to introduce an event driven loop to the class containing the state machine in the model.
It's exactly what GoF State pattern teaches us to avoid, because it'll become pretty messy and hard to maintain code as it evolves, when more states, transitions or events (triggers) need to be added.
Event driven loop has it's advantages also, if you need to work with very limited devices or really really tough performance requirements.

It's possible to adjust the EA code generation templates to achieve different renderings of state machines in code. But this has currently certain drawbacks also:
  • Code (re-)engineering of the generated code doesn't synchronize the SM model (that's also true for the default templates)
  • If you're generating classes instead of state functions they'll still all be placed in the same file(s)

The currently most promising attempt to do SM code generation with EA seems for me, to use it for a FSM DSL that provides an appropriate compiler for your target language (as SMC for example). That's also discussed in another thread in the forum (see http://www.sparxsystems.com/cgi-bin/yabb/YaBB.cgi?num=1256588736).

I have also a proposal for a C++ template class library that purposes to help for translation from UML state diagrams to GoF State pattern like constructs. But I'm still far from providing EA code generation templates for it. For this I still think, I would need to be able to do a model transformation from state machine to class model (which the State pattern also does). But EA doesn't provide EASL templates for model transformation.
@all_sparxians_reading_here:
Why don't you guys, is it that much difference? Recently one of you confirmed that it's all the same, for code or transformation intermediate language.

So, if you're interested in my draft documentation for the C++ lib, leave your email in the message box of this account (the other's in my workplace), and I'll hand it over.

WBR
Günther
Using EA9.3, UML2.3, C++, linux, my brain, http://makulik.github.com/sttcl/

DanG83616

  • EA User
  • **
  • Posts: 180
  • Karma: +0/-0
    • View Profile
Re: State internal transitions
« Reply #10 on: September 29, 2010, 03:53:46 pm »