Table of Contents Previous Next PDF

Tutorial for simpapp, a Simple C Application

Tutorial for simpapp, a Simple C Application
This topic includes the following sections:
What Is simpapp?
simpapp is a sample ATMI application that includes one client and one server. This application is distributed with the Oracle Tuxedo software. The server performs only one service: it accepts a lowercase alphabetic string from the client and returns the same string in uppercase.
Preparing simpapp Files and Resources
This topic is a tutorial that leads you, step-by-step, through the process of developing and running a sample Oracle Tuxedo ATMI application. Figure 2‑1 summarizes the process. Click on each task for instructions on completing that task.
Figure 2‑1 simpapp Development Process
Before You Begin
Before you can run this tutorial, the Oracle Tuxedo ATMI client and server software must be installed so that the files and commands referred to are available. If the installation has already been done by someone else, you need to know the pathname of the directory in which the software is installed (TUXDIR). You also need to have read and write permissions on the directories and files in the Oracle Tuxedo directory structure so you can copy simpapp files and execute Oracle Tuxedo commands.
About This Tutorial
The instructions for the simpapp tutorial are based on a UNIX system platform. While specific platform instructions for the UNIX operating system environment remain largely the same, instructions for performing tasks (such as copying simpapp files or setting environment variables) on non-UNIX platforms (such as Windows 2003) may be different. For this reason, the examples used in the tutorial may or may not provide reliable procedures for your platform.
What You Will Learn
After you complete this tutorial, you will be able to understand the tasks ATMI clients and servers can perform, edit a configuration file for your own environment, and invoke tmadmin to check on the activity of your application. You will understand the basic elements of all Oracle Tuxedo applications—client processes, server processes, and a configuration file—and you will know how to use Oracle Tuxedo system commands to manage your application.
Step 1: How to Copy the simpapp Files
Make a directory for simpapp and cd to it:
mkdir simpdir
cd simpdir
This step is suggested so you can see the simpapp files you have at the start and the additional files you create along the way. Use the standard shell (/bin/sh) or the Korn shell; do not use csh.
TUXDIR=pathname of the Oracle Tuxedo system root directory
TUXCONFIG=pathname of your present working directory/tuxconfig
You need TUXDIR and PATH to be able to access files in the Oracle Tuxedo system directory structure and to execute Oracle Tuxedo system commands. On Sun Solaris, /usr/5bin must be the first directory in your PATH. With AIX on the RS/6000, use LIBPATH instead of LD_LIBRARY_PATH. On HP-UX on the HP 9000, use SHLIB_PATH instead of LD_LIBRARY_PATH.
You need to set TUXCONFIG to be able to load the configuration file, described in “Step 4: Editing and Loading the Configuration File” on page 2‑10.
Copy the simpapp files:
cp $TUXDIR/samples/atmi/simpapp/* .
  $ ls
     README       env        simpapp.nt  ubbmp     wsimpcl
     README.as400 setenv.cmd simpcl.c    ubbsimple
     README.nt simpserv.c  ubbws
Except for the README files, the other files are variations of simp*.* and ubb* files for non-UNIX system platforms. The README files provide explanations of the other files.
The three files that are central to the application are:
simpcl.c—the source code for the client program.
simpserv.c—the source code for the server program.
ubbsimple—the text form of the configuration file for the application.
See Also
Step 2: Examining and Compiling the Client
How to Examine the Client
Review the ATMI client program source code:
$ more simpcl.c
The output is shown in Listing 2‑1.
Listing 2‑1 Source Code of simpcl.c
1     #include <stdio.h>          
2     #include "atmi.h"             /* TUXEDO */
7     #ifdef __STDC__
8     main(int argc, char *argv[])
10    #else
12    main(argc, argv)
13    int argc;
14    char *argv[];
15    #endif
17    {
19             char *sendbuf, *rcvbuf;
20             int sendlen, rcvlen;
21             int ret;
23             if(argc != 2) {
24                      fprintf(stderr, "Usage: simpcl string\n");
25                      exit(1);
26             }
27             /* Attach to BEA TUXEDO as a Client Process */
28             if (tpinit((TPINIT *) NULL) == -1) {
29                      fprintf(stderr, "Tpinit failed\n");
30                      exit(1);
31             }
32             sendlen = strlen(argv[1]);
33           if((sendbuf = (char *)tpalloc("STRING", NULL, sendlen+1))== NULL){
34                       fprintf(stderr,"Error allocating send buffer\n");
35                      tpterm();
36                      exit(1);
37             }
38             if((rcvbuf = (char *)tpalloc("STRING", NULL, sendlen+1))== NULL){
39                      fprintf(stderr,"Error allocating receive buffer\n");
40                      tpfree(sendbuf);
41                      tpterm();
42                      exit(1);
43             }
44             strcpy(sendbuf, argv[1]);
45             ret = tpcall("TOUPPER", sendbuf, NULL, &rcvbuf, &rcvlen, 0);
46             if(ret == -1) {
47                  fprintf(stderr, "Can't send request to service TOUPPER\n");
48                      fprintf(stderr, "Tperrno = %d, %s\n", tperrno,
49                                tmemsgs[tperrno]);
50                      tpfree(sendbuf);
51                      tpfree(rcvbuf);
52                      tpterm();
53                      exit(1);
54             }
55             printf("Returned string is: %s\n", rcvbuf);
57             /* Free Buffers & Detach from Oracle TUXEDO */
58             tpfree(sendbuf);
59             tpfree(rcvbuf);
60             tpterm();
61    }
The ATMI function used to allocate a typed buffer. STRING is one of the five basic Oracle Tuxedo buffer types; NULL indicates there is no subtype argument. The remaining argument, sendlen + 1, specifies the length of the buffer plus 1 for the null character that ends the string.
Sends the message buffer to the TOUPPER service specified in the first argument. Also includes the address of the return buffer. tpcall() waits for a return message.
The ATMI function used to exit an application. A call to tpterm() is used to exit the application before exiting in response to an error condition (lines 36, 42, and 53). The final call to tpterm() (line 60) is issued after the message has been printed.
Frees allocated buffers. tpfree() is the functional opposite of tpalloc().
How to Compile the Client
Run buildclient to compile the ATMI client program:
buildclient -o simpcl -f simpcl.c
The output file is simpcl and the input source file is simpcl.c.
$ ls -l
total 97
-rwxr-x--x 1 usrid grpid 313091 May 28 15:41 simpcl
-rw-r----- 1 usrid grpid 1064 May 28 07:51 simpcl.c
-rw-r----- 1 usrid grpid 275 May 28 08:57 simpserv.c
-rw-r----- 1 usrid grpid 392 May 28 07:51 ubbsimple
As can be seen, we now have an executable module called simpcl. The size of simpcl may vary.
See Also
buildclient(1) in Oracle Tuxedo Command Reference
Step 3: Examining and Compiling the Server
How to Examine the Server
Review the ATMI server program source code.
$ more simpserv.c
Listing 2‑2 Source Code of simpserv.c
/* #ident "@(#) apps/simpapp/simpserv.c $Revision: 1.1 $" */
1 #include <stdio.h>
2 #include <ctype.h>
3 #include <atmi.h> /* TUXEDO Header File */
4 #include <userlog.h> /* TUXEDO Header File */
5 /* tpsvrinit is executed when a server is booted, before it begins
   processing requests. It is not necessary to have this function.
   Also available is tpsvrdone (not used in this example), which is
   called at server shutdown time.
9 */
10 #if defined(__STDC__) || defined(__cplusplus)

12 tpsvrinit(int argc, char *argv[])
13 #else
14 tpsvrinit(argc, argv)
15 int argc;
16 char **argv;
17 #endif
18     {
19         /* Some compilers warn if argc and argv aren't used.
20          */
21        argc = argc;
22        argv = argv;
23        /* userlog writes to the central TUXEDO message log */
24         userlog("Welcome to the simple server");
25         return(0);
26 }
27 /* This function performs the actual service requested by the client.
      Its argument is a structure containing, among other things, a pointer
      to the data buffer, and the length of the data buffer.
30 */
31 #ifdef __cplusplus
32 extern "C"
33 #endif
34 void
35 #if defined(__STDC__) || defined(__cplusplus)
37 #else
38 TOUPPER(rqst)
39 TPSVCINFO *rqst;
40 #endif
41 {
42       int i;
44       for(i = 0; i < rqst->len-1; i++)
45               rqst->data[i] = toupper(rqst->data[i]);
46       /* Return the transformed buffer to the requestor. */
47       tpreturn(TPSUCCESS, 0, rqst->data, 0L, 0);
48 }
An Oracle Tuxedo server does not contain a main(). The main() is provided by the Oracle Tuxedo system when the server is built.
This subroutine is called during server initialization, that is, before the server begins processing service requests. A default subroutine (provided by the Oracle Tuxedo system) writes a message to USERLOG indicating that the server has been booted. userlog(3c) is a log used by the Oracle Tuxedo system and can be used by applications.
The declaration of a service (the only one offered by simpserv). The sole argument expected by the service is a pointer to a TPSVCINFO structure, which contains the data string to be converted to uppercase.
How to Compile the Server
Run buildserver to compile the ATMI server program:
buildserver -o simpserv -f simpserv.c -s TOUPPER
The executable file to be created is named simpserv and simpserv.c is the input source file. The -s TOUPPER option specifies the service to be advertised when the server is booted.
$ ls -l
total 97
-rwxr-x--x 1 usrid grpid 313091 May 28 15:41 simpcl
-rw-r----- 1 usrid grpid 1064 May 28 07:51 simpcl.c
-rwxr-x--x 1 usrid grpid 358369 May 29 09:00 simpserv
-rw-r----- 1 usrid grpid 275 May 28 08:57 simpserv.c
-rw-r----- 1 usrid grpid 392 May 28 07:51 ubbsimple
You now have an executable module called simpserv.
See Also
buildserver(1) in Oracle Tuxedo Command Reference
Step 4: Editing and Loading the Configuration File
How to Edit the Configuration File
In a text editor, familiarize yourself with ubbsimple, which is the configuration file for simpapp.
Listing 2‑3 The simpapp Configuration File
3 #Skeleton UBBCONFIG file for the BEA Tuxedo Simple Application.
4 #Replace the <bracketed> items with the appropriate values.
6 IPCKEY            <
Replace with valid IPC Key greater than 32,768>
8 #Example:
10 #IPCKEY 62345
12 MASTER simple
23                           APPDIR="<Replace with the current pathname>"
24             TUXCONFIG="<Replace with TUXCONFIG Pathname>"
25         UXDIR="<Root directory of Tuxedo (not /)>"
26 #Example:
27 #       APPDIR="/usr/me/simpdir"
28 #       TUXCONFIG="/usr/me/simpdir/tuxconfig"
29 #       TUXDIR="/usr/tuxedo"
31 <Machine-name> LMID=simple
32 #Example:
33 #tuxmach LMID=simple
36              LMID=simple GRPNO=1 OPENINFO=NONE
40              CLOPT="-A"
41 simpserv SRVGRP=GROUP1 SRVID=1
For each <string> (that is, for each string shown between angle brackets), substitute an appropriate value.
How to Load the Configuration File
Run tmloadcf to load the configuration file:
$ tmloadcf ubbsimple
Initialize TUXCONFIG file: /usr/me/simpdir/tuxconfig [y, q] ? y
$ ls -l
total 216
-rwxr-x--x 1 usrid grpid 313091 May 28 15:41 simpcl
-rw-r----- 1 usrid grpid 1064 May 28 07:51 simpcl.c
-rwxr-x--x 1 usrid grpid 358369 May 29 09:00 simpserv
-rw-r----- 1 usrid grpid 275 May 28 08:57 simpserv.c
-rw-r----- 1 usrid grpid 106496 May 29 09:27 tuxconfig
-rw-r----- 1 usrid grpid 382 May 29 09:26 ubbsimple
You now have a file called TUXCONFIG. The TUXCONFIG file is a new file under the control of the Oracle Tuxedo system.
See Also
tmloadcf(1) in the Oracle Tuxedo Command Reference
UBBCONFIG(5) in the File Formats, Data Descriptions, MIBs, and System Processes Reference
Step 5: How to Boot the Application
Execute tmboot to bring up the application:
$ tmboot
Boot all admin and server processes? (y/n): y
Booting all admin and server processes in /usr/me/simpdir/tuxconfig
Booting all admin processes ...
exec BBL -A:
process id=24223 ... Started.
Booting server processes ...
exec simpserv -A :
process id=24257 ... Started.
2 processes started.
The BBL is the administrative process that monitors the shared memory structures in the application. simpserv is the simpapp server that runs continuously, awaiting requests.
See Also
tmboot(1) in the Oracle Tuxedo Command Reference
“How to Boot the Application” in Administering an Oracle Tuxedo Application at Run Time
Step 6: How to Execute the Run-time Application
To execute your simpapp, have the client submit a request.
$ simpcl hello, world
Returned string is: HELLO, WORLD
See Also
Step 7: How to Monitor the Run-time Application
As the administrator, you can use the tmadmin command interpreter to check an application and make dynamic changes. To run tmadmin, you must have the TUXCONFIG environment variable set.
tmadmin can interpret and run over 50 commands. For a complete list, see tmadmin(1). The following uses two of the tmadmin commands.
$ tmadmin
The following lines are displayed:
tmadmin - Copyright (c) 1999 BEA Systems, Inc. All rights reserved.
Enter the printserver(psr) command to display information about servers:
> psr
a.out Name Queue Name Grp Name ID RqDone Load Done Current Service
---------- ---------- -------- -- ------ --------- ---------------
BBL 531993 simple 0 0 0 ( IDLE )
simpserv 00001.00001 GROUP1 1 0 0 ( IDLE )
Enter the printservice(psc) command to display information about the services:
> psc
Service Name Routine Name a.out Name Grp Name ID Machine # Done Status
------------ ------------ ---------- -------- -- ------- ------ ------
TOUPPER TOUPPER simpserv GROUP1 1 simple - AVAIL
See Also
tmadmin(1) in the Oracle Tuxedo Command Reference
Step 8: How to Shut Down the Application
Run tmshutdown to bring down the application:
$ tmshutdown
Shutdown all admin and server processes? (y/n): y
Shutting down all admin and server processes in /usr/me/simpdir/tuxconfig
Shutting down server processes ...
Server Id = 1 Group Id = GROUP1 Machine = simple: shutdown succeeded.
Shutting down admin processes ...
Server Id = 0 Group Id = simple Machine = simple: shutdown succeeded.
2 processes stopped.
$ cat ULOG*
113837.tuxmach!tmloadcf.10261: CMDTUX_CAT:879: A new file system has been created. (size = 32 4096-byte blocks)
113842.tuxmach!tmloadcf.10261: CMDTUX_CAT:871: TUXCONFIG file /usr/me/simpdir/tuxconfig has been created
113908.tuxmach!BBL.10768: LIBTUX_CAT:262: std main starting
113913.tuxmach!simpserv.10925: LIBTUX_CAT:262: std main starting
113913.tuxmach!simpserv.10925: Welcome to the simple server
114009.tuxmach!simpserv.10925: LIBTUX_CAT:522: Default tpsvrdone() function used.
114012.tuxmach!BBL.10768: CMDTUX_CAT:26: Exiting system
See Also
tmshutdown(1) in the Oracle Tuxedo Command Reference
userlog(3c) in the Oracle Tuxedo ATMI C Function Reference
“How to Shut Down Your Application” in Administering an Oracle Tuxedo Application at Run Time
“What Is the User Log (ULOG)?” in Administering an Oracle Tuxedo Application at Run Time

Copyright © 1994, 2017, Oracle and/or its affiliates. All rights reserved.