concepts.html 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?xml version='1.0' encoding='utf-8' ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  5. <title>concepts</title>
  6. <link type="text/css" rel="stylesheet" href="../style.css"/>
  7. </head>
  8. <body>
  9. <p><link href="../../../css/bootstrap.css" rel="stylesheet" />
  10. <br/><link href="../../../css/custom.css" rel="stylesheet" />
  11. </p>
  12. <h1 id="DeveloperConcepts">Developer Concepts</h1>
  13. <h2 id="APIspecificationsofthegeneratedcode">API specifications of the generated code</h2>
  14. <p>In the following comments the TrafficLight example statemachine is used to describe the API specifications of the code generated by the Yakindu C and Java code generators. The following image shows the statechart. It is a model of a simple pedestrian crossing with a traffic light for pedestrians and a traffic light for the cars.</p>
  15. <p>
  16. <img border="0" src="images/TrafficLight.png"/>
  17. </p>
  18. <p>For Java you can checkout the project &#8218;org.yakindusct.examples.trafficlight&#8217; from the Yakindu google code repository (
  19. <a href="http://svn.codespot.com/a/eclipselabs.org/yakindu/SCT2/trunk/examples">Google code link</a> ). The Java example contains the statechart, sgen model, graphical widgets and some glue code to connect the generated code with the widgets. The graphical widgets are based on SWT. To execute the Java example you can run the file &#8218;CrossingDemoCycleBased.java&#8217; as &#8218;Java Application&#8217; from the eclipse &#8218;Run As&#8217; context menu.
  20. </p>
  21. <p>For C you can checkout the project &#8218;org.yakindu.examples.c.trafficlight&#8217; from the Yakindu google code repository (
  22. <a href="http://svn.codespot.com/a/eclipselabs.org/yakindu/SCT2/trunk/examples">Google code link</a> ). The C example contains the statechart, sgen model, graphical widgets and some glue code to connect the generated code with the widgets. The graphical widgets are based on Qt. To execute the c example you can run the file org_yakindu_sct_examples_c_trafficlight as &#8218;Local C/C++ application&#8217; from the eclipse &#8218;Run As&#8217; context menu.
  23. </p>
  24. <h3 id="SpecificationsofJavacode">Specifications of Java code</h3>
  25. <p>You find the generated code in the &#8218;src-gen&#8217; folder of the traffic light example.</p>
  26. <p>In the package &#8218;org.yakindu.sct.examples.trafficlight.cyclebased&#8217; are the most basic statemachine interfaces and classes located. These are needed by each statemachine and are independend from the concrete statemachine design.</p>
  27. <p>The interface
  28. <code>IStatemachine</code> is implemented by each generated statemachine:
  29. </p>
  30. <pre><code>package org.yakindu.sct.examples.trafficlight.cyclebased;
  31. /**
  32. * Basic interface for statemachines.
  33. *
  34. *
  35. */
  36. public interface IStatemachine {
  37. /**
  38. * Initializes the statemachine. Use to init internal variables etc.
  39. */
  40. public void init();
  41. /**
  42. * Enters the statemachine. Sets the statemachine in a defined state.
  43. */
  44. public void enter();
  45. /**
  46. * Exits the statemachine. Leaves the statemachine with a defined state.
  47. */
  48. public void exit();
  49. /**
  50. * Start a run-to-completion cycle.
  51. */
  52. public void runCycle();
  53. }
  54. </code></pre>
  55. <p>It contains the four methods
  56. <code>init()</code>,
  57. <code>enter()</code>,
  58. <code>exit()</code> and
  59. <code>runCycle()</code>. The
  60. <code>init()</code> method is used to initialize the internal objects of the statemachine after instantiation. Variables are initialized to a default value. If you have initialized variables in the statechart definition these initializations are done in the init method too. The
  61. <code>enter()</code> method should be called if the statemachine is entered. It sets the statemachine into a defined state. The
  62. <code>exit()</code> method is used to leave a statemachine statefully. If for example a history state is used in one of the top regions the last active state is stored and the statemachine is leaved via
  63. <code>exit()</code> and reentered via
  64. <code>enter()</code> it continues working with this state. The
  65. <code>runCycle()</code> method is used to trigger a run to completion step in which the statemachine evaluates arising events and computes possible state changes.
  66. </p>
  67. <p>In the traffic light example timing is used (after clauses). To support this the interfaces &#8218;ITimedStatemachine&#8217;, &#8218;ITimerService&#8217; and the class &#8218;TimeEvent&#8217; are generated.</p>
  68. <pre><code>package org.yakindu.sct.examples.trafficlight.cyclebased;
  69. /**
  70. * Interface for state machines which use timed event triggers.
  71. */
  72. public interface ITimedStatemachine {
  73. /**
  74. * Set the {@link ITimerService} for the state machine. It must be set
  75. * externally on a timed state machine before a run cycle can be correct
  76. * executed.
  77. *
  78. * @param timerService
  79. */
  80. public void setTimerService(ITimerService timerService);
  81. /**
  82. * Returns the currently used timer service.
  83. *
  84. * @return {@link ITimerService}
  85. */
  86. public ITimerService getTimerService();
  87. /**
  88. * Callback method if a {@link TimeEvent} occurred.
  89. *
  90. * @param timeEvent
  91. */
  92. public void onTimeEventRaised(TimeEvent timeEvent);
  93. }
  94. </code></pre>
  95. <p>
  96. <code>ITimedStatemachine</code> extends the generated statemachine to set a
  97. <code>ITimerService</code> and provides a callback method
  98. <code>onTimeEventRaised(TimeEvent timeEvent)</code> to raise
  99. <code>TimeEvents</code>.
  100. </p>
  101. <h3 id="SpecificationsofCcode">Specifications of C code</h3>
  102. </body>
  103. </html>