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

resmgr_io_funcs_t I/O table<br />

The second parameter is always a pointer to the message. Because the functions in the<br />

table are there to handle different types of messages, the prototypes match the kind of<br />

message that each function will handle.<br />

The third parameter is a RESMGR_HANDLE_T structure called a handle — it’s used to<br />

identify the device that this message was targeted at. We’ll see this later as well, when<br />

we look at the attributes structure.<br />

Finally, the last parameter is either “reserved” or an “extra” parameter for functions<br />

that need some extra data. We’ll show the extra parameter as appropriate during our<br />

discussions of the handler functions.<br />

The I/O table is very similar in spirit to the connect functions table just shown above.<br />

Here it is, from :<br />

typedef struct _resmgr_io_funcs {<br />

unsigned nfuncs;<br />

int (*read) (ctp, io_read_t *msg, ocb);<br />

int (*write) (ctp, io_write_t *msg, ocb);<br />

int (*close_ocb) (ctp, void *reserved, ocb);<br />

int (*stat) (ctp, io_stat_t *msg, ocb);<br />

int (*notify) (ctp, io_notify_t *msg, ocb);<br />

int (*devctl) (ctp, io_devctl_t *msg, ocb);<br />

int (*unblock) (ctp, io_pulse_t *msg, ocb);<br />

int (*pathconf) (ctp, io_pathconf_t *msg, ocb);<br />

int (*lseek) (ctp, io_lseek_t *msg, ocb);<br />

int (*chmod) (ctp, io_chmod_t *msg, ocb);<br />

int (*chown) (ctp, io_chown_t *msg, ocb);<br />

int (*utime) (ctp, io_utime_t *msg, ocb);<br />

int (*openfd) (ctp, io_openfd_t *msg, ocb);<br />

int (*fdinfo) (ctp, io_fdinfo_t *msg, ocb);<br />

int (*lock) (ctp, io_lock_t *msg, ocb);<br />

int (*space) (ctp, io_space_t *msg, ocb);<br />

int (*shutdown) (ctp, io_shutdown_t *msg, ocb);<br />

int (*mmap) (ctp, io_mmap_t *msg, ocb);<br />

int (*msg) (ctp, io_msg_t *msg, ocb);<br />

int (*dup) (ctp, io_dup_t *msg, ocb);<br />

int (*close_dup) (ctp, io_close_t *msg, ocb);<br />

int (*lock_ocb) (ctp, void *reserved, ocb);<br />

int (*unlock_ocb) (ctp, void *reserved, ocb);<br />

int (*sync) (ctp, io_sync_t *msg, ocb);<br />

} resmgr_io_funcs_t;<br />

For this structure as well, I’ve shortened the prototype by removing the type of the ctp<br />

member (resmgr_context_t *) and the last member (ocb, of type RESMGR_OCB_T<br />

*). For example, the full prototype for read is really:<br />

int (*read) (resmgr_context_t *ctp,<br />

io_read_t *msg,<br />

RESMGR_OCB_T *ocb);<br />

The very first member of the structure (nfuncs) indicates how big the structure is (how<br />

many members it contains). The proper manifest constant for initialization is<br />

_RESMGR_IO_NFUNCS.<br />

Note that the parameter list in the I/O table is also very regular. The first parameter is<br />

the ctp, and the second parameter is the msg, just as they were in the connect table<br />

handlers.<br />

208 Chapter 5 • Resource Managers April 30, 2009

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

Saved successfully!

Ooh no, something went wrong!