BEA Logo BEA Tuxedo Release 7.1

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

 

   Tuxedo Doc Home   |   Programming   |   Topic List   |   Previous   |   Next   |   Contents

   Programming a BEA Tuxedo Application Using C

Client Process Examples

The following pseudo-code shows how a typical client process works from the time at which it joins an application to the time at which it leaves the application.

Typical Client Process Paradigm


main()
{
check level of security
call tpsetunsol() to name your handler for TPU_DIP
get usrname, cltname
prompt for application password
allocate a TPINIT buffer
place values into TPINIT buffer structure members

if (tpinit((TPINIT *) tpinfo) == -1){
error routine;
}

allocate a message buffer
while user input exists {
place user input in the buffer
make a service call
receive the reply
check for unsolicited messages
}
free buffers
. . .
if (tpterm() == -1){
error routine;
}
}


On error, -1 is returned and the application sets the external global variable, tperrno, to a value that indicates the nature of the error. tperrno is defined in the atmi.h header file and documented in tperrno(5) in the BEA Tuxedo File Formats and Data Descriptions Reference. Programmers typically assign, to this global variable, an error Introduction to the C Language Application-Transaction Monitor Interface in the BEA Tuxedo C Function Reference for a complete list of error codes that can be returned for each of the ATMI functions.

The following example illustrates how to use the tpinit() and tpterm() functions. This example is borrowed from, bankapp, the sample banking application that is provided with the BEA Tuxedo system.

Joining and Leaving an Application


#include <stdio.h>         /* UNIX */
#include <string.h> /* UNIX */
#include <fml.h> /* BEA Tuxedo System */
#include <atmi.h> /* BEA Tuxedo System */
#include <Uunix.h> /* BEA Tuxedo System */
#include <userlog.h> /* BEA Tuxedo System */
#include "bank.h" /* BANKING #defines */
#include "aud.h" /* BANKING view defines */

...

main(argc, argv)
int argc;
char *argv[];

{
...
if (strrchr(argv[0],'/') != NULL)
proc_name = strrchr(argv[0],'/')+1;
else
proc_name = argv[0];
...
/* Join application */
if (tpinit((TPINIT *) NULL) == -1) {
(void)userlog("%s: failed to join application\n", proc_name);
exit(1);
}
...
/* Leave application */
if (tpterm() == -1) {
(void)userlog("%s: failed to leave application\n", proc_name);
exit(1);
}
}


The previous example shows the client process attempting to join the application with a call to tpinit(). If the process encounters an error (that is, if the return code is -1), the process writes a descriptive message to the central event log via a call to userlog(), which takes arguments similar to the printf() C program statement. Refer to userlog(3c) in the BEA Tuxedo C Function Reference for more information.

Similarly, when tpterm() is called, if an error is encountered, the process writes a descriptive message to the central event log.