Controller Functions

Cogent Tools Demo and Tutorials: Version 4.0
Prev |  | Next

# Chapter 12. Controller Functions

This chapter presents annotated code for `gtkcontrol.g` (for GTK) and `phcontrol.g`, as well as contain common functions that are used in Linux or QNX, GTK or Photon.

# 12.1. Choosing a Controller - the `demo.g` program

This mini-program starts the Tools Demo by starting the Controller. It first checks to make sure that a Controller is not running, and then it chooses which Controller program to run: `gtkcontrol.g` or `phcontrol.g`, based on the current operating system, and (in the case of QNX 6) the desired GUI.

       /*--------------------------------------------------------------------
        * File:        demo.g
        *
        * Description: This program starts the demo.
        *------------------------------------------------------------------*/

       /*--------------------------------------------------------------------
        * Function:    main
        * Returns:     doesn't return
        * Description: Calls gtkcontrol.g or phcontrol.g, depending on the OS
        *              and/or a command line argument.
        *------------------------------------------------------------------*/
       function main()
       {
         if (_os_ == "Linux")
           system("gamma gtkcontrol.g");
         else if (_os_ == "QNX4")
           system("phgamma phcontrol.g");

The prompt for QNX 4 Gamma programs that run Photon is phgamma, not gamma. This `demo.g` program lets us effectively wrap the phgamma command in a gamma command, giving us one, simple way to start the demo in any of the three operating systems.

         else if (_os_ == "QNX6")
           {
             if (cadr(argv) == nil)
               system("gamma phcontrol.g");
             else if (cadr(argv) == "photon")
               system("gamma phcontrol.g");
             if (cadr(argv) == "gtk")
               system("gamma gtkcontrol.g");
           }
       }

The Gamma function `system` function is used to send the system command gamma *control.g, which starts the Controller. The optional third argument in the gamma demo command (which is only available in QNX 6) is accessed using `argv`, a symbol containing a list of command-line arguments. We use the Gamma function `cadr` to extract the third argument (if any) from the list.

Prev | Home | Next
The Monitor in Photon | Up | GTK: the Controller window - `create_control_win`

Copyright 1995-2002 by Cogent Real-Time Systems, Inc.