Chapter 9. Common Functions for Any Program (in lib/common.g)

Table of Contents

9.1. Requiring OS-Specific Libraries - lib_require
9.2. Starting Programs - program_startup
9.3. Starting qserve and nserve - start_qnserves
9.4. Control Button Functionality - start_stop
9.5. Start a Process - start_process, find_on_path
9.6. Handling Terminated Processes - child_died
9.7. Kill a Child Process - kill_child
9.8. Stop Processes - stop_processes
9.9. Sending Messages - send_message, started_died_hook

Any function in the demo that can be used in Linux, QNX 4, QNX6, GTK and Photon is put in the lib/common.g file. This helps avoid duplication and facilitates maintenance of the code. Some functions in the lib/common.g file are specific to one program in the demo (such as the Controller, Log, or History), and are thus are documented with that particular program. The functions documented in this chapter are those from lib/common.g that are used by several or all of the programs in the demo.

For more information on common and abstracted functions, please refer to Section 3.1, “File Overview”.

9.1. Requiring OS-Specific Libraries - lib_require

Since this demo runs in three different operating systems, each program needs to know which OS is running, so it can load the appropriate library functions. The actual loading functionality is provided by the Gamma require function.

   /*--------------------------------------------------------------------
    * Function:    lib_require
    * Returns:     t or nil
    * Description: Finds the name of the current OS, and requires (loads)
    *              the library files specific to that OS.
    *------------------------------------------------------------------*/
   function lib_require ()
   {
     if (_os_ == "Linux")
       require("lib/linux.g");
     else if (_os_ == "QNX4")
       {
         require("lib/qnx.g");
         require("lib/qnx4.g");
       }
     else if (_os_ == "QNX6")
       {
         require("lib/qnx.g");
         require("lib/qnx6.g");
       }
   }
   
   lib_require();