Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Papyrus for Real Time » Protocol with pointers and arrays(Sending pointers and arrays through ports)
Protocol with pointers and arrays [message #1769954] Mon, 07 August 2017 04:13 Go to next message
Christopher Won is currently offline Christopher WonFriend
Messages: 11
Registered: July 2017
Junior Member
I am trying to change the attribute of an object created from a user-made class in a different capsule then where it was created and was finding that I couldn't, I believe the problem might be because I am passing the object by value to the other capsule rather than passing it by pointer however I don't know how to configure a protocol to let me send a pointer

My model is a bit complicated and messy so I have modified a simpler model to demonstrate how i can't change the attribute

In the model attached the attribute label is set in the capsule that it was created but when i try to change it to something else after passing it to another capsule it doesn't change

Thanks in advance
Re: Protocol with pointers and arrays [message #1770054 is a reply to message #1769954] Mon, 07 August 2017 19:25 Go to previous messageGo to next message
Ernesto Posse is currently offline Ernesto PosseFriend
Messages: 438
Registered: March 2011
Senior Member
You've ran into a new bug in the code generator, but there is a workaround.

The bug is this: whenever you send data from one capsule to another, the runtime must know how to serialize the data in order to send it. It cannot simply send a pointer, because the receiver could be in a separate memory space. Well, the current runtime doesn't yet support multi-core or multi-processes on separate memory spaces, but it is designed with that in mind, so the code generator produces code that serializes the data payload of messages. When the data in question is a user-defined type, this serialization is done by looking at a data structure that describes the fields of the data class. This is encoded by the code generator in what we call "field descriptors", which are generated for the passive class. You can find the "fields" variable in the generated code. Now, the problem in you case is that that you are trying to sent an instance of WidgetVector, which has an attribute whose type (std::vector<Widget>) is specified with the AttributeProperties stereotype's "type" string, and unfortunately, the code generator does not know how to generate field descriptors for such attributes. It only generates descriptors for types it knows, i.e. primitive types, or types defined by the user in the model, i.e. specified directly in the type of the attribute, rather than in the AttributeProperties stereotype. So the generated code doesn't have the required field descriptor.

Now, before I explain the workaround, I want to say that you cannot send an array or pointer directly as the data of a message. It would be a very bad idea. First, doing so would also make the assumption that the sender and the receiver are running both in the same memory space, which, as I mentioned above, is an assumption that will likely change in the future. Conceptually you should always think of capsules as being "isolated", i.e. not sharing memory. Second, even if we allowed you to pass pointers directly, you could easily get into trouble because if the capsules are running in separate threads, you now have to deal with potential race-conditions and other concurrent safety issues, so you would be forced to use things like mutexes to avoid those problems.

Having said that, there is a way where you can share data and have a result which is analogous to passing a pointer: create a "wrapper" data class that acts like a pointer. See the attached, updated model. In the new model, I've created a "WidgetVectorWrapper" which has a single attribute that is the WidgetVector. So instead of sending the WidgetVector, I create a WidgetVectorWrapper whose attribute is set to the WidgetVector and I send the WidgetVectorWrapper. Now the data is correctly serialized on send, and extracted on the receiving end.



  • Attachment: UserTypes.zip
    (Size: 12.67KB, Downloaded 127 times)

[Updated on: Mon, 07 August 2017 19:27]

Report message to a moderator

Re: Protocol with pointers and arrays [message #1770137 is a reply to message #1770054] Tue, 08 August 2017 15:06 Go to previous messageGo to next message
Christopher Won is currently offline Christopher WonFriend
Messages: 11
Registered: July 2017
Junior Member
So I have made the wrapper class and have implemented it in the same way that UserTypes has and the attribute in UserTypes is changing however it is not working in my model. I have tried to make sure that everything in both cases are the same however I noticed that the model used in UserTypes has dependencies and I was wondering what these are and what are they used for and if my attributed are not changing because my model does not have these dependencies

Thanks again
Re: Protocol with pointers and arrays [message #1770144 is a reply to message #1770137] Tue, 08 August 2017 15:18 Go to previous message
Ernesto Posse is currently offline Ernesto PosseFriend
Messages: 438
Registered: March 2011
Senior Member
The dependency relationships define the elements that a class/capsule depends on. In the generated C++ they result in either #include directives or forward references. Some dependencies are computed automatically, so it's not always necessary to add them, but in general it is better to have explicit dependencies in the model.

Nevertheless, it sounds like you got your generated code to compile, so that suggests the issue is not with the dependencies.

If it is not working for your model, then there is something in you model which is not like the example. My suggestion is to use the extraction operator (<<) as defined in the example to print out on std::cout the objects in question so you can debug it.
Previous Topic:User Input
Next Topic:Constructing a state machine as part of the code generator
Goto Forum:
  


Current Time: Tue Apr 23 15:06:19 GMT 2024

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

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

Back to the top