26.02.2014 Views

Getting Started with QNX Neutrino - QNX Software Systems

Getting Started with QNX Neutrino - QNX Software Systems

Getting Started with QNX Neutrino - QNX Software Systems

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

© 2009, <strong>QNX</strong> <strong>Software</strong> <strong>Systems</strong> GmbH & Co. KG. Porting philosophy<br />

typedef struct<br />

{<br />

int data_rate;<br />

int more_stuff;<br />

} my_input_xyz_t;<br />

typedef struct<br />

{<br />

int old_data_rate;<br />

int new_data_rate;<br />

int more_stuff;<br />

} my_output_xyz_t;<br />

typedef union<br />

{<br />

my_input_xyz_t i;<br />

my_output_xyz_t o;<br />

} my_message_xyz_t;<br />

Here, we’ve defined a union of an input and output message, and called it<br />

my_message_xyz_t. The naming convention is that this is the message that relates to<br />

the “xyz” service, whatever that may be. The input message is of type<br />

my_input_xyz_t, and the output message is of type my_output_xyz_t. Note that<br />

“input” and “output” are from the point of view of the resource manager — “input” is<br />

data going into the resource manager, and “output” is data coming from the resource<br />

manager (back to the client).<br />

We need to make some form of API call for the client to use — we could just force the<br />

client to manually fill in the data structures my_input_xyz_t and<br />

my_output_xyz_t, but I don’t recommend doing that. The reason is that the API is<br />

supposed to “decouple” the implementation of the message being transferred from the<br />

functionality. Let’s assume this is the API for the client:<br />

int<br />

adjust_xyz (int *data_rate,<br />

int *odata_rate,<br />

int *more_stuff );<br />

Now we have a well-documented function, adjust_xyz(), that performs something<br />

useful from the client’s point of view. Note that we’ve used pointers to integers for the<br />

data transfer — this was simply an example of implementation. Here’s the source code<br />

for the adjust_xyz() function:<br />

int<br />

adjust_xyz (int *dr, int *odr, int *ms)<br />

{<br />

my_message_xyz_t msg;<br />

int<br />

sts;<br />

msg.i.data_rate = *dr;<br />

msg.i.more_stuff = *ms;<br />

sts = io_msg (global_fd, COMMAND_XYZ, &msg,<br />

sizeof (msg.i),<br />

sizeof (msg.o));<br />

if (sts == EOK) {<br />

*odr = msg.o.old_data_rate;<br />

*ms = msg.o.more_stuff;<br />

}<br />

April 30, 2009 Appendix: A • <strong>QNX</strong> 4 to <strong>Neutrino</strong> 297

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!