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. The resource manager’s view<br />

The resource manager’s view<br />

Registering a pathname<br />

Let’s look at things from the resource manager’s perspective. Basically, the resource<br />

manager needs to tell the process manager that it’ll be responsible for a certain part of<br />

the pathname space (it needs to register itself). Then, the resource manager needs to<br />

receive messages from clients and handle them. Obviously, things aren’t quite that<br />

simple.<br />

Let’s take a quick overview look at the functions that the resource manager provides,<br />

and then we’ll look at the details.<br />

The resource manager needs to tell the process manager that one or more pathnames<br />

are now under its domain of authority — effectively, that this particular resource<br />

manager is prepared to handle client requests for those pathnames.<br />

The serial port resource manager might handle (let’s say) four serial ports. In this case,<br />

it would register four different pathnames <strong>with</strong> the process manager: /dev/ser1,<br />

/dev/ser2, /dev/ser3, and /dev/ser4. The impact of this is that there are now<br />

four distinct entries in the process manager’s pathname tree, one for each of the serial<br />

ports. Four entries isn’t too bad. But what if the serial port resource manager handled<br />

one of those fancy multiport cards, <strong>with</strong> 256 ports on it? Registering 256 individual<br />

pathnames (i.e., /dev/ser1 through /dev/ser256) would result in 256 different<br />

entries in the process manager’s pathname tree! The process manager isn’t optimized<br />

for searching this tree; it assumes that there will be a few entries in the tree, not<br />

hundreds.<br />

As a rule, you shouldn’t discretely register more than a few dozen pathnames at each<br />

level — this is because a linear search is performed. The 256 port registration is<br />

certainly beyond that. In that case, what the multiport serial resource manager should<br />

do is register a directory-style pathname, for example /dev/multiport. This<br />

occupies only one entry in the process manager’s pathname tree. When a client opens<br />

a serial port, let’s say port 57:<br />

fp = fopen ("/dev/multiport/57", "w");<br />

The process manager resolves this to the ND/PID/CHID/handle for the multiport serial<br />

resource manager; it’s up to that resource manager to decide if the rest of the pathname<br />

(in our case, the “57”) is valid. In this example, assuming that the variable path<br />

contains the rest of the pathname past the mountpoint, this means that the resource<br />

manager could do checking in a very simple manner:<br />

devnum = atoi (path);<br />

if ((devnum = 256)) {<br />

// bad device number specified<br />

} else {<br />

// good device number specified<br />

}<br />

This search would certainly be faster than anything the process manager could do,<br />

because the process manager must, by design, be much more general-purpose than our<br />

resource manager.<br />

April 30, 2009 Chapter 5 • Resource Managers 199

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

Saved successfully!

Ooh no, something went wrong!