123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686 |
- <link href="../../css/bootstrap.css" rel="stylesheet" />
- h1. SCT Reference
- h2. Statechart elements
- In the following the state chart elements of the YAKINDU SCT 2 editor are described. The meta model of the YAKINDU SCT 2 is the model of finite state machines. It is based on the view of a system that is defined by a finite number of states. The behavior of that system is based on the active states. These states are determined by the history of the state machine. Very important are the theoretical models for state machines by Mealy and Moore. Mealy state machines associate actions with transitions. Moore machines associate actions with states (entry, exit). In the YAKINDU SCT 2 both is possible.
- The YAKINDU SCT 2 meta model is designed similar to the UML state chart meta model with the following differences
- * they are self contained with interfaces defined by events and variables
- * core execution semantics are cycle driven, not event driven
- ** this allows to process concurrent events
- ** event driven behavior can be defined on top
- * time is an abstract concept for state charts
- * time control is delegated to the environment
- The model interpreter and different flavors of generated code follow these same core semantics.
- Please refer to the description of the "UML Statecharts":http://en.wikipedia.org/wiki/UML_state_machine for more details.
- h3. Regions
- As already mentioned the YAKINDU state charts are self contained. They are organized in regions. Due to this it is possible to organize multiple state machines in different regions and to run them concurrently.
- !images/parallelRegions.jpg!
- h3. States
- States are the central elements of a state machine. A state has to be placed inside a region and needs a unique name inside this region. During simulation each state can be active or passive. An active state has actions that are accomplished. Either an action is carried out on entering a state, during active state or on exit.
- h3. Transitions
- A transition is the transfer of one state to another. Transitions are diagrammed as arrows and can carry events and actions but must not.
- The syntax of events and actions is defined by a textual description language (#Statechartdescriptionlanguage). Please refer to the documentation section "Events":#Events for more details. For more details on Actions refer to the chapter "Actions":#ReactionTriggers.
- If a state has more than one outgoing transition without event that transition is carried out first that was modeled first.
- h3. Initial state and final state
- Initial and final states are pseudo states, because the state chart does not rest on them. Pseudo states express characteristics that are impossible to express by simple states.
- The initial state is always the first state that is active during interpretation or simulation of the state machine. An initial state can only have one outgoing transition and no incoming. This transition has no events or actions.
- Inside a region only one initial state is allowed, but every region can have an initial state.
- h3. Choice
- Choice is also a pseudo state. It can be used to model a conditional path. Choice nodes divide a transition into multiple parts.
- Usually the first transition points towards the choice node. One of the choice outgoing transitions can carry a condition.
- h3. Junction
- A junction is a pseudo state do combine transitions. This is very comfortable if a state machine has many similar transitions. Junctions add clear arrangement to the state machine.
- h3. Composite State
- A composite state is a state that is composed of other state machines. These are also organized in regions. Besides the simple composite state YAKINDU knows two kinds of composite states: orthogonal state and submachine states.
- Composite states contain other state machine branches.
- h4. Orthogonal states
- In the context of state machines orthogonal states are states that are independent from each other. The most famous example is the keyboard example:
- !images/orthogonalState_example.jpg!
- h4. Submachine states
- Submachine states may contain complete state machines. Here the user can chose another state machine to be included or create a new sub statemachine. During simulation only the top level statemachine is interpreted. It is not possible to jump to the sub level state machines and back.
- !images/substatemachine_example.jpg!
- h3. Shallow History
- The shallow history state is a pseudo state that is placed inside regions of composite states. It is used to 'remember' the last active state inside a composite state. So it is possible to jump to this state instead of starting at the inner entry state again. The following example of a questionaire answering will explain this:
- !images/shallowHistory01.jpg!
- The interesting parts in this state chart are the events _checkProgress_ and _goon_. CheckProgress jumps back to the init state while assigning the current progress count to the variable _temp_. _goon_ jumps to the shallow history state that was placed inside the composite state.
- !images/shallowHistory02.jpg!
- !images/shallowHistory03.jpg!
- On triggering the _goon_ event the last active state is activated again.
- h3. Deep History
- Deep history is similar to shallow history but more complex. With a deep history the latest state of multiple nested states is remembered.
- h2. Statechart description language
- The textual description language is used to declare and describe behaviors in the state machine. It is case sensitive.
- h3. Typesystem
- The language has an integrated small typesystem with the following simple types:
- * integer
- * real
- * boolean
- * string
- * void
- So events and variables can be declared with types:
- bc..
- var intVar : integer
- var realVar : real
- var boolVar : boolean
- var stringVar : string
- var voidVar : void
- event addInt : integer
- event checkValidity : boolean
-
- h3. Expressions
- Expressions can be defined similar to other programming languages. The language offers operators to define logical expressions, bitwise arithmetic, and arithmetic expressions and bit shifting.
- Logical expressions are similar to other programming languages. The return type is *boolean*. In the following there are some examples of these:
- h4. Logical AND
- bc..
- var1 && var2
- h4. Logical OR
- bc..
- var1 || var2
- h4. Logical NOT
- bc..
- !var1
- h4. Conditional expression
- bc..
- var1 ? var2 : 23
- h4. Bitwise XOR
- bc..
- var1 ^ var2
- h4. Bitwise OR
- bc..
- var1 | var2
- h4. Bitwise AND
- bc..
- var1 & var2
- h4. Logical Relations and Shift Operators
- |less than | < |
- |equal or less than | <= |
- |greater than | > |
- |equal or greater than | >= |
- |equal | == |
- |not equal | != |
- |shift left | << |
- |shift right | >> |
- h4. Binary arithmetic operators
- |plus | + |
- |minus | - |
- |multiply | * |
- |divide | / |
- |modulo | % |
- h4. Unary arithmetic operators
- |positive | + |
- |negative | - |
- |complement | ~ |
- h3. Statements
- A statements can be either an assignment, raising an event or call an operation. The language has the following assignment operators:
- * simple assignment: =
- * multiply and assign: *=
- * divide and assign: /=
- * calculate modulo and assign: %=
- * add and assign: +=
- * subtract and assign: -=
- * bitshift left and assign: <<=
- * bitshift right and assign: >>=
- * bitwise AND and assign: &=
- * bitwise XOR and assign: ^=
- * bitwise OR and assign: @|=@
- An event is raised by the keyword _raise_ followed by the event name and if it is an interface event the name of the interface.
- An operation is called similar to other programming languages with the operation name and passing concrete parameters. The parameters can be expressions.
- h3. Scopes
- ==<!-- Start stext_keyword_namespace -->==
- h4. Namespace
- The language allows to define unique namespaces, which can be used to qualify references to the statechart.
- bc..
- namespace trafficlights
- p. ==<!-- End stext_keyword_namespace -->==
- ==<!-- Start stext_keyword_interface -->==
- h4. interface scope
- Declarations in the interface scope are externally visible. They can be shared within the environment.
- bc..
- interface NamedInterface:
- in event event1
- out event event3
- var variable1 : real
- entrypoint entry1
- exitpoint exit1
- p. ==<!-- End stext_keyword_interface -->==
- ==<!-- Start stext_keyword_internal -->==
- h4. internal scope
- Declarations made in an internal scope are only visible for contained states.
- bc..
- internal:
- var localVariable1: integer
- event localEvent: integer
- local event localEvent2: NamedInterface.event1 || localEvent
- local event localEvent3: localEvent || localEvent2 : 25
- operation localOperation (integer, integer): integer
- localEvent3 / raise NamedInterface.event3 :
- localOperation(valueOf(localEvent),NamedInterface.variable1);
- p. ==<!-- End stext_keyword_internal -->==
- h3. Declarations
- Within scopes there can be declarations of Events, Variables, Operations, LocalReactions, EntryPoints and ExitPoints.
- ==<!-- Start stext_keyword_event -->==
- h3. Events
- Within interface scope events have an direction. They can either be ingoing or outgoing:
- bc..
- interface NamedInterface:
- in event event1
- out event event2
- p. Within local scope events can carry variables:
- bc..
- internal:
- event localEvent1 : integer
- p. Local events can be derived from interface events or other local events and can have a value assignment:
- bc..
- internal:
- event localEvent1: integer
- local event localEvent2 = NamedInterface.event1 || localEvent1
- local event localEvent3 = localEvent2 || 25
- p. ==<!-- End stext_keyword_event -->==
- ==<!-- Start stext_keyword_var -->==
- h3. Variables
- Variables can have different visibilities. They can be visible for the environment:
- bc..
- var variable1: real
- p. Variables can be *readonly* (constants):
- bc..
- var readonly pi: real = 3.1415
- p. Variables can be referenced by the environment.
- bc..
- var external variable3: integer = 34
- p. ==<!-- End stext_keyword_var -->==
- h3. Reaction Triggers
- Actions are key constructs in state machines to model behavior. The YAKINDU SCT 2 knows the following kinds of actions.
- ==<!-- Start stext_keyword_after -->==
- h4. after
- The _after_ trigger specifies one-shot time events.
- After the specified time the reaction is triggered. An _after_ trigger can be used in transitions of states as well in local reactions of states and statecharts. The specified time starts when the state or statechart is entered.
- bc. after 20 s
- Structure:
- @after@ _@time@_ (_@unit@_)?
- The time unit can be:
- * ==<!-- Start stext_keyword_s -->== s - seconds ==<!-- End stext_keyword_s -->==
- * ==<!-- Start stext_keyword_ms -->== ms - milliseconds ==<!-- End stext_keyword_ms -->==
- * ==<!-- Start stext_keyword_us -->== us - microseconds ==<!-- End stext_keyword_us -->==
- * ==<!-- Start stext_keyword_ns -->== ns - nanoseconds ==<!-- End stext_keyword_ns -->==
- * empty - implies seconds
- p. ==<!-- End stext_keyword_after -->==
- ==<!-- Start stext_keyword_every -->==
- h4. every
- The _every_ trigger specifies periodic time events.
- The reaction is triggered periodically after the specified time. An _every_ trigger can be used in transitions of states as well in local reactions of states and statecharts. The specified time starts when the state or statechart is entered and repeats periodically.
- bc. every 200 ms
- Structure:
- @every@ _@time@_ (_@unit@_)?
- The time unit can be:
- * s - seconds
- * ms - milliseconds
- * us - microseconds
- * ns - nanoseconds
- * empty - implies seconds
- ==<!-- End stext_keyword_every -->==
- ==<!-- Start stext_keyword_always -->==
- h4. always
- This trigger is always true and enables a reaction to be executed in every run to completion step (RTS). It is equivalent to _oncycle_.
- ==<!-- End stext_keyword_always -->==
- ==<!-- Start stext_keyword_default -->==
- ==<!-- Start stext_keyword_else -->==
- h4. default, else
- The _default_ trigger is equivalent to the _else_ trigger. It is intended for use for the outgoing transitions of _choice_ pseudo states, to make sure that always an outgoing transition can be taken. It can only be be used in transitions and implies the lowest evaluation priority for that transition.
- ==<!-- End stext_keyword_else -->==
- ==<!-- End stext_keyword_default -->==
- ==<!-- Start stext_keyword_entry -->==
- h4. entry
- An _entry_ trigger marks actions that are carried out on entering a state or state machine.
- ==<!-- End stext_keyword_entry -->==
- ==<!-- Start stext_keyword_exit -->==
- h4. exit
- An _exit_ trigger marks actions that are carried out on exiting a state or state machine.
- ==<!-- End stext_keyword_exit -->==
- ==<!-- Start stext_keyword_oncycle -->==
- h4. oncycle
- The _oncycle_ trigger is always true and enables a reaction to be executed in every run to completion step (RTS). It is equivalent to _always_.
- ==<!-- End stext_keyword_oncycle -->==
- ==<!-- Start stext_keyword_operation -->==
- h3. Operations
- Operations can have none, one or multiple parameters. The parameters are only declarated by their type. An operation can have one return type similar to Java.
- bc..
- operation localOperation (integer, integer):integer
- localEvent3/ raise NamedInterface3.event1
- p.
- ==<!-- End stext_keyword_operation -->==
- h3. Build-In Functions
-
- ==<!-- Start stext_keyword_valueof -->==
-
- h4. valueof(event)
- Returns the value of an valued event that it passed to the function as parameter.
- bc..
- myVar = valueof(myEvent)
- p.
- ==<!-- End stext_keyword_valueof -->==
- ==<!-- Start stext_keyword_active -->==
- h4. active(state)
- Returns "true" if a state is active or "false" otherwise.
- bc..
- myBool = active(StateA)
- p.
- ==<!-- End stext_keyword_active -->==
- h3. LocalReactions
- Local reactions describe the internal behavior of a state. So they have internal scope. A local reaction is declared as follows:
- bc..
- LocalReaction: ReactionTrigger '/' ReactionEffect ('#' ReactionProperties)?
- ReactionTrigger: (Event ("," Event )* (=> '[' Expression ']')?) | '[' Expression ']'
- ReactionEffect: Statement (';' Statement )* (';')?
- Statement: Assignment | EventRaising | OperationCall
- ReactionProperties: (EntryPoint | ExitPoint)*
- p. Within a local reaction an interface event can be raised:
- bc..
- internal:
- localEvent1 / raise NamedInterface.event3 : localOperation (valueOf(localEvent), NamedInterface.variable1);
- p. Local reactions can have priority values. These are defined by a following # and the integer number of priority:
- bc..
- localEvent2 / NamedInterface.variable2 += 3; #1
- localEvent3 / NamedInterface.variable4 += 2.0; #2
- p. ==<!-- Start stext_keyword_entrypoint -->==
- h3. EntryPoints
- Every state chart has an entry point. An entry point can be declared like the following:
- bc..
- entrypoint entry1
- p. ==<!-- End stext_keyword_entrypoint -->==
- ==<!-- Start stext_keyword_exitpoint -->==
- h3. ExitPoints
- Every state chart has an exit point. This exit point can be declared like the following.
- bc..
- exitpoint exit1
- p. ==<!-- End stext_keyword_exitpoint -->==
- h2. SGen Generator Features
- All generators can be customized with a generator model. This is a textual model file where generator features, like i.e. the outlet path, can be specified. The following screenshot shows an example configuration for the java code generator.
- To get started with the generator model, we included a new Eclipse wizard that creates a basic configuration file with default values.
- !images/sGenEditor.png!
- The generator model is associated with the builder. If *Project* > *Build Automatically* is checked the files are generated. In the following the specific customizing features of the generator models are explained.
- The following section describes the *Core Features* which are available for all code generators:
- ==<!-- Start sgen_feature_outlet -->==
- h4. Outlet
- The *Outlet* feature specifies the target project and folder for the generated artifacts. It is a *required* feature and consists of the following parameters:
- # __targetProject__ (String, required): The project to store the generated artifacts
- # __targetFolder__ (String, required): The folder to store the generated artifacts
- Example configuration:
- bc..
- feature Outlet {
- targetProject = "ExampleProject"
- targetFolder = "src-gen"
- }
- p. ==<!-- End sgen_feature_outlet -->==
- ==<!-- Start sgen_feature_licenseheader -->==
- h4. LicenseHeader
- 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:
- # __licenseText__ (String, required): The license text to add as a header
- Example configuration:
- bc..
- feature LicenseHeader {
- licenseText = "Copyright (c) 2012 committers of YAKINDU and others."
- }
- p. ==<!-- End sgen_feature_licenseheader -->==
- ==<!-- Start sgen_feature_functioninlining -->==
- h4. FunctionInlining
- 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.
- It is an *optinal* feature and consists of the following parameters:
- # __inlineReactions__ (Boolean, optional): Inlines the expression for reactions
- # __inlineEntryActions__ (Boolean, optional): Inlines the expression for entry actions
- # __inlineExitActions__ (Boolean, optional): Inlines the expression for exit actions
- # __inlineEnterSequences__ (Boolean, optional): Inlines the expression for enter sequences
- # __inlineExitSequences__ (Boolean, optional): Inlines the expression for exit sequences
- # __inlineChoices__ (Boolean, optional): Inlines the expression for choices
- # __inlineEnterRegion__ (Boolean, optional): Inlines the expression for enter regions
- # __inlineExitRegion__ (Boolean, optional): Inlines the expression for exit regions
- # __inlineEntries__ (Boolean, optional): Inlines the expression for entries
- Example configuration:
- bc..
- feature FunctionInlining {
- inlineChoices = false
- inlineEnterRegion = true
- inlineEntries = true
- }
- p. ==<!-- End sgen_feature_functioninlining -->==
- ==<!-- Start sgen_feature_debug -->==
- h4. Debug
- 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:
- # __dumpSexec__ (Boolean, required): The license text to add as a header
- Example configuration:
- bc..
- feature Debug {
- dumpSexec = true
- }
- p. ==<!-- End sgen_feature_debug -->==
- h2. Java Generator Features
- ==<!-- Start sgen_feature_naming -->==
- h4. Naming
- The *Naming* feature allows the configuration of package names as well as class name prefix / suffix.
- It is an *optional* feature and consists of the following parameters:
- # __basePackage__ (Boolean, required): The package to create for the generated java classes
- # __implementationSuffix__ (Boolean, optional): The suffix for the implementing classes
- Example configuration:
- bc..
- feature Naming {
- basePackage = "org.yakindu.sct"
- implementationSuffix = "Impl"
- }
- p. ==<!-- End sgen_feature_naming -->==
- ==<!-- Start sgen_feature_generalfeatures -->==
- h4. GeneralFeatures
- 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:
- ==<!-- # __EventBasedStatemachine__ (Boolean, optional): Enables/disables the generation of a cycle based statemachine implementation -->==
- # __InterfaceObserverSupport__ (Boolean, optional): Enables/disables the generation of listener interfaces for the statemachine
- # __RuntimeService__ (Boolean, optional): Enables/disables the generation of a runtime service that triggers the runcycle of a cycle based statemachine
- # __TimerService__ (Boolean, optional): Enables/disables the generation of a timer service implementation using __java.util.Timer__
- ==<!-- # __GenericInterfaceSupport__ (Boolean, optional): Enables/disables the generation of generic interfaces -->==
- ==<!-- # __StatemachineFactorySupport__ (Boolean, optional): Enables/disables the generation of a factory class -->==
- Example configuration:
- bc..
- feature GeneralFeatures {
- InterfaceObserverSupport = true
- RuntimeService = true
- TimerService = true
- }
- p. ==<!-- End sgen_feature_generalfeatures -->==
- h2. C Generator Features
- ==<!-- Start sgen_feature_ccodefeature -->==
- h4. CCodeFeature
- The *CCodeFeature* feature allows to configure c code specific generator properties. It is an *optional* feature and consists of the following parameters:
- # __InterfaceEventListener__ (Boolean, mandatory): generates listener interface for notification of outgoing events.
- # __Singleton__ (Boolean, mandatory): generates a statically allocated singleton variant of the state machine that does not allow multiple instances.
- # __DebugType__ (String, optional): don't use this property - it will be removed
- Example configuration:
- bc..
- feature CCodeFeature {
- InterfaceEventListerner = true
- Singleton = true
- }
- p. ==<!-- End sgen_feature_ccodefeature -->==
- h2. Create Custom Code Generators
- 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
-
- h3. Writing a custom code generator with Xtend2/Java
- 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.
- !images/xtendGenerator.png!
- 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.
- 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.
- 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].
- h3. Executing a custom Xtend2/Java code generator
- YAKINDU Statechart Tools provide a convenient way to execute your generator while you are developing it.
- 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.
- ==<!-- Start sgen_feature_generator -->==
- h4. Generator
- 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:
- # __generatorProject__ (String, required): The name of the generator project
- # __generatorClass__ (String, required): The full qualified class name of the code generator class.
- # __configurationModule__ (String, optional): The full qualified class name for a guice module to configure the code generator
- Example configuration:
- bc..
- feature Generator {
- generatorProject = "org.yakindu.sct.mygenerator"
- generatorClass = "org.yakindu.sct.MyGenerator"
- }
-
- p. ==<!-- End sgen_feature_generator -->==
- h3. Executing a custom Xpand code generator
- 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.
- ==<!-- Start sgen_feature_template -->==
- h4. Template
- 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:
- # __templateProject__ (String, required): The name of the generator project
- # __templatePath__ (String, required): The full qualified template path to the main template.
- Example configuration:
- bc..
- feature Template {
- templateProject = "ExampleProject"
- templatePath = "org::yakindu::sct::generator::xpand::Main::main"
- }
- p. ==<!-- End sgen_feature_template -->==
|