m2asseli wrote:
Thanks for the information. I gather I am having the problem because
I have two separate processes, and the pointer is not to a shared
memory location.
With regards to this shared memory, which you do not recommend…I
have used some shared memory variables between two processes, because
I assumed it would be quicker to shared the information in that manner
than to send a message with the data. I haven’t encountered any
problems to date, but you still recommend not using shared memory? I
am sharing approximately a dozen or so decimal values between the two
processes, would it be safer and just as quick to send a message with
the data?
Thanks again. Matthew.
Hello Matthew,
You can to use something like this:
Messge structure:
#define MY_MSG_TYPE ??? // Now I don’t know, where is correct space
for user message type, for experiment we can use value 0x200. Don’t use
this values: 0x000-0x0FF - SYSMGR, PROCMGR, MEMMGR, PATHMGR, CPUMGR,
RSRCDBMGR; 0x100-0x1FF - IOMSG; 0x700-??? - PHOTON; 0xA00-0xA80 - PCCARD;
struct _my_data_t
{
msg_t type;
size_t TextLen;
int data;
/* char Text[TextLen]; this line is only for information about
message format */
};
Similar construction you can to find in iomsg.h struct _io_write
For send message use:
io_t wiov[2];
my_data.type = MY_MSG_TYPE;
my_data.TextLen = strlen( Text ) + 1;
my_data.data = ???;
SETIOV( wiov + 0, &my_data, sizeof( struct _my_data_t ) );
SETIOV( wiov + 1, Text, my_data.TextLen );
MsgSendv( fd, wiov, 2, NULL, 0 );
For read message
int NonPtMsgHandler( void *data, int rcvid, void *msg, size_t msglen)
{
struct _my_data_t mydata;
msg_t *msg_type;
int number=rcvd_msg->data;
iov_t riov[1];
char *text;
// Check if message is my
msg_type = (msg_t *) msg;
if( (*msg_type) != MY_MSG_TYPE )
return Pt_CONTINUE;
// check if you have whoe message in buffer or you can to use
PtResizeEventMsg for allocate enough space when application is start.
Then you can use struct _my_data_t *my_data_ptr = (struct my_data_t *) msg;
if( msglen < sizeof( struct _my_data_t ) )
{
// read message again
SETIOV( riov + 0, &my_data, sizeof( struct _my_data_t ) );
MsgRead( rcvid, riov, 1, 0 );
}
else
{
// make only copy form buffer
my_data = * ((struct _my_data_t *) msg);
}
// Allocate text buffer
text = ( char * ) malloc (rcvd_msg->TextLen );
// Read text
SETIOV( riov + 0, text, rcvd_msg->TextLen );
MsgReadv( rcvid, riov, 1, sizeof( struct _my_data_t) );
printf( “I have message: %s”, text );
free( text );
return Pt_HALT;
}
I hope it will help to you
Marian.