|
Re: Implementing Guards [message #1785717 is a reply to message #1785640] |
Wed, 18 April 2018 17:43 |
Ernesto Posse Messages: 438 Registered: March 2011 |
Senior Member |
|
|
Hi Eric.
There are two kinds of guards: transition guards and trigger guards. I assume you are looking for transition guards.
There are two approaches: use guards directly on a transition whose source is a state, and which has at least one trigger, or use guards on transitions that leave a choice point (and the transition leading to the choice point has a trigger). Both are equivalent (*). In both cases you write the guard in the "Guard" tab of the code-snippet view as you found, but keep in mind that the guard is a statement, not a condition. Hence, you should write, e.g.
rather than
See the attached example. There is a capsule with two parts. Each part is a capsule that shows the two styles.
A key thing is that the variables that you use in your guard must correspond to the parameters of the protocol message. In the attached example, the protocol message is "m" and has a unique int parameter called "data", so the guard expression uses 'data'.
You can also attach guards to triggers: select a transition, and in the Properties view, select the relevant trigger (assuming you already added a trigger) and click in the "Guard" field. This will open a "Trigger Guard" code-snippet view. In this case the transition will only be enabled when the message arrives and the trigger guard is true.
(*) Actually there is a difference: if you have a transition, say t1 that leads to a choice points that have guards, and the transition is triggered, then it will execute its action before evaluating the guards of the transitions leaving the choice point. In the other case, if the transitions with guards leave a state rather than a choice point, then their actions are executed after, and only if the message is received, and the guard in question is true.
-
Attachment: Guards.zip
(Size: 10.22KB, Downloaded 287 times)
[Updated on: Wed, 18 April 2018 17:47] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03927 seconds