Prev Next

Event Macro: EVENT_PARAMETER

EVENT_PARAMETER is a function macro used to access attribute of a signal instance, in State's behavior, Transition's guard and effect. This macro will be expanded to executable code according to the simulation language.

Access Default Macro Definition

Ribbon | Develop | Source Code | Options | Edit Code Templates | Language | Stm Event Parameter

Usage Format

%EVENT_PARAMETER(SignalType, SignalAttributeName)%

For example: A signal "MySignal" has two attributes, "foo:int" and "bar:int", the following use cases are valid:

  • Transition's effect: %EVENT_PARAMETER(MySignal, foo)%
  • State's behavior: %EVENT_PARAMETER(MySignal, bar)%
  • Transition's guard: %EVENT_PARAMETER(MySignal, bar)% > 10
  • State's behavior: %EVENT_PARAMETER(MySignal, bar)%++
  • Trace the value to Simulation Window: %TRACE(EVENT_PARAMETER(MySignal, foo))%

Macro Expansion Example

For Signal "MySignal" with attribute "value", Examples of macro expansion for Transition with signal trigger:%EVENT_PARAMETER(MySignal, value)%

C

((MySignal*)signal)->value

C++

static_cast<MySignal*>(signal)->value

C#

((MySignal)signal).value

Java

((EventProxy.MySignal)signal).value

JavaScript

signal.value

Example

This example demonstrated how to use EVENT_MACRO in Transition's effect, guard and State's behavior.

While running the simulation,

(1) trigger REQUEST and specify number 1 in for attribute value.

Since the condition for the guard is false, the active state will remain as State1.

(2) trigger REQUEST and specify number 11 for the attribute value.

Since the condition for the guard is true, the active state will change from State1 to State2;

The Transition's effect is executed. Here we traced the runtime value for the signal's attribute to the simulation window..

State2's behavior is executed. Here we incremented the runtime value for the signal's attribute and traced it to the simulation window.

[32608107]      [Part1:TransactionServer] Transition Effect: Initial_4019__TO__State1_4420

[32608118]      [Part1:TransactionServer] Entry Behavior: StateMachine_State1

[32608124]      [Part1:TransactionServer] Do Behavior: StateMachine_State1

[32608877]      [Part1:TransactionServer] Completion: TransactionServer_StateMachine_State1

[32608907]      Waiting for Trigger

[32613165]      Command: broadcast REQUEST.RequestSignal(1)

[32613214]      [Part1:TransactionServer] Event Queued: REQUEST.RequestSignal(value:1)

[32613242]      [Part1:TransactionServer] Event Dispatched: REQUEST.RequestSignal(value:1)

[32613279]      Waiting for Trigger

[32619541]      Command: broadcast REQUEST.RequestSignal(11)

[32619546]      [Part1:TransactionServer] Event Queued: REQUEST.RequestSignal(value:11)

[32619551]      [Part1:TransactionServer] Event Dispatched: REQUEST.RequestSignal(value:11)

[32619557]      [Part1:TransactionServer] Exit Behavior: StateMachine_State1

[32619562]      [Part1:TransactionServer] Transition Effect: State1__TO__State2_4421

[32619567]      instance of RequestSignal . value

[32619571]      11

[32619576]      [Part1:TransactionServer] Entry Behavior: StateMachine_State2

[32619584]      State's entry behavior: Increment instance of RequestSignal . value by 1:

[32619590]      12

[32619594]      [Part1:TransactionServer] Do Behavior: StateMachine_State2

[32620168]      [Part1:TransactionServer] Completion: TransactionServer_StateMachine_State2

[32620211]      Waiting for Trigger

[32622266]      Command: broadcast END

[32622272]      [Part1:TransactionServer] Event Queued: END

[32622310]      [Part1:TransactionServer] Event Dispatched: END

[32622349]      [Part1:TransactionServer] Exit Behavior: StateMachine_State2

[32622359]      [Part1:TransactionServer] Transition Effect: State2__TO__Final_4023_4423

[32622896]      [Part1:TransactionServer] Completion: TransactionServer_VIRTUAL_SUBMACHINESTATE

Limitation and Workaround

Since the macro expansion involve type casting, it is user's responsibility to ensure the type casting is valid.

And here are workarounds for some common cases that the type casting will encounter issues in the model.

  • One Transition has multiple triggers of different signal types

For example, a Transition has triggerA(specified SignalA) and triggerB(specified SignalB); A macro %EVENT_PARAMETER(SignalA, attributeOfA)% will not work when this Transition is triggered by triggerB.

We suggest to create two Transitions, one with triggerA(specified SignalA), and the other with triggerB(SignalB).

  • One State is the target of multiple Transitions of different signal triggers

For example, both TransitionA and TransitionB are targeting to MyState, TransitionA is triggered by SignalA, and TransitionB is triggered by SignalB.

If EVENT_PARAMETER is used in state's behavior code, one macro will not be able to work for both cases.

We suggest to move the logic dealing with signal's attribute from State's behavior to Transition's effect.

  • Customize template and generated code

User can also change the default template to add Run Time Type Identification (RTTI)  before type casting. User can also modify the generated code after generation, which can also satisfy the simulation purpose after compilation.