BEA Logo BEA Tuxedo Release 7.1

  Corporate Info  |  News  |  Solutions  |  Products  |  Partners  |  Services  |  Events  |  Download  |  How To Buy

 

   Tuxedo Doc Home   |   Getting Started   |   Topic List   |   Previous   |   Next   |   Contents

   Tutorials for Developing a BEA Tuxedo Application

Examining the bankapp Clients

What Is the bankclt.c File

The bankclt file contains the client program that requests BEA Tuxedo services from the bankapp application. This client program is text-based and provides the following options:

Each of these options, except Exit Application, calls a subroutine that performs the following tasks:

  1. Obtains the user input from the keyboard using the get_account(), get_amount(), get_socsec(), get_phone(), and the get_val() functions.

  2. Puts the values into a global FML buffer (*fbfr). (Some functions add more fields than others. This is dependent on the information needed by the servers.)

  3. Enables routines that make a request to the BEA Tuxedo system through the do_tpcall() function to invoke the required service. The following table lists the functions and the services they invoke.

    Services Called by Function

    Function Name

    Input FML Fields

    Output FML Fields

    Service Name

    BALANCE()

    ACCOUNT_ID

    SBALANCE

    INQUIRY

    WITHDRAWAL()

    ACCOUNT_ID SAMOUNT

    SBALANCE

    WITHDRAWAL

    DEPOSIT()

    ACCOUNT_ID SAMOUNT

    SBALANCE

    DEPOSIT

    TRANSFER()

    ACCOUNT_ID (0)1 ACCOUNT_ID (1)
    SAMOUNT

    SBALANCE (0)
    SBALANCE (1)

    TRANSFER

    OPEN_ACCT()

    LAST_NAME FIRST_NAME MID_INIT
    SSN
    ADDRESS
    PHONE
    ACCT_TYPE BRANCH_ID SAMOUNT

    ACCOUNT_ID SBALANCE

    OPEN_ACCT

    CLOSE_ACCT()

    ACCOUNT_ID

    SBALANCE

    CLOSE_ACCT

1The number in parentheses is the FML occurrence number for that field.

  1. After the call completes successfully, each function gets the fields it needs from the returned FML buffer and prints the results.

The do_tpcall() function (that begins on line 447 in bankclt.c ) follows:

do_tpcall() in bankclt.c


/*
* This function does the tpcall to Tuxedo.
*/
static int
do_tpcall(char *service)

{

long len;
char *server_status;
/* Begin a Global transaction */
if (tpbegin(30, 0) == -1) {
(void)fprintf(stderr, "ERROR: tpbegin failed (%s)\n",
tpstrerror(tperrno));
return(-1);
}
/* Request the service with the user data */
if (tpcall(service, (char *)fbfr, 0, (char **)&fbfr, &len,
0) == -1) {
if(tperrno== TPESVCFAIL && fbfr != NULL &&
(server_status=Ffind(fbfr,STATLIN,0,0)) != 0) {
/* Server returned failure */
(void)fprintf(stderr, "%s returns failure
(%s)\n",
service,server_status);
}
else {
(void)fprintf(stderr,
"ERROR: %s failed (%s)\n", service,
tpstrerror(tperrno));
}
/* Abort the transaction */
(void) tpabort(0);
return(-1);
}
/* Commit the transaction */
if(tpcommit(0) < 0) {
(void)fprintf(stderr, "ERROR: tpcommit failed
(%s)\n",
tpstrerror(tperrno));
return(-1);
}
return(0);
}

The do_tpcall() function performs the following tasks:

How ud(1) Is Used in bankapp

bankapp uses the BEA Tuxedo program ud(1), which allows fielded buffers to be read from standard input and sent to a service. In the sample application, ud is used by both the populate and driver programs:

A Request/Response Client: audit.c

audit is a request/response client program that makes branch-wide or bank-wide balance inquiries, using the services: ABAL, TBAL, ABAL_BID, and TBAL_BID. You can invoke it in two ways:

The source code for audit contains two major parts: main() and a subroutine called sum_bal(). BEA Tuxedo ATMI functions are used in both parts. The program uses a VIEW typed buffer and a structure that is defined in the aud.h header file. The source code for the structure can be found in the view description file, aud.v.

The following pseudo-code shows the algorithm for the program.

audit Pseudo-code


     main()
{
Parse command-line options with getopt();
Join application with tpinit();
Begin global transaction with tpbegin();
If (branch_ID specified) {
Allocate buffer for service requests with tpalloc();
Place branch_ID into the aud structure;
Do tpcall() to "ABAL_BID" or "TBAL_BID";
Print balance for branch_ID;
Free buffer with tpfree();
}
else /* branch_ID not specified */
call subroutine sum_bal();
Commit global transaction with tpcommit();
Leave application with tpterm();
}
sum_bal()
}
Allocate buffer for service requests with tpalloc();
For (each of several representative branch_ID's,
one for each site)
Do tpacall() to "ABAL" or "TBAL";
For (each representative branch_ID) {
Do tpgetrply() wtith TPGETANY flag set
to retrieve replies;
Add balance to total;
Print total balance;
}
Free buffer with tpfree();
}


Following is a summary of the two main parts of the audit source code.

In the programs main():

  1. /* Join application */

  2. /* Start global transaction */

  3. /* Create buffer and set data pointer */

  4. /* Do tpcall */

  5. /* Commit global transaction */

  6. /* Leave application /*

In the subroutine sum_bal:

  1. /* Create buffer and set data pointer */

  2. /* Do tpacall */

  3. /* Do tpgetrply to retrieve answers to questions */

A Conversational Client: auditcon.c

auditcon is a conversational version of the audit program. The source code for auditcon uses the ATMI functions for conversational communication: tpconnect() to establish the connection between the client and service, tpsend() to send a message, and tprecv() to receive a message.

The following pseudo-code shows the algorithm for the program.

auditcon Pseudo-code


    main()
{

            Join the application
Begin a transaction
Open a connection to conversational service AUDITC
Do until user says to quit: {
Query user for input
Send service request
Receive response
Print response on user's terminal
Prompt for further input
}

            Commit transaction
Leave the application
}


A Client that Monitors Events: bankmgr.c

bankmgr is included with bankapp as an example of a client that is designed to run constantly. It subscribes to application-defined events of special interest, such as the opening of a new account or a withdrawal above $10,000. (The bankmgr.c client is more fully described in the README2 file of bankapp and in the bankmgr.c code itself.)

See Also