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. time1.c<br />

time1.c<br />

For more information about this program, see “Server-maintained timeouts” in the<br />

Clocks, Timers, and <strong>Getting</strong> a Kick Every So Often chapter.<br />

/*<br />

* time1.c<br />

*<br />

* Example of a server that receives periodic messages from<br />

* a timer, and regular messages from a client.<br />

*<br />

* Illustrates using the timer functions <strong>with</strong> a pulse.<br />

*/<br />

#include <br />

#include <br />

#include <br />

#include <br />

#include <br />

#include <br />

#include <br />

#include <br />

// message send definitions<br />

// messages<br />

#define MT_WAIT_DATA 2 // message from client<br />

#define MT_SEND_DATA 3 // message from client<br />

// pulses<br />

#define CODE_TIMER 1 // pulse from timer<br />

// message reply definitions<br />

#define MT_OK 0 // message to client<br />

#define MT_TIMEDOUT 1 // message to client<br />

// message structure<br />

typedef struct<br />

{<br />

int messageType;<br />

int messageData;<br />

} ClientMessageT;<br />

// contains both message to and from client<br />

// optional data, depending upon message<br />

typedef union<br />

{<br />

ClientMessageT msg; // a message can be either from a client, or<br />

struct _pulse pulse; // a pulse<br />

} MessageT;<br />

// client table<br />

#define MAX_CLIENT 16<br />

// maximum number of simultaneous clients<br />

struct<br />

{<br />

int in_use;<br />

// is this client entry in use?<br />

int rcvid;<br />

// receive ID of client<br />

int timeout;<br />

// timeout left for client<br />

} clients [MAX_CLIENT]; // client table<br />

April 30, 2009 Appendix: C • Sample Programs 317

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

Saved successfully!

Ooh no, something went wrong!