Chapter 10. Abstracted Functions

Table of Contents

10.1. Linux or QNX (in lib/linux.g, lib/qnx.g)
10.1.1. System Calls - anyos_system
10.1.2. Showing Help - anyos_help
10.2. Linux, QNX 4, or QNX 6 (in lib/linux.g, lib/qnx4.g, lib/qnx6.g)
10.2.1. Process Termination - anyos_find_process
10.2.2. Reassigning Strings - anyos_assign
10.3. QNX 4 or QNX 6 (in lib/qnx4.g, lib/qnx6.g)
10.3.1. Loading Extra Libraries for QNX 4 - anyver_loadlibs, gui_require
10.4. GTK or Photon (in lib/gtk.g, lib/photon.g)
10.4.1. Displaying Text - anygui_show_text
10.4.2. Process Termination - anygui_sigchild
10.4.3. Process Termination - anygui_destroyer
10.4.4. Buttons - .switched_on
10.4.5. Moving the Window - anygui_move_window
10.4.6. Change PID settings in the Monitor - anyos_change_settings
10.4.7. Creating a Message/Dialog Window - anygui_makemsg
10.5. GTK only (in lib/gtk.g)
10.5.1. Buttons - button_messages
10.6. Photon 1.14 or Photon 2 (in lib/qnx4.g, lib/qnx6.g)
10.6.1. Accessing Trend Data - .put_data
10.6.2. Numeric Callbacks - anyver_numeric_callback
10.6.3. Numeric Assignments - anyver_numeric_assign
10.6.4. Numeric Changing Settings - anyver_change_settings
10.7. Photon only (in lib/photon.g)
10.7.1. Buttons - PtLabel.get_text, PtLabel.set_text
10.7.2. Rollovers - PtBasic.rollover, attach_msg

These functions have been created to handle differences between different operating systems (Linux, QNX 4, and QNX 6) and/or different graphical user interfaces (GTK, Photon 1.14 and Photon 2). We refer to these functions as "abstracted" because they come in OS- or GUI-specific pairs or triplets, where each function has exactly the same name and arguments. Each function in the pair or triplet is included in a mutually exclusive OS-specific or GUI-specific library. When a program starts up, the common.g function lib_require ensures that the appropriate libraries are loaded. Thereafter, when the program or the common code calls one of these functions, the code that runs is specific to the OS and GUI in use.

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

10.1. Linux or QNX (in lib/linux.g, lib/qnx.g)

Section 10.1.1, “System Calls - anyos_system”
Section 10.1.2, “Showing Help - anyos_help”

10.1.1. System Calls - anyos_system

This function has been abstracted because the QNX operating system emits a signal when it makes a system call. In QNX we have to block signals while we make the system call.

10.1.1.1. For Linux (lib/linux.g)

   /*--------------------------------------------------------------------
    * Function:    anyos_system
    * Returns:     doesn't return
    * Description: A wrapper for the system() function to allow for alternate
    *              code in QNX.
    *------------------------------------------------------------------*/
   function anyos_system(call, sig)
   {
     system(call);
   }
   

10.1.1.2. For QNX (lib/qnx.g)

The Gamma functions block_signal and unblock_signal signal are used for deactivating signals while the system call is made. The signal has to be re-defined using the Gamma signal function once block_signal has been used.

   /*--------------------------------------------------------------------
    * Function:    anyos_system
    * Application: common 
    * Returns:     t or nil
    * Description: A wrapper for the Gamma system() function that blocks
    *              signals while making a call, then reassigns a signal
    *              and unblocks the signals.  This is necessary for QNX4,
    *              and perhaps QNX6, because in that OS a system() call
    *              emits a signal.  
    *------------------------------------------------------------------*/
   function anyos_system(call, sig)
   {
     block_signal(sig);
     system(call);
     signal(sig, `anygui_sigchild());
     unblock_signal(sig);
   }
   

10.1.2. Showing Help - anyos_help

Each of these functions calls the anygui_makemsg function to create the message/dialog window that displays the message.

10.1.2.1. For Linux (lib/linux.g)

For Linux we assume that help files are not installed on the system, but that a browser is installed. Thus, this function walks through a list of browsers and starts the first available one, pointing it to the on-line Cogent documentation for the Demo and Tutorials. We use the find_on_path fuction to locate a browser that is actually installed.

   /*--------------------------------------------------------------------
    * Function:    anyos_help
    * Returns:     function
    * Description: Starts up a browser and displays the Tutorial docs.
    *------------------------------------------------------------------*/
   function anyos_help()
   {
     local url = "http://developers.cogentrts.com/cogent/cogentdocs/booktu.html";
     local browser, browsers = list("galeon", "mozilla", "lynx", "opera",
                                    "dillo", "netscape", "w3m", "netrik",
                                    "skipstone", "amaya", "phoenix", "elinks");
     local b_length = length(browsers);
   
     for (i = 0; i < b_length; i++)
       {
         browser = car(nth_cdr(browsers,i));
         if (find_on_path(browser))
           {
             system(string(browser, " ", url, " &"));
             i = b_length;
           }
         else if(i == (b_length - 1))
           anygui_makemsg(string("\nSorry, your browser isn't supported. ",
                             "Try installing one of these: \n",
                             browsers, "\n\n",
                             "Or modify the anyos_help() function, ",
                             "line 60, in lib/linux.d\n",
                             "and add your browser to the list.\n"));
       }
   }
   

10.1.2.2. For QNX (lib/qnx.g)

For QNX running Photon, we assume that the Helpviewer is available to view the documentation. We use the Gamma is_file function to make sure the documentation has been installed in the Helpviewer. Then we use the Gamma/Photon functions PxHelpTopicRoot and PxHelpTopic to set the Helpviewer to the proper page. When QNX 6 is running GTK, the Px* functions are not readily available, so we use Voyager to view the documentation.

   /*--------------------------------------------------------------------
    * Function:    anyos_help
    * Returns:     t or nil
    * Description: Starts up the Helpviewer and displays the Tutorial docs.
    *------------------------------------------------------------------*/
   function anyos_help()
   {
     local help_url = "/usr/cogent/help/cogent-set/booktu/booktu.html";
     
     if (is_file(help_url))
       {
         if (_gui_ == "Photon")
           {
             /* Use Helpviewer */
             PxHelpTopicRoot("/Cogent Documentation/Cogent Tools Demo and Tutorial");
             PxHelpTopic("booktu.html");
           }
         else
           {
             /* Use Voyager */
             help_url = "http://developers.cogentrts.com/cogent/cogentdocs/booktu.html";
             system(string("voyager -u ", help_url, " &"));
           }
       }
     else
       anygui_makemsg(string("\nSorry, the Cogent Tools Demo and Tutorial",
                             "\nmanual is not available on your system.\n",
                             "\nPlease check your",
                             "\nCogent Documentation installation.\n\n"));
   }