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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Writing a resource manager<br />

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

id<br />

msg_max_size<br />

status<br />

offset<br />

size<br />

iov<br />

The identifier for the mountpoint this message was meant for.<br />

When you did the resmgr_attach(), it returned a small integer ID.<br />

This ID is the value of the id member. Note that you’d most likely<br />

never use this parameter yourself, but would instead rely on the<br />

attributes structure passed to you in your io_open() handler.<br />

This contains the msg_max_size that was passed in as the<br />

msg_max_size member of resmgr_attr_t (given to the<br />

resmgr_attach() function) so that the size, offset, and<br />

msg_max_size are all contained in one handy structure/location.<br />

This is where your handler function places the result of the<br />

operation. Note that you should always use the macro<br />

_RESMGR_STATUS to write this field. For example, if you’re<br />

handling the connect message from an open(), and you’re a<br />

read-only resource manager but the client wanted to open you for<br />

write, you’d return an EROFS errno via (typically)<br />

_RESMGR_STATUS (ctp, EROFS).<br />

The current number of bytes into the client’s message buffer. Only<br />

relevant to the base layer library when used <strong>with</strong><br />

resmgr_msgreadv() <strong>with</strong> combine messages (see below).<br />

This tells you how many bytes are valid in the message area that<br />

gets passed to your handler function. This number is important<br />

because it indicates if more data needs to be read from the client<br />

(for example, if not all of the client’s data was read by the<br />

resource manager base library), or if storage needs to be allocated<br />

for a reply to the client (for example, to reply to the client’s read()<br />

request).<br />

The I/O Vector table where you can write your return values, if<br />

returning data. For example, when a client calls read() and your<br />

read-handling code is invoked, you may need to return data. This<br />

data can be set up in the iov array, and your read-handling code<br />

can then return something like _RESMGR_NPARTS (2) to<br />

indicate (in this example) that both iov [0] and iov [1]<br />

contain data to return to the client. Note that the iov member is<br />

defined as only having one element. However, you’ll also notice<br />

that it’s conveniently at the end of the structure. The actual<br />

number of elements in the iov array is defined by you when you<br />

set the nparts_max member of the control structure above (in the<br />

section “resmgr_attr_t control structure,” above).<br />

Resource manager structure<br />

Now that we’ve seen the data structures, we can discuss interactions between the parts<br />

that you’d supply to actually make your resource manager do something.<br />

210 Chapter 5 • Resource Managers April 30, 2009

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

Saved successfully!

Ooh no, something went wrong!