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

}<br />

/*<br />

* CLID_IPC (IPC message number)<br />

*<br />

* This routine will call the server <strong>with</strong> the global buffer<br />

* CLID_IPCData, and will stuff in the message number passed<br />

* as the argument.<br />

*<br />

* Should the server not exist, this routine will stuff the<br />

* .returnValue field <strong>with</strong> CLID_NoServer. Otherwise, no<br />

* fields are affected.<br />

*/<br />

void<br />

CLID_IPC (IPCMessage)<br />

int IPCMessage;<br />

{<br />

if (clid_pid == -1) {<br />

CLID_IPCData.returnValue = CLID_NoServer;<br />

return;<br />

}<br />

CLID_IPCData.serverFunction = IPCMessage;<br />

CLID_IPCData.type = 0x8001;<br />

CLID_IPCData.subtype = 0;<br />

if (Send (clid_pid, &CLID_IPCData, &CLID_IPCData,<br />

sizeof (CLID_IPCData),<br />

sizeof (CLID_IPCData))) {<br />

CLID_IPCData.returnValue = CLID_IPCError;<br />

return;<br />

}<br />

}<br />

void<br />

checkAttach ()<br />

{<br />

if (clid_pid == -1) {<br />

CLID_Attach (NULL);<br />

}<br />

}<br />

As you can see, the checkAttach() function is used to ensure that a connection exists to<br />

the CLID server. If you didn’t have a connection, it would be like calling read() <strong>with</strong><br />

an invalid file descriptor. In my case here, the checkAttach() automagically creates the<br />

connection. It would be like having the read() function determine that there is no valid<br />

file descriptor and just create one out of the blue. Another style issue.<br />

The customized messaging occurs in the CLID_IPC() function. It takes the global<br />

variable CLID_IPCData and tries to send it to the server using the <strong>QNX</strong> 4 Send()<br />

function.<br />

The customized messages can be handled in one of two ways:<br />

1 Functionally translate them into standard, file-descriptor-based POSIX calls.<br />

Or:<br />

2 Encapsulate them into either a devctl() or a customized message wrapper using<br />

the _IO_MSG message type.<br />

294 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!