Book a Demo

Author Topic: code generation from state diagram  (Read 6974 times)

leblanc

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
code generation from state diagram
« on: June 26, 2008, 12:23:08 am »
What steps would i need to follow to be able to generate code from the state diagram in c#?

I've opened the EAExample.eap
and looking at the 3 models there:
1) Login
2) Manage Titles State
3) Search


Thanks

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: code generation from state diagram
« Reply #1 on: June 26, 2008, 02:57:37 am »
AFAIK EA does not generate code from state diagrams (yet). Search the forum and the Sparx site, as there might be an add-in to do this.
No, you can't have it!

Frank Horn

  • EA User
  • **
  • Posts: 535
  • Karma: +1/-0
    • View Profile
Re: code generation from state diagram
« Reply #2 on: June 26, 2008, 04:16:17 am »
Quote
Search the forum and the Sparx site, as there might be an add-in to do this

Haven't seen one yet, but you can roll your own if you really want to use state machines for code generation. You can either use the automation API and write am AddIn to write a code file, or you can export to xmi and write an xsl transformation with text output to be compiled.

It's intriguing of course, for often a state machine is much easier to understand than a code file, and I've tried something like that last year. Actually I didn't create code, but I implemented a kind of simple generic state machine class which uses a state machine definition class and interpretes the states and transitions. It has callback events for entering a state and entering a decision point, and an application has to handle these events. The state machine definition class is xml-serializable and my xsl transforms EA's xmi 2.1 export to it's xml representation.

Just an idea. It's not the world formula, but it eases error tracking because I can lay a printout of my state diagram beside my screen and check whether all transitions from the model are actually processed by the code.

leblanc

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: code generation from state diagram
« Reply #3 on: June 26, 2008, 09:28:31 am »
I'll like to see your implementation to see what i can extract.

i just wonder if i should write it based on xmi as you did or http://www.w3.org/TR/scxml/


rolling my own... on the surface it sounds feasible but it really is a complex and time consuming problem.

how is hierarchical statemachines supported?
how do you move to the next state ... machine.Send(.....input parameters) or is it event based? [i'll like to see an example of an event based one]

how do you support gaurds.  so if you received the correct input or event you won't go to the next state unless the gaurd is satisifed.  (should a gaurd be wrapped in its own object)


Here are some problems in rolling my own:
although i can implement the template pattern:
where my base defines:
State_Entry
State_Do
State_Exit
Send(...new input parameteres...)  ... might be different for each state machine  "params object[] values"?



here is an earlier statemachine i've done

var statemachine = new Parser.RFC1867StateMachine("--" + match.Groups["Boundary"].Value, config);
var iterator = new Parser.ByteIterator(request, config.IByteIteratorXml);

statemachine.Execute();
for (Byte b = iterator.First(); !iterator.IsDone(); b = iterator.Next())
{
    statemachine.Send(b);
}
statemachine.Terminate();



i'll look around .. if i can't find anything then i guess i'm left to hack another manually.

- lm







Frank Horn

  • EA User
  • **
  • Posts: 535
  • Karma: +1/-0
    • View Profile
Re: code generation from state diagram
« Reply #4 on: June 26, 2008, 05:55:50 pm »
Can't share my code, unfortunately, cause I did it for the company. Anyway, I didn't tackle all those complicated questions: no hierarchical state machine support.

It was a simple thing, actually. The state machine keeps track of the current state for each region, has a method to invoke a trigger by name, iterates through all outgoing transitions of all current states, and sends an EnterState callback to the application when another state is entered. The application then does whatever the new state actually means. When there is a guard on the transition, the machine sends a callback and the application decides whether the guard is fulfilled. Same if a transition goes to a decision pseudostate.

Dermot

  • EA Administrator
  • EA User
  • *****
  • Posts: 591
  • Karma: +7/-0
    • View Profile
Re: code generation from state diagram
« Reply #5 on: June 27, 2008, 04:12:00 pm »
If you are a registered user - you might like to look at this entry:
http://www.sparxsystems.com/products/mdg/tech/rtuml/beta.html