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.

The resource manager library<br />

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

dispatch_handler (ctp);<br />

}<br />

}<br />

There you have it! A complete /dev/null resource manager implemented in a few<br />

function calls!<br />

If you were to write this from scratch, and have it support all the functionality that this<br />

one does (e.g., stat() works, chown() and chmod() work, and so on), you’d be looking<br />

at many hundreds if not thousands of lines of C code.<br />

The library really does what we just talked about<br />

By way of introduction to the library, let’s see (briefly) what the calls do in the<br />

/dev/null resource manager.<br />

dispatch_create()<br />

iofunc_attr_init()<br />

iofunc_func_init()<br />

Creates a dispatch structure; this will be used for blocking on<br />

the message reception.<br />

Initializes the attributes structure used by the device. We’ll<br />

discuss attributes structures in more depth later, but for now,<br />

the short story is that there’s one of these per device name, and<br />

they contain information about a particular device.<br />

Initializes the two data structures cfuncs and ifuncs, which<br />

contain pointers to the connect and I/O functions, respectively.<br />

You might argue that this call has the most “magic” in it, as this<br />

is where the actual “worker” routines for handling all the<br />

messages got bound into a data structure. We didn’t actually<br />

see any code to handle the connect message, or the I/O<br />

messages resulting from a client read() or stat() function etc.<br />

That’s because the library is supplying default POSIX versions<br />

of those functions for us, and it’s the iofunc_func_init()<br />

function that binds those same default handler functions into<br />

the two supplied tables.<br />

resmgr_attach()<br />

Creates the channel that the resource manager will use for<br />

receiving messages, and talks to the process manager to tell it<br />

that we’re going to be responsible for “/dev/null.” While<br />

there are a lot of parameters, we’ll see them all in painful detail<br />

later. For now, it’s important to note that this is where the<br />

dispatch handle (dpp), pathname (the string /dev/null), and<br />

the connect (cfuncs) and I/O (ifuncs) message handlers all get<br />

bound together.<br />

dispatch_context_alloc()<br />

Allocates a dispatch internal context block. It contains<br />

information relevant to the message being processed.<br />

dispatch_block()<br />

This is the dispatch layer’s blocking call; it’s where we wait for<br />

a message to arrive from a client.<br />

202 Chapter 5 • Resource Managers April 30, 2009

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

Saved successfully!

Ooh no, something went wrong!