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.

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

The value member is actually a union:<br />

union sigval {<br />

int sival_int;<br />

void *sival_ptr;<br />

};<br />

Therefore (expanding on the server example above), you often see code like:<br />

#include <br />

rcvid = MsgReceive (chid, ...<br />

if (rcvid == 0) {<br />

// it’s a pulse<br />

// determine the type of pulse<br />

switch (msg.pulse.code) {<br />

case MY_PULSE_TIMER:<br />

// One of your timers went off, do something<br />

// about it...<br />

break;<br />

case MY_PULSE_HWINT:<br />

// A hardware interrupt service routine sent<br />

// you a pulse. There’s a value in the "value"<br />

// member that you need to examine:<br />

val = msg.pulse.value.sival_int;<br />

// Do something about it...<br />

break;<br />

case _PULSE_CODE_UNBLOCK:<br />

// A pulse from the kernel, indicating a client<br />

// unblock was received, do something about it...<br />

break;<br />

// etc...<br />

} else { // it’s a regular message<br />

}<br />

// determine the type of message<br />

// handle it<br />

This code assumes, of course, that you’ve set up your msg structure to contain a<br />

struct _pulse pulse; member, and that the manifest constants<br />

MY_PULSE_TIMER and MY_PULSE_HWINT are defined. The pulse code<br />

_PULSE_CODE_UNBLOCK is one of those negative-numbered kernel pulses<br />

mentioned above. You can find a complete list of them in along<br />

<strong>with</strong> a brief description of the value field.<br />

April 30, 2009 Chapter 2 • Message Passing 115

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

Saved successfully!

Ooh no, something went wrong!