Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Papyrus for Real Time » multiplicity at objects?
multiplicity at objects? [message #1795480] Mon, 24 September 2018 06:48 Go to next message
Twan Dieltjes is currently offline Twan DieltjesFriend
Messages: 22
Registered: September 2018
Junior Member
If I set multiplicty for an object at 2, is there a way in a code snippit to distinquish the objects? For example by an special ID?

Re: multiplicity at objects? [message #1795520 is a reply to message #1795480] Mon, 24 September 2018 16:12 Go to previous messageGo to next message
Ernesto Posse is currently offline Ernesto PosseFriend
Messages: 438
Registered: March 2011
Senior Member
When you set the multiplicity of an element such as a port or part, the generated code will be an array whose name is the name of the element, so you can use normal indices to access individual elements. For example, say you have a protocol P with some messages m1 and m2 and you have a capsule A with a port p (of type P) with multiplicity 2. Then, in actions of A's state machine, or A's operations, you can write, e.g.

p[0].m1().send();
p[1].m2().send();


The same notation can be used for parts.

Now, in a state machine, a transition trigger cannot specify directly a specific index for a port, but there is an API method from the UMLRTMessage class that allows you to determine which has the index of the port that received the message. Every transition action (and state action) has an implicit parameter called "msg" which contains a pointer to the message that was received and triggered the transition (more precisely its type is const UMLRTMessage * msg). From this parameter we can obtain the relevant index in action code by calling on "msg" the methods "sapIndex" or "sapIndex0". They return the same thing, the index of the port where the message was received. The difference is that "sapIndex" counts from 1 and "sapIndex0" counts from 0. So in the action of a transition whose trigger is a port with multiplicity > 1, you can write, e.g.

int i = msg->sapIndex0();

Re: multiplicity at objects? [message #1795555 is a reply to message #1795520] Tue, 25 September 2018 09:01 Go to previous message
Twan Dieltjes is currently offline Twan DieltjesFriend
Messages: 22
Registered: September 2018
Junior Member
Ok thanks. I will check this out!
Previous Topic:Define an attribute typed with a class without the default constructor
Next Topic:Can a state machine be a child of another state state machine
Goto Forum:
  


Current Time: Wed Apr 24 14:39:30 GMT 2024

Powered by FUDForum. Page generated in 0.03306 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top