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 />

typedef struct _resmgr_attr {<br />

unsigned flags;<br />

unsigned nparts_max;<br />

unsigned msg_max_size;<br />

int (*other_func) (resmgr_context_t *ctp, void *msg);<br />

} resmgr_attr_t;<br />

The other_func message handler<br />

In general, you should avoid using this member. This member, if non-NULL,<br />

represents a routine that will get called <strong>with</strong> the current message received by the<br />

resource manager library when the library doesn’t recognize the message. While you<br />

could use this to implement “private” or “custom” messages, this practice is<br />

discouraged (use either the _IO_DEVCTL or _IO_MSG handlers, see below). If you<br />

wish to handle pulses that come in, I recommend that you use the pulse_attach()<br />

function instead.<br />

You should leave this member <strong>with</strong> the value NULL.<br />

The data structure sizing parameters<br />

The flags parameter<br />

These two parameters are used to control various sizes of messaging areas.<br />

The nparts_max parameter controls the size of the dynamically allocated iov member<br />

in the resource manager library context block (of type resmgr_context_t, see<br />

below). You’d typically adjust this member if you were returning more than a one-part<br />

IOV from some of your handling functions. Note that it has no effect on the incoming<br />

messages — this is only used on outgoing messages.<br />

The msg_max_size parameter controls how much buffer space the resource manager<br />

library should set aside as a receive buffer for the message. The resource manager<br />

library will set this value to be at least as big as the header for the biggest message it<br />

will be receiving. This ensures that when your handler function gets called, it will be<br />

passed the entire header of the message. Note, however, that the data (if any) beyond<br />

the current header is not guaranteed to be present in the buffer, even if the<br />

msg_max_size parameter is “large enough.” An example of this is when messages are<br />

transferred over a network using Qnet. (For more details about the buffer sizes, see<br />

“The resmgr_context_t internal context block,” below.)<br />

This parameter gives additional information to the resource manager library. For our<br />

purposes, we’ll just pass a 0. You can read up about the other values in the <strong>Neutrino</strong><br />

Library Reference under the resmgr_attach() function.<br />

resmgr_connect_ funcs_t connect table<br />

When the resource manager library receives a message, it looks at the type of message<br />

and sees if it can do anything <strong>with</strong> it. In the base layer, there are two tables that affect<br />

this behavior. The resmgr_connect_funcs_t table, which contains a list of<br />

connect message handlers, and the resmgr_io_funcs_t table, which contains a<br />

similar list of I/O message handlers. We’ll see the I/O version below.<br />

206 Chapter 5 • Resource Managers April 30, 2009

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

Saved successfully!

Ooh no, something went wrong!