tasks.textile 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. h1. Tasks
  2. h2. Modeling a statemachine
  3. # Make sure the YAKINDU Modeling perspective is active.
  4. # Create a new project.
  5. # Click *File* > *New* > *Other...* > *YAKINDU* > *YAKINDU Statechart Model*.
  6. # Click *Next* name the sct file and click *Finish*
  7. # The YAKINDU statechart editor opens on the statechart model. It already has an initial state and an unnamed simple state connected by a transition.
  8. # Now you can add states and transitions from the palette.
  9. To edit the states and transitions you can use the properties view. It has an integrated Xtext support. This makes correct editing easier. You can also change the appearance of the model elements.
  10. On the palette you will also find a composite submachine state. This is a state that contains a complete statemachine. You can choose an existing statemachine or create a new one.
  11. h3. Related topics
  12. "Statemachine Elements reference":../05_Reference/reference.html#Statechartelements
  13. "Textual modeling lanuage Reference":../05_Reference/reference.html#Statechartdescriptionlanguage
  14. h2. Validating a statemachine
  15. The statemachine is validated automatically during build. The elements that cause problems get error markers. You can find the details about the problems on the problems view.
  16. h2. Simulating a statemachine
  17. The YAKINDU simulation engine supports simulation modes:
  18. * event driven
  19. * cycle based
  20. The default setting is _cycle based_ with a cycle period of 200 ms. In this mode the simulation engine processes the state machine transitions in steps of the given cycle duration. The following statechart illustrates this. It is simulated cycle based with a cycle period of 3 seconds.
  21. !images/cycleBasedVsEventDriven.png!
  22. What happend during simulation is the following:
  23. # After 3s *init* switches to *pre1*
  24. # After 3 further seconds recursive transition to *pre1* is processed (not after 2s the transition says)
  25. # After 3 further seconds recursive transition to *pre1* is processed again and the condition becomes *true* so *result* gets activated
  26. In contrast to cycle based the event driven simulation mode concentrates on the events of a state machine. The same state machine above could be simulated as follows:
  27. # Immediately *init* switches to *pre1*
  28. # Immediately the event *touch* is raised twice
  29. # The condition becomes true so that the *result* state is reached after 2 or 3 seconds instead of 9
  30. Start a simulation with the different modes as follows
  31. # Make sure the YAKINDU Simulation Perspectiv is opened.
  32. # Start the simulation by clicking *Run* > *Run Configurations...*.
  33. # Select the statechart you want to simulate and the simulation mode.
  34. # *Apply* the setting and *Run* the simulation.
  35. !images/simulationRunConfiguration.png!
  36. "Simulation Concept":../03_Concepts/concepts.html#Simulation
  37. "Simulation perspective":../03_Concepts/concepts.html#YakinduSCSimulationperspective
  38. "Simulation View":../03_Concepts/concepts.html#SimulationView
  39. h2. Generating Code
  40. For configuring the code generation process, YAKINDU Statechart Tools uses a textual generator model called *SGen*. It can be created either by using the provided wizard *Yakindu Statechart Generator Model* or by creating a new text file with the file extension '.sgen'.
  41. To create a generator model with the wizard,
  42. # Click *File* > *New* > *Other...* > *Yakindu Statechart Generator Model*
  43. # Type a name and click *Next*
  44. # Choose the desired generator, i.e. *YAKINDU Java Code Generator*
  45. # Check the model(s) to generate code from and click *Finish*
  46. !images/genmodelwizardchooselanguage.jpg!
  47. The result is an .sgen file of the following format:
  48. bc..
  49. GeneratorModel for [GeneratorId] {
  50. statechart [StatechartReference] {
  51. feature [Feature] {
  52. [ParameterName] = [ParameterValue]
  53. }
  54. }
  55. }
  56. p. The [GeneratorId] is the unique id of the Generator. Currently, the following Generators are supported out of the box:
  57. # yakindu::java - Generator ID for the Java Code Generator
  58. # yakindu::c - Generator ID for the C Code Generator
  59. # yakindu::cpp - Generator ID for the C++ Code Generator
  60. # yakindu::xpand - Generator ID for custom Xpand based Code Generators
  61. # yakindu::generic - Generator ID for custom Java based Code Generators
  62. One GeneratorModel can contain several [StatechartReference]s. These are cross references to statechart models for which the code should be generated. For each reference, the generator process can be configured with [Feature]s. Each Feature consists of several parameters. These parameters can be configured with [ParameterName] = [ParameterValue].
  63. The Generator Model is executed by a builder. Thus, the artifacts are generated automatically if *Project* > *Build Automatically* is checked. If you want to execute your Generator Model by hand, select *Generate Statechart Artifacts* from the *Package Explorer's* context menu.
  64. h2. Core Features
  65. The following section describes the *Core Features* which are available for all code generators:
  66. ==<!-- Start sgen_feature_outlet -->==
  67. h4. Outlet
  68. The *Outlet* feature specifies the target project and folder for the generated artifacts. It is a *required* feature and consists of the following parameters:
  69. # __targetProject__ (String, required): The project to store the generated artifacts
  70. # __targetFolder__ (String, required): The folder to store the generated artifacts
  71. Example configuration:
  72. bc..
  73. feature Outlet {
  74. targetProject = "ExampleProject"
  75. targetFolder = "src-gen"
  76. }
  77. p. ==<!-- End sgen_feature_outlet -->==
  78. ==<!-- Start sgen_feature_licenseheader -->==
  79. h4. LicenseHeader
  80. The *LicenseHeader* feature specifies the license text that should be added as a header to the generated artifacts. It is an *optional* feature and consists of the following parameters:
  81. # __licenseText__ (String, required): The license text to add as a header
  82. Example configuration:
  83. bc..
  84. feature LicenseHeader {
  85. licenseText = "Copyright (c) 2012 committers of YAKINDU and others."
  86. }
  87. p. ==<!-- End sgen_feature_licenseheader -->==
  88. ==<!-- Start sgen_feature_functioninlining -->==
  89. h4. FunctionInlining
  90. The *FunctionInlining* feature allows the inlining of expressions instead of generating separate functions or methods. This might reduce the readability of the generated code, but increases performance because less operation calls are necessary.
  91. It is an *optinal* feature and consists of the following parameters:
  92. # __inlineReactions__ (Boolean, optional): Inlines the expression for reactions
  93. # __inlineEntryActions__ (Boolean, optional): Inlines the expression for entry actions
  94. # __inlineExitActions__ (Boolean, optional): Inlines the expression for exit actions
  95. # __inlineEnterSequences__ (Boolean, optional): Inlines the expression for enter sequences
  96. # __inlineExitSequences__ (Boolean, optional): Inlines the expression for exit sequences
  97. # __inlineChoices__ (Boolean, optional): Inlines the expression for choices
  98. # __inlineEnterRegion__ (Boolean, optional): Inlines the expression for enter regions
  99. # __inlineExitRegion__ (Boolean, optional): Inlines the expression for exit regions
  100. # __inlineEntries__ (Boolean, optional): Inlines the expression for entries
  101. Example configuration:
  102. bc..
  103. feature FunctionInlining {
  104. inlineChoices = false
  105. inlineEnterRegion = true
  106. inlineEntries = true
  107. }
  108. p. ==<!-- End sgen_feature_functioninlining -->==
  109. ==<!-- Start sgen_feature_debug -->==
  110. h4. Debug
  111. The *Debug* feature dumps the Execution Model to the target folder as xmi model. It is an *optional* feature and consists of the following parameters:
  112. # __dumpSexec__ (Boolean, required): The license text to add as a header
  113. Example configuration:
  114. bc..
  115. feature Debug {
  116. dumpSexec = true
  117. }
  118. p. ==<!-- End sgen_feature_debug -->==
  119. h2. Java Generator Features
  120. ==<!-- Start sgen_feature_naming -->==
  121. h4. Naming
  122. The *Naming* feature allows the configuration of package names as well as class name prefix / suffix.
  123. It is an *optional* feature and consists of the following parameters:
  124. # __basePackage__ (Boolean, required): The package to create for the generated java classes
  125. # __implementationSuffix__ (Boolean, optional): The suffix for the implementing classes
  126. Example configuration:
  127. bc..
  128. feature Naming {
  129. basePackage = "org.yakindu.sct"
  130. implementationSuffix = "Impl"
  131. }
  132. p. ==<!-- End sgen_feature_naming -->==
  133. ==<!-- Start sgen_feature_generalfeatures -->==
  134. h4. GeneralFeatures
  135. The *GeneralFeatures* feature allows to configure additional services to generate with the statemachine. Per default, all parameters are configured to __false__ It is an *optional* feature and consists of the following parameters:
  136. # __EventBasedStatemachine__ (Boolean, optional): Enables/disables the generation of a cycle based statemachine implementation
  137. # __InterfaceObserverSupport__ (Boolean, optional): Enables/disables the generation of listener interfaces for the statemachine
  138. # __RuntimeService__ (Boolean, optional): Enables/disables the generation of a runtime service that triggers the runcycle of a cycle based statemachine
  139. # __TimerService__ (Boolean, optional): Enables/disables the generation of a timer service implementation using __java.util.Timer__
  140. # __GenericInterfaceSupport__ (Boolean, optional): Enables/disables the generation of generic interfaces
  141. # __StatemachineFactorySupport__ (Boolean, optional): Enables/disables the generation of a factory class
  142. Example configuration:
  143. bc..
  144. feature GeneralFeatures {
  145. EventBasedStatemachine = true
  146. InterfaceObserverSupport = true
  147. RuntimeService = true
  148. TimerService = true
  149. GenericInterfaceSupport = true
  150. StatemachineFactorySupport = true
  151. }
  152. p. ==<!-- End sgen_feature_generalfeatures -->==
  153. h2. C Generator Features
  154. ==<!-- Start sgen_feature_ccodefeature -->==
  155. h4. CCodeFeature
  156. The *CCodeFeature* feature allows to configure c code specific generator properties. It is an *optional* feature and consists of the following parameters:
  157. # __InterfaceEventListener__ (Boolean, mandatory): generates listener interface for notification of outgoing events.
  158. # __Singleton__ (Boolean, mandatory): generates a statically allocated singleton variant of the state machine that does not allow multiple instances.
  159. # __DebugType__ (String, optional): don't use this property - it will be removed
  160. Example configuration:
  161. bc..
  162. feature CCodeFeature {
  163. InterfaceEventListerner = true
  164. Singleton = true
  165. }
  166. p. ==<!-- End sgen_feature_ccodefeature -->==
  167. h2. Create Custom Code Generators
  168. YAKINDU Statechart Tools provides a rich feature set to supports custom code generators out of the box. These code generators can be either written in Java, "Xtend":http://www.eclipse.org/xtend/ or in "Xpand":http://www.eclipse.org/modeling/m2t/?project=xpand
  169. h3. Writing a custom code generator with Xtend2/Java
  170. First, you have to create a new Xtend2 generator project. Click *File* > *New* > *Other...* > *YAKINDU* > *YAKINDU Xtend2/Java Generator Project* to create a new Xtend2 Generator Project.
  171. !images/xtendGenerator.png!
  172. The wizards asks for a *Project name* and the name of the *Generator class*, where you have to specify a full qualified class name. If you check the *Use Xtend* checkbox, the Generator class will be initially created as an "Xtend":http://www.eclipse.org/xtend/ class. Otherwise, Java will be used for the generator.
  173. The check box *Configure for Plugin Export* adds all required extension point registrations to the new project for exporting as a plugin The Generator Model can refer to the new Generator Plugin via its unique *Generator ID*. If you want to contribute custom generator features for your code generator, check the *Create Feature Library* check box.
  174. After click on *Finish* a new project is created in your workspace. All required plugin dependencies and extension points are registered and you can start to write your code generator based on the ExecutionFlow meta model [Link].
  175. h3. Executing a custom Xtend2/Java code generator
  176. YAKINDU Statechart Tools provide a convenient way to execute your generator while you are developing it.
  177. Therefore, you have to create a new *Generator Model* with the generator id *yakindu::generic*, either by using the *New Statechart Generator Model* wizard or by simple creating a new text file with the file extension *.sgen*. the following feature allows to configure your code generator.
  178. ==<!-- Start sgen_feature_generator -->==
  179. h4. Generator
  180. The *Generator* feature allows the configuration of a custom code generator located in the workspace and written in Java or another JVM language. It is a *required* feature and consists of the following parameters:
  181. # __generatorProject__ (String, required): The name of the generator project
  182. # __generatorClass__ (String, required): The full qualified class name of the code generator class.
  183. # __configurationModule__ (String, optional): The full qualified class name for a guice module to configure the code generator
  184. Example configuration:
  185. bc..
  186. feature Generator {
  187. generatorProject = "org.yakindu.sct.mygenerator"
  188. generatorClass = "org.yakindu.sct.MyGenerator"
  189. }
  190. p. ==<!-- End sgen_feature_generator -->==
  191. h3. Executing a custom Xpand code generator
  192. to execute an xpand based custom code generator, you have to create a new *Generator Model* with the generator id *yakindu::xpand*, either by using the *New Statechart Generator Model* wizard or by simple creating a new text file with the file extension *.sgen*. the following feature allows to configure your code generator.
  193. ==<!-- Start sgen_feature_template -->==
  194. h4. Template
  195. The *Generator* feature allows the configuration of a custom code generator located in the workspace and written in Java or another JVM language. It is a *required* feature and consists of the following parameters:
  196. # __templateProject__ (String, required): The name of the generator project
  197. # __templatePath__ (String, required): The full qualified template path to the main template.
  198. Example configuration:
  199. bc..
  200. feature Template {
  201. templateProject = "ExampleProject"
  202. templatePath = "org::yakindu::sct::generator::xpand::Main::main"
  203. }
  204. p. ==<!-- End sgen_feature_template -->==