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.

Porting philosophy<br />

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

qnx_name_attach()<br />

In this case, you have two choices. You can try to retain the global namespace idiom,<br />

or you can modify your client and server to act like a standard resource manager. If<br />

you wish to retain the global namespace, then you should look at the name_attach()<br />

and name_detach() functions for your server, and name_open() and name_close() for<br />

your clients.<br />

However, I’d recommend that you do the latter; it’s “the <strong>Neutrino</strong> way” to do<br />

everything <strong>with</strong> resource managers, rather than try to bolt a resource manager<br />

“kludge” onto the side of a global namespace server.<br />

The modification is actually reasonably simple. Chances are that the client side calls a<br />

function that returns either the process ID of the server or uses the “VC” (Virtual<br />

Circuit) approach to create a VC from the client’s node to a remote server’s node. In<br />

both cases, the process ID or the VC to the remote process ID was found based on<br />

calling qnx_name_locate().<br />

Here, the “magic cookie” that binds the client to the server is some form of process ID<br />

(we’re considering the VC to be a process ID, because VCs are taken from the same<br />

number space, and for all intents and purposes, they look just like process IDs).<br />

If you were to return a connection ID instead of a process ID, you’d have conquered<br />

the major difference. Since the <strong>QNX</strong> 4 client probably doesn’t examine the process ID<br />

in any way (what meaning would it have, anyway? — it’s just a number), you can<br />

probably trick the <strong>QNX</strong> 4 client into performing an open() on the “global name.”<br />

In this case, however, the global name would be the pathname that the resource<br />

manager attached as its “id.” For example, the following is typical <strong>QNX</strong> 4 client code,<br />

stolen from my caller ID (CLID) server library:<br />

/*<br />

* CLID_Attach (serverName)<br />

*<br />

* This routine is responsible for establishing a connection to<br />

* the CLID server.<br />

*<br />

* Returns the process ID or VC to the CLID server.<br />

*/<br />

// a place to store the name, for other library calls<br />

static char CLID_serverName [MAX_CLID_SERVER_NAME + 1];<br />

// a place to store the clid server id<br />

static int clid_pid = -1;<br />

int<br />

CLID_Attach (char *serverName)<br />

{<br />

if (serverName == NULL) {<br />

sprintf (CLID_serverName, "/PARSE/CLID");<br />

} else {<br />

strcpy (CLID_serverName, serverName);<br />

}<br />

clid_pid = qnx_name_locate (0, CLID_serverName,<br />

sizeof (CLID_ServerIPC), NULL);<br />

292 Appendix: A • <strong>QNX</strong> 4 to <strong>Neutrino</strong> April 30, 2009

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

Saved successfully!

Ooh no, something went wrong!