Table of Contents
The functions in this chapter are identical in both gtksimple.g and phsimple.g, because for this tutorial we want to have all the code for each GUI version (GTK or Photon) complete in its own unique file. Generally we prefer to avoid duplicating code, but this exception was made to keep the focus on the code, rather than on file organization. Later, in Chapter 9, Common Functions for Any Program (in lib/common.g) (Tutorial Two), we will see how these two functions, and others, are maintained in a library of common code.
The Cogent C API utilities qserve and nserve support interprocess communication, and must be started before any IPC is performed within the demo. Due to underlying differences in QNX 4 and QNX 6 OS architecture, the program has to use different Gamma functions (qnx_name_locate and access) to see if the processes are already running, and then start the two utilities accordingly.
These utilities are now started automatically by the Cogent program that uses them; this code is simply a fail-safe. |
This function is an adaptation of the common function start_qnserves explained in Tutorial Two. |
/*-------------------------------------------------------------------- * Function: start_qnserves * Returns: t on success, or nil * Description: Used to start qserve or nserve, as specified. Called by * the program_startup() function. *------------------------------------------------------------------*/ function start_qnserves(command, name) { for(i=0; i<=50; i++) { if ((_os_ == "Linux") || (_os_ == "QNX4")) if ((qnx_name_locate(0, name, 0) == nil)) { system(command); usleep(10000); } else { i = 50; nil; } else if (access(string("/dev/", command), 0) == -1) { system(command); usleep(10000); } else { i = 50; nil; } } }
This function uses the Gamma for statement to create a loop. If the requested program is not running, the function starts the command using a Gamma system call, followed by a usleep call to ensure adequate time for each utility to get running. The for loop allows for several attempts in case either utility was not able to be on-line within 10000 ms.
Copyright © 1995-2010 by Cogent Real-Time Systems, Inc. All rights reserved.