It is currently Thu Feb 09, 2012 12:11 am

All times are UTC



Welcome
Welcome to RHAPSODY4YOU

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, respond to polls, upload and download content, and access many other special features. Registration is fast, simple, and absolutely free, so please, register to join our community today.





 Page 1 of 1 [ 4 posts ] 
Author Message
 Post subject: passing an object in an event.
PostPosted: Wed Jun 02, 2010 1:11 pm 

Joined: Thu May 21, 2009 11:25 pm
Posts: 12
I have the following. PacketHandlerClass (Active) <-> SerialPortClass (Active)<-> Serial Bus (hardware).

The SerialPortClass sends and receives messages from the serial port. Once it receives a message I want it to send it to the PacketHandlerClass. The messages are 8 bytes long and come every 100 ms. I made a union/struct to represent the message. So then I pass the struct object to the PacketHandlerClass over an Event. However, it appears that the object is getting overwritten. So I believe the problem is that the message object is on the stack and the event only copies the address of the object and not the values. Then when a new message arrives, it overwrites the data on the message.

Does that make sense? I am going to try to create the message object on the heap now, but I just want to make sure there aren't any other pitfalls.


Offline
 Profile  
 
 Post subject: Re: passing an object in an event.
PostPosted: Wed Jun 02, 2010 1:28 pm 

Joined: Sat Oct 18, 2008 9:32 pm
Posts: 10
Hi,
In this case, simply create the event data on the heap and pass a pointer to the receiver who then owns the allocated event data (and needs to delete it). :D

BR//
LGJ


Offline
 Profile  
 
 Post subject: Re: passing an object in an event.
PostPosted: Wed Jun 02, 2010 2:01 pm 

Joined: Thu May 21, 2009 11:25 pm
Posts: 12
xlarjo wrote:
Hi,
In this case, simply create the event data on the heap and pass a pointer to the receiver who then owns the allocated event data (and needs to delete it). :D

BR//
LGJ



How do I make an event take a pointer argument? I can't chose In/Inout/Out. Do I have to uncheck use existing type? That makes me feel uncomfortable about whether I am doing the right thing.


Offline
 Profile  
 
 Post subject: Re: passing an object in an event.
PostPosted: Thu Jun 03, 2010 5:44 am 

Joined: Sat Oct 18, 2008 9:32 pm
Posts: 10
Hi,
Simply decheck the "Use existing type" box in the argument dialog of the event and write the type of the argument (with a * or a &) explicit instead of using the "in"/"out" options. This will require that you add a "usage" dependency to the event data type to the context of the event (i.e the package that contains the event).

BR//
LGJ


Offline
 Profile  
 
Display posts from previous:  Sort by  
 Page 1 of 1 [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:

cron

suspicion-preferred