Previous Topic

Next Topic

Sample Code

The Ingres installation includes OpenAPI sample code that demonstrates synchronous and asynchronous execution of OpenAPI functions. The sample code provides an example of how an application uses OpenAPI functions are and combines them to access database information.

The sample code is located in the API directory, which is under the Ingres demo directory. Makefiles for compiling and linking the demo programs are provided for UNIX (Makefile) and Windows NT (makefile.wnt) environments.

Previous Topic

Next Topic

How the Synchronous Sample Code Works

The synchronous sample code consists of a number of sources files whose names begin with the prefix "apis". Each source file demonstrates a single aspect of the OpenAPI interface and compiles into its own executable demo program.

OpenAPI functions are called synchronously: each OpenAPI function call is followed by a loop that calls IIapi_wait() repeatedly until the original OpenAPI call completes.

Note: Database event processing is inherently asynchronous and is not demonstrated in the synchronous sample code. The asynchronous sample code provides an extensive example of database event handling using OpenAPI.

Previous Topic

Next Topic

main() Function

The main() function at the beginning of the source file usually contains the specific aspect being demonstrated. OpenAPI function calls that support the demonstration, such as connection or transaction management, are at the end of the file. Sometimes, when the demonstration calls for multiple executions of an OpenAPI function, you can place the OpenAPI function call in its own function following main().

Previous Topic

Next Topic

Error Checking

Typically, the sample programs do not perform error checking on the results of OpenAPI function calls. Error processing is demonstrated in one of the sample programs.

In general, these source files show:

While the samples can be compiled and executed, the actual runtime actions performed provide little useful information.

Previous Topic

Next Topic

How You Can Run a Program

Each sample program takes a single command line argument, which is the target database to run against. For example:

apisconn mydb

Previous Topic

Next Topic

Source File Descriptions

The following list identifies the synchronous sample source files and the OpenAPI functionality they demonstrate.

Previous Topic

Next Topic

How the Asynchronous Sample Code Works

The asynchronous sample code consists of a number of sources files whose names begin with the prefix "apia". The source files are compiled and linked to produce a single comprehensive demo program that provides a real-life example of using OpenAPI in a client/server environment. OpenAPI functions are called asynchronously: each OpenAPI function call is provided with a callback function, which notifies the demo program of the completion of the function call.

Though single-threaded, the demo program consists of two independent execution units: a server unit, which creates, registers, and waits for database events, and a client unit, which periodically raises database events. The main processing control in the demo program initializes one, the other, or both of the execution units, then loops calling IIapi_wait() until all asynchronous activity has ended. Each execution unit, when initialized, issues its first asynchronous request. The units regain execution control when their requests complete and continue issuing new requests until they reach their termination conditions.

Previous Topic

Next Topic

How the Client Execution Unit Works

The client execution unit demonstrates asynchronous processing using unique callbacks. Each asynchronous OpenAPI call is given a unique callback function, which determines the next action to be performed when the call completes. Each callback function checks the OpenAPI function call status, processes any result data, and determines the next action to be performed. Operation continues by making a new asynchronous OpenAPI function call and providing the next function in the processing sequence as the callback function. After all requested database events have been raised (including the optional server termination event), the client unit stops making asynchronous OpenAPI requests.

Previous Topic

Next Topic

How the Server Execution Unit Works

The server execution unit demonstrates asynchronous processing using a Finite State Machine. A single callback function is used for all asynchronous OpenAPI calls. A control block passed with the asynchronous call contains the information necessary, including the current state, to process the call results and determine the next state and actions to be performed. The server unit continues waiting for and processing database events until the termination event is received. Upon receiving the termination event, the server unit cancels any active requests, frees resources, and terminates.

Previous Topic

Next Topic

How You Can Run the Demo Program

You can run the demo program in a variety of configurations: client-only, serveronly, and client and server. You can run multiple instances of the demo program simultaneously. Each server instance receives and displays events raised by each client instance.

You run the demo program with the following command line syntax:

apiademo [-s] [-c] [-t] [-i] db [n]

This command uses the following parameters:

Examples: apiademo command

The following commands are equivalent:

This command…

Is the same as this command…

apiademo dbname

apiademo -s -c -t dbname 5

apiademo -c dbname

apiademo -c dbname 5

apiademo -t dbname

apiademo -c -t db 0

Previous Topic

Next Topic

Source File Descriptions

The asynchronous sample source files are as follows:


© 2007 Ingres Corporation. All rights reserved.