return value from devctl()

Hi,
Another resource manager newbie question here…
Can someone please post a small code snippet that shows how to get a
resource manager’s io_devctl function to return a value?

I would like to use it as follows:
Code:


int status = devctl( fd, cmd, data, …);


I cannot seem to get my devctl() calls to return anything; i.e. a
status value indicating success/failure of the operation as performed
by the resource manager. The problem is that this statement does not
return the variable to the calling application.
/*
If you wanted to pass something different to the return
field of the devctl() you could do it through this member.
*/
msg->o.ret_val = status;


My resource manager code uses the following framework:
Code:

int io_devctl(resmgr_context_t *ctp, io_devctl_t *msg, RESMGR_OCB_T
*ocb) {
int nbytes, status, previous;
union {
data_t data;
int data32;
// … other devctl types you can receive
} *rx_data;

if ((status = iofunc_devctl_default(ctp, msg, ocb)) !=
_RESMGR_DEFAULT) {
return(status);
}
status = nbytes = 0;

rx_data = _DEVCTL_DATA(msg->i);


switch (msg->i.dcmd) {
case MY_DEVCTL_SETVAL:
global_integer = rx_data->data32;
nbytes = 0;
break;

case MY_DEVCTL_GETVAL:
rx_data->data32 = global_integer;
nbytes = sizeof(rx_data->data32);
break;

case MY_DEVCTL_SETGET:
previous = global_integer;
global_integer = rx_data->data.tx;
rx_data->data.rx = previous; //Overwrites tx data
nbytes = sizeof(rx_data->data.rx);
break;

default:
return(ENOSYS);
}

memset(&msg->o, 0, sizeof(msg->o));

/*
If you wanted to pass something different to the return
field of the devctl() you could do it through this member.
*/
msg->o.ret_val = status;


msg->o.nbytes = nbytes;
return(_RESMGR_PTR(ctp, &msg->o, sizeof(msg->o) +
nbytes));
}


Thanks!
EWatz

The ‘ret_val’ is returned in the ‘dev_info_ptr’ field

int devctl( int filedes,
int dcmd,
void * dev_data_ptr,
size_t n_bytes,
int * dev_info_ptr ); <---- this field


aryckw wrote:

Hi,
Another resource manager newbie question here…
Can someone please post a small code snippet that shows how to get a
resource manager’s io_devctl function to return a value?

I would like to use it as follows:
Code:


int status = devctl( fd, cmd, data, …);


I cannot seem to get my devctl() calls to return anything; i.e. a
status value indicating success/failure of the operation as performed
by the resource manager. The problem is that this statement does not
return the variable to the calling application.
/*
If you wanted to pass something different to the return
field of the devctl() you could do it through this member.
*/
msg->o.ret_val = status;


My resource manager code uses the following framework:
Code:

int io_devctl(resmgr_context_t *ctp, io_devctl_t *msg, RESMGR_OCB_T
*ocb) {
int nbytes, status, previous;
union {
data_t data;
int data32;
// … other devctl types you can receive
} *rx_data;

if ((status = iofunc_devctl_default(ctp, msg, ocb)) !=
_RESMGR_DEFAULT) {
return(status);
}
status = nbytes = 0;

rx_data = _DEVCTL_DATA(msg->i);


switch (msg->i.dcmd) {
case MY_DEVCTL_SETVAL:
global_integer = rx_data->data32;
nbytes = 0;
break;

case MY_DEVCTL_GETVAL:
rx_data->data32 = global_integer;
nbytes = sizeof(rx_data->data32);
break;

case MY_DEVCTL_SETGET:
previous = global_integer;
global_integer = rx_data->data.tx;
rx_data->data.rx = previous; //Overwrites tx data
nbytes = sizeof(rx_data->data.rx);
break;

default:
return(ENOSYS);
}

memset(&msg->o, 0, sizeof(msg->o));

/*
If you wanted to pass something different to the return
field of the devctl() you could do it through this member.
*/
msg->o.ret_val = status;


msg->o.nbytes = nbytes;
return(_RESMGR_PTR(ctp, &msg->o, sizeof(msg->o) +
nbytes));
}


Thanks!
EWatz

Warren Deitch <warren.deitch@transtoll.com> wrote:

The ‘ret_val’ is returned in the ‘dev_info_ptr’ field

int devctl( int filedes,
int dcmd,
void * dev_data_ptr,
size_t n_bytes,
int * dev_info_ptr ); <---- this field

Yup, and the return value of the devctl() function itself is either
EOK for success or an errno value on failure. (Check the docs, returns
section for devctl() to see that.)

-David

David Gibbs
QNX Training Services
dagibbs@qnx.com

Thanks, I was not using the dev_info_ptr field!! Tried that and it
works fine…