Implementing Guards [message #1785640] |
Tue, 17 April 2018 13:31  |
Eclipse User |
|
|
|
Hello,
I am using Papyrus-RT 1.0, and can't for the life of me figure out how to correctly implement guards.
I have a transition into a choice point, and multiple transitions out, but the only mention I see for guards is on the Code Snippet window for the transition, but cannot seem to make this work.
Any clarification would be great.
Thanks!
|
|
|
Re: Implementing Guards [message #1785717 is a reply to message #1785640] |
Wed, 18 April 2018 13:43  |
Eclipse User |
|
|
|
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 319 times)
[Updated on: Wed, 18 April 2018 13:47] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.02578 seconds