problem with message_attach in resource manager

Hello,

I write a resource manager which manages several devices and I handle
private messages.
I use ctp->id to know with which device communicates the client.
When the client does an open() on the first device, the id is 0. But when
the client
sends a private message with the same device, the id is -1 ???


Here is the code :

int main(int argc, char **argv)
{

if(message_attach(dpp, NULL, FIRST_PRIV_MESS, LAST_PRIV_MESS,
&message_handler, NULL) == -1) {
return EXIT_FAILURE;
}

if(pulse_attach(dpp, 0, 3, &pulse_handler, NULL) == -1) {
perror(“pulse_attach”);
return EXIT_FAILURE;
}


/* start the resource manager message loop */
while(1) {
if((new_ctp = dispatch_block(ctp)) == NULL) {
return EXIT_FAILURE;
}
ctp=new_ctp;
dispatch_handler(ctp);
}

return 0;
}


int io_open(resmgr_context_t *ctp, io_open_t *msg, IOFUNC_ATTR_T *device,
void *extra)
{
int sts;

printf(“IO_OPEN\n”);
sts = iofunc_open_default(ctp, msg, &device->attr, extra);
printf(“ctp->id:%d ctp->rcvid:%d ctp->info.coid:%d\n”, ctp->id,
ctp->rcvid, ctp->info.coid);
return sts;
}


Here the function printf() displays:
ctp->id:0 ctp->rcvid:4 ctp->info.coid:3


int message_handler(message_context_t *ctp, int code, unsigned flags, void
*handle)
{

printf(“ctp->id:%d ctp->rcvid:%d ctp->info.coid:%d\n”, ctp->id,
ctp->rcvid, ctp->info.coid);


}


Here the function printf() displays:
ctp->id:-1 ctp->rcvid:4 ctp->info.coid:3


I don’t know why ‘id’ is bad.

My problem is to know with which device communicates the client.
If I can’t use ctp->id, is there a simple solution to know the device when
the client uses a private message ?

Thank you for your answer.

-Phil

Bretin <philippebretin@hotmail.com> wrote:

Hello,

I write a resource manager which manages several devices and I handle
private messages.
I use ctp->id to know with which device communicates the client.
When the client does an open() on the first device, the id is 0. But when
the client
sends a private message with the same device, the id is -1 ???

If you need to know what device is being dealt with, you might try
using the IO_MSG type, where you generate messages with a type of
IO_MSG and io_funcs.msg = my_msg_handler to catch them on the incoming
side, then the library will have done the lookup, and you’ll be supplied
with a pointer to an OCB in your callback.

Here is the code :

int message_handler(message_context_t *ctp, int code, unsigned flags, void
*handle)
{

printf(“ctp->id:%d ctp->rcvid:%d ctp->info.coid:%d\n”, ctp->id,
ctp->rcvid, ctp->info.coid);


}



Here the function printf() displays:
ctp->id:-1 ctp->rcvid:4 ctp->info.coid:3

I don’t know why ‘id’ is bad.

ctp->id may not be filled in in the “pass-through” case for a
message_attach(). The library will, I think, try to do minimal
processing in this case, as it doesn’t have to look up an OCB
for you.

You can uniquely identify your client from the info structure,
you need:
ctp->info.nd;
ctp->info.pid;
ctp->info.coid;

This gives you the node descriptor (which you can ignore if all
clients are local)and pid to uniquely identify the client, then
the coid (i.e. fd) on the client side. Together they identify
your device (barring issues of dup()s…). Because of the messiness
of dup()s, I’d suggest going with the IO_MSG stuff I suggested up
top.

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

“David Gibbs” <dagibbs@qnx.com> a écrit dans le message de news:
adg2ul$9pq$1@nntp.qnx.com

Bretin <> philippebretin@hotmail.com> > wrote:
Hello,

I write a resource manager which manages several devices and I handle
private messages.
I use ctp->id to know with which device communicates the client.
When the client does an open() on the first device, the id is 0. But
when
the client
sends a private message with the same device, the id is -1 ???

If you need to know what device is being dealt with, you might try
using the IO_MSG type, where you generate messages with a type of
IO_MSG and io_funcs.msg = my_msg_handler to catch them on the incoming
side, then the library will have done the lookup, and you’ll be supplied
with a pointer to an OCB in your callback.

Here is the code :

int message_handler(message_context_t *ctp, int code, unsigned flags,
void
*handle)
{

printf(“ctp->id:%d ctp->rcvid:%d ctp->info.coid:%d\n”, ctp->id,
ctp->rcvid, ctp->info.coid);


}


Here the function printf() displays:
ctp->id:-1 ctp->rcvid:4 ctp->info.coid:3

I don’t know why ‘id’ is bad.

ctp->id may not be filled in in the “pass-through” case for a
message_attach(). The library will, I think, try to do minimal
processing in this case, as it doesn’t have to look up an OCB
for you.

You can uniquely identify your client from the info structure,
you need:
ctp->info.nd;
ctp->info.pid;
ctp->info.coid;

This gives you the node descriptor (which you can ignore if all
clients are local)and pid to uniquely identify the client, then
the coid (i.e. fd) on the client side. Together they identify
your device (barring issues of dup()s…). Because of the messiness
of dup()s, I’d suggest going with the IO_MSG stuff I suggested up
top.

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

Thanks for your advices. But when I use io_funcs.msg, I can’t intercept
client messages.
In my client program, I use MsgSend and I have an error in return :
“Function not implemented”.
What is the function to use in the client to send messages if I have
io_funcs.msg in the resource manager ?

Thank you.

-Phil

Bretin <philippebretin@hotmail.com> wrote:

Thanks for your advices. But when I use io_funcs.msg, I can’t intercept
client messages.
In my client program, I use MsgSend and I have an error in return :
“Function not implemented”.
What is the function to use in the client to send messages if I have
io_funcs.msg in the resource manager ?

The message sent has to be of type IO_MSG, that is, the first 16-bits must
look like that.

e.g.

typedef struct {
struct _io_msg hdr;
/* my payload here */
} my_msg;

my_msg msg;

msg.hdr.type = _IO_MSG; /* type /
msg.hdr.combine_len = sizeof(msg.hdr); /
length of header /
msg.hdr.mgrid = _IOMGR_PRIVATE_BASE; /
must be filled in, this value plus /
msg.hdr.subtype = IO_MSG_SUBTYPE_TEXT; /
can be used for your msg type */

The hdr.type = _IO_MSG gets the incoming message to your io_funcs.msg
callback.

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.