View the Code

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

# Chapter 3. View the Code

# 3.1. File Overview

The code for the Cogent Tools Demo has been written to facilitate cross-platform implementation in Linux and QNX, and their respective GUIs--GTK and Photon. Despite cosmetic differences due to the different GUI software, much of the functionality within the programs is similar if not identical. To avoid having to maintain and document several versions of identical or similar functions, we have set up libraries that contain common code and abstracted code. Overall, there are three general categories of functions, grouped into files as follows.

Application-specific functions are specific to a single application, such as the PID Emulator (`emul.g`) or the Monitor running in Photon (`phmonitor.g`). Each Photon-specific program (`ph*.g`) has two sets of widget files: a Photon 1.14 version for QNX 4, and a Photon 2 version for QNX 6.

Common functions run on any OS (Linux, QNX 4, and QNX 6), regardless of GUI support (GTK or Photon), and are all found in `lib/common.g`. Every application loads these.

Abstracted functions are a group of functions that come in pairs or triples. Each member of the pair or triple varies from OS to OS or from GUI to GUI, but has the same name, takes the same argument lists and performs the same tasks as the other function(s) in that group. But the code within the function is different. For example, the `anyos_help` function in `lib/linux.g` calls a web browser on a Linux system to display this book's title page, while `anyos_help`a function in `lib/qnx.g` calls the Helpviewer on a QNX system to display the same page.

The libraries that contain these identically-named functions are loaded in a mutually exclusive way, using the Gamma `require` function. The `lib/common.g` file's first function is `lib_require`, which determines the operating system and loads one of the following groups:

- In Linux it loads `lib/linux.g`, which then loads `lib/gtk.g`.

- In QNX 4 it loads `lib/qnx.g` and `lib/qnx4.g`. The `lib/qnx4.g` file loads `lib/photon.g`.

- In QNX 6 it loads `lib/qnx.g` and `lib/qnx6.g` for QNX 6. The `lib/qnx6.g` function `gui_require` chooses between `lib/photon.g` and `lib/gtk.g`, depending on the command-line prompt.

Once a library is loaded its functions are accessible by the original program and any other function in the loaded group.

Prev | Home | Next
Using the Cogent PID Demo for Windows (available soon) | Up | `demo.g` - The Demo Start-Up mini-program

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