Examples

This chapter describes examples of Tmax programs developed in various environments.

1. Programs for Each Communication Type

This section describes examples of synchronous, asynchronous, and interactive programs.

1.1. Synchronous Communication

In the following example, a client copies a string to a STRING buffer and calls a service. The service routine of a server receives the string, converts it to all upper case, and then returns the converted string.

Program Files
  • Common program

    File Description

    sample.m

    Tmax configuration file.

  • Client program

    File Description

    sync_cli.c

    Client program.

  • Server program

    File Description

    syncsvc.c

    Service program that converts a string to all upper case.

    Makefile

    Tmax makefile that must be modified.

Program Feature
  • Client program

    Feature Description

    Tmax connection

    Basic connection (no client information).

    Buffer type

    STRING.

    Communication type

    Synchronous communication using tpcall().

  • Server program

    Feature Description

    Service

    TOUPPERSTR.

    Database connection

    None.

Tmax Configuration File

The following is an example.

<sample.m>

*DOMAIN
resrc         SHMKEY = 77990, MAXUSER = 256

*NODE
tmax          TMAXDIR = "/home/tmax",
              APPDIR =  "/home/tmax/appbin",
              PATHDIR = "/home/tmax/path",
              TLOGDIR = "/home/tmax/log/tlog",
              ULOGDIR = "/home/tmax/log/slog",
              SLOGDIR = "/home/tmax/log/ulog"

*SVRGROUP
svg1          NODENAME = tmax

*SERVER
syncsvc       SVGNAME = svg1,
              MIN = 1, MAX = 5,
              CLOPT = " –e $(SVR).err –o $(SVR).out "

*SERVICE
TOUPPERSTR    SVRNAME = syncsvc
Client Program

The following is an example.

<sync_cli.c>

#include <stdio.h>
#include <string.h>
#include <usrinc/atmi.h>

main(int argc,char *argv[])
{
       char *sendbuf, *recvbuf;
       long rlen;

       if (argc != 2)
       {
              fprintf(stderr,"Usage: $ %s string \n",argv[0]);
              exit(1);
       }

       if (tpstart((TPSTART_T*)NULL) == -1)
       {
              fprintf(stderr,"Tpstart failed\n");
              exit(1);
       }

       if ((sendbuf = tpalloc("STRING",NULL,0)) == NULL) {
              fprintf(stderr,"Error allocation send buffer\n");
              tpend();
              exit(1);
       }

       if ((recvbuf = tpalloc("STRING",NULL,0)) == NULL) {
                     fprintf(stderr,"Error allocation recv buffer\n");
              tpend();
              exit(1);
       }

       strcpy(sendbuf ,argv[ 1 ] ) ;

       if ( tpcall("TOUPPERSTR",sendbuf,0,&sendbuf,&rlen, TPNOFLAGS) == -1)
       {
              fprintf(stderr,"Can’t send request to service TOUPPER->%s!\n",
              tpstrerror(tperrno)) ;
              tpfree(sendbuf) ;
              tpfree(recvbuf) ;
              tpend();
              exit(1);
       }
       printf("Sent value:%s\n ",sendbuf );
       printf("Returned value:%s\n ",recvbuf );
       tpfree(sendbuf);
       tpfree(recvbuf);
       tpend( );
Server program

The following is an example.

<syncsvc.c>

#include <stdio.h>
#include <usrinc/atmi.h>

TOUPPERSTR(TPSVCINFO *msg)
{
       int i;

       for (i = 0; i < msg->len ; i++)
       msg->data[i] = toupper(msg->data[i]);
       msg->data[i] = ‘\0’;

       tpreturn(TPSUCCESS, 0, msg->data, 0, TPNOFLAGS);
}

1.2. Asynchronous Communication

In the following example, a client copies a string to a STRUCT buffer and calls a service. The service routine of a server receives the string, converts it to upper or lower case, and then returns the converted string. The client requests the TOUPPER service through asynchronous communication and then calls the TOLOWER service through synchronous communication. The client receives the TOLOWER service result first and then receives the TOUPPER service result.

Program Files
  • Common program

    File Description

    demo.s

    Defines a struct buffer.

    sample.m

    Tmax configuration file.

  • Client program

    File Description

    async_cli.c

    Client program.

  • Server program

    File Description

    asyncsvc.c

    Service program converts a string to upper or lower case.

    Makefile

    Tmax makefile that must be modified.

Program Feature
  • Client program

    Feature Description

    Tmax connection

    Basic connection.

    Buffer type

    STRUCT.

    Communication type

    Synchronous and asynchronous.

  • Server program

    Feature Description

    Service

    TOUPPER, TOLOWER.

    Database connection

    None.

    Communication type

    Synchronous and asynchronous.

Struct Buffer

The following example is a struct buffer used for asynchronous communication.

<demo.s>

struct strdata {
   int flag;
   char sdata[20];
};
Tmax Configuration File

The following is an example.

<sample.m>

*DOMAIN
resrc         SHMKEY = 77990, MAXUSER = 256

*NODE
tmax          TMAXDIR = "/home/tmax",
              APPDIR = "/home/tmax/appbin",
              PATHDIR = "/home/tmax/path"

*SVRGROUP
svg1          NODENAME = tmax

*SERVER
asyncsvc      SVGNAME = svg1, MIN = 1, MAX = 5

*SERVICE
TOUPPER        SVRNAME = asyncsvc
TOLOWER        SVRNAME = asyncsvc
Client Program

The following is an example.

<async_cli.c>

#include <stdio.h>
#include <string.h>
#include <usrinc/atmi.h>
#include "../sdl/demo.s"

main(int argc,char *argv[ ])
{
       struct strdata *sendbuf, *sendbuf1;
       long dlen,clen;
       int cd;

       if (argc != 3) {
              fprintf(stderr, "Usage: $ %s string STRING\n", argv[0], argv[1]);
              exit(1) ;
       }

       if (tpstart((TPSTART_T *)NULL) == -1) {
              fprintf(stderr, "TPSTART_T failed\n");
              exit(1) ;
       }

       sendbuf = (struct strdata *)tpalloc("STRUCT", "strdata", 0);
       if ( sendbuf == NULL) {
              fprintf(stderr, "Error allocation send buffer\n");
              tpend () ;
              exit(1) ;
       }

       sendbuf1 = (struct strdata *)tpalloc("STRUCT", "strdata", 0);
       if (sendbuf1 == NULL) {
              fprintf(stderr, "Error allocation send1 buffer\n");
              tpend();
              exit(1) ;
       }

       strcpy(sendbuf->sdata, argv[1]);
       strcpy(sendbuf1->sdata, argv[2]);

       if ((cd = tpacall("TOUPPER", (char *)sendbuf, 0, TPNOFLAGS)) == -1)
       {
              fprintf(stderr, "Toupper error -> %s", tpstrerror(tperrno));
              tpfree((char *)sendbuf);
              tpend();
              exit(1) ;
       }
       if (tpcall("TOLOWER",(char *)sendbuf1,0,(char **)&sendbuf1, &dlen,
                               TPSIGRSTRT) == -1) {
              fprintf(stderr, "Tolower error -> %s", tpstrerror(tperrno));
              tpfree((char *)sendbuf);
              tpend();
              exit(1) ;
       }
       if (tpgetrply(&cd, (char **)&sendbuf, &clen, TPSIGRSTRT) == -1) {
              fprintf(stderr, "Toupper getrply error -> %s", tpstrerror(tperrno));
              tpfree((char *)sendbuf);
              tpend();
              exit(1) ;
       }
       printf("Return value %s\n %s\n", sendbuf -> sdata, sendbuf1 -> sdata);
       tpfree((char *)sendbuf);
       tpfree((char *)sendbuf1);
       tpend() ;
}
Server program

The following is an example.

<asyncsvc.c>

#include <stdio.h>
#include <usrinc/atmi.h>
#include "../sdl/demo.s"

TOUPPER(TPSVCINFO *msg)
{
       int i = 0;
       struct strdata *stdata;

       stdata = (struct strdata *)msg -> data;

       while (stdata->sdata[ i ] != ‘\0’) {
       stdata->sdata[ i ] = toupper(stdata->sdata[ i ]);
       i++ ;
       }

       tpreturn(TPSUCCESS, 0, (char *)stdata, 0, TPNOFLAGS);
}

TOLOWER(TPSVCINFO *msg)
{
       int i = 0;
       struct strdata *stdata;

       stdata = (struct strdata *)msg -> data;

       while ( stdata->sdata[ i ] != ‘\0’) {
            stdata->sdata[ i ] = tolower(stdata->sdata[ i ]);
            i++;
       }

       tpreturn(TPSUCCESS, 0, (char *)stdata, 0, TPNOFLAGS);
}

1.3. Interactive Communication

A client receives user input and sends a number through a STRING buffer. The service routine of a server returns customer information with a number that is greater than the sent number in a database table.

The client sends the number along with a communication control to the server through interactive communication. The server reads all database data through a cursor and sends data that meets the condition to the client. The client can check that the data is successfully fetched through TPEVSVCSUCC.

Program Files
  • Common program

    File Description

    demo.s

    Defines a structure.

    sample.m

    Tmax configuration file.

    mktable.sql

    Script for creating a database table.

    sel.sql

    Script for outputting tables and data.

  • Client program

    File Description

    conv_cli.c

    Client program.

  • Server program

    File Description

    convsvc.pc

    Server program.

    Makefile

    Tmax makefile that must be modified.

Program Feature
  • Client program

    Feature Description

    Tmax connection

    Basic connection.

    Buffer type

    STRING for transmission and STRUCT for reception.

    Communication type

    Interactive.

  • Server program

    Feature Description

    Service

    MULTI.

    Database connection

    Oracle is used.

Struct Buffer

The following example is a struct buffer used for interactive communication.

<demo.s>

struct sel_o {
    char seqno[10];
    char corpno[10];
    char compdate[8];
    int totmon;
    float guarat;
    float guamon;
} ;
Tmax Configuration File

The following is an example.

<sample.m>

* DOMAIN
resrc        SHMKEY = 77990, MAXUSER = 256

*NODE
tmax          TMAXDIR = "/home/tmax",
              APPDIR  = "/home/tmax/appbin",
              PATHDIR ="/home/tmax/path"

* SVRGROUP
svg1          NODENAME = tmax,
              DBNAME = ORACLE,
              OPENINFO = "ORACLE_XA+Acc=P/scott/tiger+SesTm=60",
              TMSNAME = svg1_tms

*SERVER
convsvc       SVGNAME = svg1, CONV = Y

*SERVICE
MULTI         SVRNAME = convsvc

The following items are added.

Item Description

DBNAME

Database name.

OPENINFO

Oracle database connection information.

TMSNAME

Name of the process that handles global transactions.

CONV

Interactive mode server.

Database Script

The following creates an Oracle table.

<mktable.sql>

sqlplus scott/tiger << EOF
create table multi_sel
(
       seqno      VARCHAR(10),
       corpno     VARCHAR(10),
       compdate   VARCHAR(8),
       totmon     NUMERIC(38),
       guarat      FLOAT,
       guamon     FLOAT
);
create unique index idx_tdb on multi_sel(seqno);
EOF

The following outputs the Oracle table and data.

<sel.sql >

sqlplus scott/tiger << EOF
Desc multi_sel;
select * from multi_sel;
EOF
Client Program

The following is an example.

<conv_cli.c>

#include <stdio.h>
#include <usrinc/atmi.h>
#include "../sdl/demo.s"

main(int argc, char *argv[])
{
       struct sel_o *rcvbuf;
       char *sndbuf;
       long sndlen, rcvlen, revent;
       int cd;

       if (argc != 2) {
              printf("Usage: client string\n");
              exit(1);
       }

       /* connects to Tmax with tpstart() */
       if (tpstart((TPSTART_T *) NULL) == -1) {
              printf("tpstart failed\n");
              exit(1);
       }

       if ((sndbuf = tpalloc("STRING", NULL, 12)) == NULL) {
              printf("tpalloc failed:sndbuf\n");
              tpend();
              exit(1);
       }

       if ((rcvbuf = (struct sel_o *)tpalloc("STRUCT", "sel_o", 0)) == NULL) {
              printf("tpalloc failed:rcvbuf\n");
              tpfree(sndbuf);
              tpend();
              exit(1);
       }
       strcpy(sndbuf, argv[1]);

       if ((cd = tpconnect ("MULTI", sndbuf, 0, TPRECVONLY)) == -1){
              printf("tpconnect failed:CONVER service, tperrno=%d\n", tperrno);
              tpfree(sndbuf);
              tpfree((char *)rcvbuf);
              tpend();
              exit(1);
       }

     /* interactive communication connection, The interaction control is sent
         to a server. */
       printf("tpconnect SUCESS \"MULTI\" service\n");
       while ( 1 ) {    /* receives multiple data */
              printf("tprecv strat\n");
              if( tprecv(cd, (char **)&rcvbuf, &rcvlen, TPNOTIME, &revent) < 0 ) {
              /* If ends with tpreturn() in a server */
              if (revent == TPEV_SVCSUCC){
                     printf("all is completed\n");
                     break;
              }
              printf("tprecv failed, tperrno=%s, revent=%x\n",
              tpstrerror(tperrno), revent );
              tpfree(sndbuf);
              tpfree((char *)rcvbuf);
              tpend();
              exit(1);
       }
       printf("seqno = %s\t\t corpno =%s\n", rcvbuf->seqno, rcvbuf->corpno);
       printf("compdate = %s\t\t totmon =%d\n", rcvbuf->compdate, rcvbuf->totmon);
       printf("guarat = %f\t\t guamon =%f\n\n\n", rcvbuf->guarat, rcvbuf->guamon) ;
}
       tpfree(sndbuf);
       tpfree((char *)rcvbuf);
       tpend();
       printf("FINISH\n");
}
Server program

The following is an example.

<convsvc.pc>

#include <stdio.h>
#include <string.h>
#include <usrinc/atmi.h>
#include "../sdl/demo.s"

EXEC SQL begin declare section; /* Oracle global variables declaration */
       char seq[10];
       struct sel_o *sndbuf;
EXEC SQL end declare section;
EXEC SQL include sqlca;

MULTI(TPSVCINFO *msg)
{
       int i, cd;
       long sndlen, revent;

       memset(seq, 0, 10);
       strcpy(seq, msg->data);

       if ((sndbuf = (struct sel_o *) tpalloc ("STRUCT", "sel_o", 0)) == NULL) {
               printf("tpalloc failed:\n");
               tpreturn (TPFAIL, -1, NULL, 0, TPNOFLAGS);
       }

       /* declares a cursor for large amount of data */
       EXEC SQL declare democursor cursor for
       select *
       from corp
       where seqno > :seq;

       EXEC SQL open democursor;
       EXEC SQL whenever not found goto end_of_fetch;
       if (sqlca.sqlcode != 0){
              printf("oracle sqlerror=%s", sqlca.sqlerrm.sqlerrmc);
              tpreturn (TPFAIL, sqlca.sqlcode, NULL, 0, TPNOFLAGS);
       }

        /* sends data while there is no Oracle error */
       while ( sqlca.sqlcode == 0 ){
              EXEC SQL fetch democursor into :sndbuf;

              if (tpsend (msg->cd, (char *)sndbuf, 0, TPNOTIME, &revent) == -1){
                     printf("tpsend failed, tperrno=%d, revent=%x\n", tperrno,
                              revent ) ;
                     tpfree ((char *)sndbuf);
                     tpreturn (TPFAIL, -1, NULL, 0, TPNOFLAGS);
              }
       }

       tpreturn (TPFAIL, sqlca.sqlcode, NULL, 0, TPNOFLAGS);

       end_of_fetch:
       exec sql close democursor;
       printf("tpreturn before");
       tpreturn (TPSUCCESS, 0, NULL, 0, TPNOFLAGS);
}

2. Global Transaction Programs

A global transaction is when multiple resource managers (databases) and physical entities participate in processing one logical unit. Tmax regards all transactions as global transactions, and two-phase commit (2PC) is used for data integrity.

A client receives user input and sends a unique number and data through a struct buffer. A server updates any data that has the unique number and adds it to a table by calling a service that uses another database. If an error occurs, the client can simultaneously roll back both databases because the client specifies the whole process as a single transaction.

chap13 1
Connection to 2 Databases
Program Files
  • Common program

    File Description

    demo.s

    Struct buffer configuration file.

    sample.m

    Tmax configuration file.

    mktable.sql

    SQL script for creating a database table.

  • Client program

    File Description

    client.c

    Client program.

  • Server program

    File Description

    update.pc

    Server program that executes UPDATE for a database.

    insert.pc

    Server program that executes INSERT for a database.

    Makefile

    Tmax makefile that must be modified.

Program Feature
  • Client program

    Feature Description

    Tmax connection

    Basic connection.

    Buffer type

    STRUCT.

    Communication type

    Synchronous communication using tpcall().

    Transaction handling

    Transaction scope is specified by a client.

  • Server program

    Feature Description

    Server program

    2 server programs that use different databases.

    Service

    UPDATE, INSERT.

    Database connection

    2 types of Oracle databases.

Struct Buffer

The following example is a struct buffer used for global transactions.

<demo.s>

struct input {
       int account_id;
       int branch_id;
       char phone[15];
       char address[61];
};
Tmax Configuration File

The following is an example.

<sample.m>

*DOMAIN
res       SHMKEY=88000, MINCLH=1, MAXCLH=5, TPORTNO=8880, BLOCKTIME=60

*NODE
tmax1     TMAXDIR = "/user/ tmax ",
          APPDIR  = "/user/ tmax /appbin",
          PATHDIR = "/user/ tmax /path",
          TLOGDIR = "/user/ tmax /log/tlog",
          ULOGDIR="/user/ tmax /log/ulog",
          SLOGDIR="/user/ tmax /log/slog"

tmax2     TMAXDIR = "/user/ tmax ",
          APPDIR  = "/user/ tmax /appbin",
          PATHDIR = "/user/ tmax /path",
          TLOGDIR = "/user/ tmax /log/tlog",
          ULOGDIR="/user/ tmax /log/ulog",
          SLOGDIR="/user/ tmax /log/slog"


*SVRGROUP
svg1       NODENAME = tmax1, DBNAME = ORACLE,
           OPENINFO = "ORACLE_XA+Acc=P/scott/tiger+SesTm=60",
           TMSNAME = svg1_tms

svg2       NODENAME = tmax2, DBNAME = ORACLE,
           OPENINFO = "ORACLE_XA+Acc=P/scott/tiger+SesTm=60",
           TMSNAME = svg2_tms

*SERVER
update       SVGNAME=svg1
insert       SVGNAME=svg2

*SERVICE
UPDATE       SVRNAME=update
INSERT       SVRNAME=insert
Database Script

The following creates an Oracle table.

<mktable.sql>

sqlplus scott/tiger << EOF
drop table ACCOUNT;

create table ACCOUNT (
    ACCOUNT_ID  integer,
    BRANCH_ID   integer not null,
    SSN     char(13) not null,
    BALANCE     number,
    ACCT_TYPE   char(1),
    LAST_NAME   char(21),
    FIRST_NAME  char(21),
    MID_INIT    char(1),
    PHONE       char(15),
    ADDRESS     char(61),
    CONSTRAINT ACCOUNT_PK PRIMARY KEY(ACCOUNT_ID)
);
quit
EOF
Client Program

The following is an example.

<client.c >

#include <stdio.h>
#include <usrinc/atmi.h>
#include "../sdl/demo.s"

#define TEMP_PHONE "6283-2114"
#define TEMP_ADDRESS "Korea"

int main(int argc, char *argv[])
{
       struct input *sndbuf;
       char *rcvbuf;
       int acnt_id, n, timeout;
       long len;

       if (argc != 2) {
              fprintf(stderr, "Usage:%s account_id \n", argv[0]);
              exit(1);
       }

       acnt_id = atoi(argv[1]);
       timeout = 5;

       n = tmaxreadenv("tmax.env", "tmax");
       if (n < 0) {
              fprintf(stderr, "tmaxreadenv fail! tperrno = %d\n", tperrno);
              exit(1);
       }

       n = tpstart((TPSTART_T *)NULL);
       if (n < 0) {
              fprintf(stderr, "tpstart fail! tperrno = %s\n", tperrno);
              exit(1);
       }
       sndbuf = (struct input *)tpalloc("STRUCT", "input", sizeof(struct input));
       if (sndbuf == NULL) {
              fprintf(stderr, "tpalloc fail: sndbuf tperrno = %d\n", tperrno);
              tpend();
              exit(1);
       }
       rcvbuf = (char *)tpalloc("STRING", NULL, 0);
       if (rcvbuf == NULL) {
              fprintf(stderr, "tpalloc fail: rcvbuf tperrno = %d\n", tperrno);
              tpend();
              exit(1);
       }
       sndbuf->account_id = acnt_id;
       sndbuf->branch_id = acnt_id;
       strcpy(sndbuf ->phone, TEMP_PHONE);
       strcpy(sndbuf ->address, TEMP_ADDRESS);

       tx_set_transaction_timeout(timeout);
       n = tx_begin();
       if (n < 0)
              fprintf(stderr, "tx begin fail! tperrno = %d\n", tperrno);

       n = tpcall("UPDATE", (char *)sndbuf, sizeof(struct input),
                  (char **)&rcvbuf, (long *)&len, TPNOFLAGS);
       if (n < 0) {
              fprintf(stderr, "tpcall fail! tperrno = %d\n", tperrno);
              tpend();
              exit(1);
       }

       n = tx_commit();
       if (n < 0) {
              fprintf(stderr, "tx commit fail! tx error = %d \n", n);
              tx_rollback();
              tpend();
              exit(1);
       }
       printf("rtn msg = %s\n", rcvbuf);
       tpfree((char *)sndbuf);
       tpfree((char *)rcvbuf);
       tpend();
}
Server program

The following example is a server program that executes UPDATE for a database.

<update.pc>

#include <stdio.h>
#include <ctype.h>
#include <usrinc/atmi.h>
#include <usrinc/sdl.h>
#include "../sdl/demo.s"

#define OKMSG "YOU COMPLETE THE TRANSACTION"

EXEC SQL include sqlca.h;
EXEC SQL BEGIN DECLARE SECTION;
int account_id;
    int     branch_id;
    char    ssn[15];
    char    phone[15];
    char    address[61];
EXEC SQL END DECLARE SECTION;

UPDATE(TPSVCINFO *msg)
{
    struct input *rcvbuf;
    int     ret;
    long    acnt_id, rcvlen;
    char    *send;

    rcvbuf = (struct input *)(msg->data);
    send = (char *)tpalloc("STRING", NULL, 0);
    if (send == NULL) {
       fprintf(stderr, "tpalloc fail errno = %s\n", strerror(tperrno));
       tpreturn(TPFAIL, 0, (char *)NULL, 0, 0);
    }
    account_id = rcvbuf->account_id;
    branch_id = rcvbuf->branch_id;
    strcpy(phone, rcvbuf->phone);
    strcpy(address, rcvbuf->address);
    strcpy(ssn, "1234567");

    EXEC SQL UPDATE ACCOUNT
                SET BRANCH_ID = :branch_id,
                    PHONE = :phone,
                    ADDRESS = :address,
                    SSN = :ssn
              WHERE ACCOUNT_ID = :account_id;
    if (sqlca.sqlcode != 0 && sqlca.sqlcode != 1403 ) {
        fprintf(stderr, "update failed sqlcode = %d\n", sqlca.sqlcode);
        tpreturn(TPFAIL, -1, (char *)NULL, 0, 0);
    }
    rcvbuf->account_id++;
    ret = tpcall("INSERT", (char *)rcvbuf, 0, (char **)&send, (long *)&rcvlen,
                 TPNOFLAGS);
    if (ret < 0) {
        fprintf(stderr, "tpcall fail tperrno = %d\n", tperrno);
        tpreturn(TPFAIL, -1, (char *)NULL, 0, 0);
    }
    strcpy(send, OKMSG);
    tpreturn(TPSUCCESS, 1, (char *)send, strlen(send), TPNOFLAGS);
}

The following example is a server program that executes INSERT for a database.

<insert.pc>

#include <stdio.h>
#include <ctype.h>
#include <usrinc/atmi.h>
#include <usrinc/sdl.h>
#include "../sdl/demo.s"

#define OKMSG "YOU COMPLETE THE TRANSACTION"

EXEC SQL include sqlca.h;
EXEC SQL BEGIN DECLARE SECTION;
    int     account_id;
    int     branch_id;
    char    ssn[15];
    char    phone[15];
    char    address[61];
EXEC SQL END DECLARE SECTION;

INSERT(msg)
TPSVCINFO  *msg;
{
    struct input *rcvbuf;
    int     ret;
    long    acnt_id;
    char    *send;

    rcvbuf = (struct input *)(msg->data);
    send = (char *)tpalloc("STRING", NULL, 0);
    if (send == NULL) {
        fprintf(stderr, "tpalloc fail errno = %s\n", tpstrerror(tperrno));
        tpreturn(TPFAIL, 0, (char *)NULL, 0, TPNOFLAGS);
    }

    account_id = rcvbuf->account_id;
    branch_id = rcvbuf->branch_id;
    strcpy(phone, rcvbuf->phone);
    strcpy(address, rcvbuf->address);
    strcpy(ssn, "1234567");

    /*  Declare && Open Cursor for Fetch */
    EXEC SQL INSERT INTO ACCOUNT (
    ACCOUNT_ID,
    BRANCH_ID,
    SSN,
    PHONE,
    ADDRESS )
    VALUES (
    :account_id, :branch_id, :ssn, :phone, :address);

    if (sqlca.sqlcode != 0 && sqlca.sqlcode != 1403 )
    {
        printf("insert failed sqlcode = %d\n", sqlca.sqlcode);
        tpreturn(TPFAIL, -1, (char *)NULL, 0, TPNOFLAGS);
    }
    strcpy(send, OKMSG);
    tpreturn(TPSUCCESS, 1, (char *)send, strlen(send), TPNOFLAGS);
}

3. Database Programs

This section describes several examples that illustrate the use of Oracle and Informix databases.

3.1. Oracle Insert Program

A client receives user input and calls a service through a struct buffer. A server receives the input and adds it to a corresponding table. If an error occurs, a client can roll back the database by specifying the process as a single transaction.

Program Files
  • Common program

    File Description

    demo.s

    Struct buffer configuration file.

    sample.m

    Tmax configuration file.

    mktable.sql

    SQL script for creating a database table.

    sel.sql

    Script for outputting tables and data.

  • Client program

    File Description

    oins_cli.c

    Client program.

  • Server program

    File Description

    oinssvc.pc

    Oracle source of a service program.

    Makefile

    Tmax makefile that must be modified.

Program Feature
  • Client program

    Feature Description

    Tmax connection

    Basic connection.

    Buffer type

    STRUCT.

    Communication type

    Synchronous communication using tpcall().

    Transaction handling

    Transaction scope is specified by a client.

  • Server program

    Feature Description

    Service

    ORAINS.

    Database connection

    Oracle database.

Struct Buffer

The following is an example.

<demo.s>

struct ktran {
    int no;
    char name[20];
};
Tmax Configuration File

The following is an example.

<sample.m>

*DOMAIN
resrc             SHMKEY = 77990, MAXUSER = 256

*NODE
tmax              TMAXDIR = /home/tmax,
                  APPDIR = /home/tmax/appbin,
                  PATHDIR = /home/tmax/path

*SVRGROUP
svg1              NODENAME = tmax,
                  DBNAME = ORACLE,
                  OPENINFO = "Oracle_XA+Acc=P/scott/tiger+SesTm=60",
                  TMSNAME = svg1_tms

*SERVER
oinssvc           SVGNAME = svg1, MIN = 1, MAX = 5

*SERVICE
ORAINS            SVRNAME = oinssvc

The following items are added.

Item Description

DBNAME

Database name.

OPENINFO

Oracle database connection information. CLOSEINFO does not need to be specified for an Oracle database because It is called by tpsvrinfo().

TMSNAME

Name of the process that handles automatic transactions that meet OPENINFO. The service included in svg1 is handled as automatic transitions.

Database Script

The following creates an Oracle table.

<mktable.sql>

sqlplus scott/tiger << EOF
       create table testdb1 (
       no number(7),
       name char(30)
) ;
EOF

The following outputs the Oracle table and data.

<sel.sql>

sqlpus scott/tiger << EOF
desc testdb1;
select * from testdb1;
select count (*) from testdb1;
EOF
Client Program

The following is an example.

<oins_cli.c>

#include <stdio.h>
#include <usrinc/atmi.h>
#include "../sdl/demo.s"

main(int argc, char *argv[])
{
       struct ktran *sndbuf, *rcvbuf;
       long sndlen, rcvlen;
       int cd;

       if (argc != 3) {
       printf("Usage: client no name\n");
              exit(1);
       }

       printf("tpstart-start \n");
       if(tpstart ((TPSTART_T *) NULL) == -1) {
              printf("Tpstart failed\n");
              exit(1);
       }
       printf("tpstart-ok \n");

       if((sndbuf=(struct ktran *) tpalloc("STRUCT","ktran",0))==NULL) {
            printf("tpalloc failed:sndbuf, tperrno=%d\n", tperrno);
            tpend();
            exit(1) ;
        }

        if((rcvbuf = (struct ktran *) tpalloc("STRUCT", "ktran", 0))== NULL) {
             printf("tpalloc failed:rcvbuf, tperrno=%d\n", tperrno);
             tpfree((char *)sndbuf);
             tpend();
             exit(1);
        }

       sndbuf->no = atoi(argv[1]);
       strcpy(sndbuf->name, argv[2]);
       printf("tpcall-start \n");
       tx_begin();

       if(tpcall("ORAINS",(char *)sndbuf,0,(char **)&rcvbuf,&rcvlen,TPNOFLAGS)==-1)
       {
            printf("tpcall failed:ORA service, tperrno=%d", tperrno);
            printf("sql code=%d\n", tpurcode);
            tx_rollback();
            tpfree ((char *)sndbuf);
            tpfree ((char *)rcvbuf);
            tpend();
            exit(1);
       }

       printf("tpcall-success \n");
       tx_commit();

       tpfree ((char *)sndbuf);
       tpfree ((char *)rcvbuf);
       tpend();
}
Server program

The following is an example.

<oinssvc.pc>

#include <stdio.h>
#include <usrinc/atmi.h>
#include "../sdl/demo.s"

EXEC SQL begin declare section;
char name[20];
int no;

EXEC SQL end declare section;
EXEC SQL include sqlca;

ORAINS(TPSVCINFO *msg)
{
       struct ktran *stdata;
        stdata = (struct ktran *)msg->data;
        strcpy(name, stdata->name);
        no = stdata->no;
        printf("Ora service started\n");

       /* inserts to a database */
       EXEC SQL insert into testdb1(no, name) values(:no, :name);

       if (sqlca.sqlcode != 0){
             printf("oracle sqlerror=%s",sqlca.sqlerrm.sqlerrmc);
             tpreturn (TPFAIL, sqlca.sqlcode, NULL, 0, TPNOFLAGS);
        }

       tpreturn (TPSUCCESS, sqlca.sqlcode, stdata, 0, TPNOFLAGS);
}

3.2. Oracle Select Program

A client receives user input and calls a service through a struct buffer. A server receives all corresponding data and returns it using a structure array. If an error occurs, a client can roll back the database by specifying the process as a single transaction.

Program Files
  • Common program

    File Description

    demo.s

    Struct buffer configuration file.

    sample.m

    Tmax configuration file.

    mktable.sql

    SQL script for creating a database table.

    sel.sql

    Script for outputting tables and data.

  • Client program

    File Description

    oins_cli.c

    Client program.

    cdata.c

    Function module used by a client.

  • Server program

    File Description

    oselsvc.pc

    Oracle source of a service program.

    Makefile

    Tmax makefile that must be modified.

Program Feature
  • Client program

    Feature Description

    Tmax connection

    Basic connection.

    Service

    ORASEL.

    Buffer type

    STRUCT.

    Communication type

    Synchronous communication using tpcall().

    Transaction handling

    Transaction scope is specified by a client.

  • Server program

    Feature Description

    Service

    ORASEL.

    Database connection

    Oracle database.

    Buffer usage

    Buffer size can be changed if necessary.

Struct Buffer

The following is an example.

<demo.s>

struct stru_his{
       long    ACCOUNT_ID ;
       long    TELLER_ID ;
       long    BRANCH_ID ;
       long    AMOUNT ;
} ;
Tmax Configuration File

The following is an example.

<sample.m>

*DOMAIN
resrc             SHMKEY = 77990, MAXUSER = 256

*NODE
tmax              TMAXDIR ="/home/tmax",
                  APPDIR ="/home/tmax/appbin",
                  PATHDIR ="/home/tmax/path"

*SVRGROUP
svg1              NODENAME = tmax,
                  DBNAME = ORACLE,
                  OPENINFO = "Oracle_XA+Acc=P/scott/tiger+SesTm=600",
                  TMSNAME = svg1_tms

*SERVER
oselsvc           SVGNAME = svg1, MIN = 1, MAX = 5

*SERVICE
ORASEL            SVRNAME = oselsvc

The following items are added.

Item Description

DBNAME

Database name.

OPENINFO

Oracle database connection information. CLOSEINFO does not need to be specified for an Oracle database. Available options are described in the following table.

TMSNAME

Name of the process that handles transactions.

AUTOTRAN

Corresponding service is automatically processed in transaction status.

The following options are available for OPENINFO.

Option Description

LogDir

Records XA-related log in a specified location.

If unspecified, the <xa_NULLdate.trc> file is created in $ORACLE_HOME/rdbms/log or a current directory.

DbgFl

Level of the debug flag. 0x01 (basic level), 0x04 (OCI level), and other levels can be used.

The following uses the LogDir and DbgFl options for OPENINFO.

OPENINFO="Oracle_XA+Acc=P/account/password +SesTm=60+LogDir=/tmp+DbgFl=0x01"

To avoid disk full issues, disalbe the degug mode during development.

Database Script

The following creates an Oracle table.

<mktable.sql>

sqlplus scott/tiger << EOF
       create table sel_his(
       account_id number(6),
       teller_id number(6),
       branch_id number(6),
       amount number(6)
);
create unique index idx_tdb1 on sel_his(account_id);
EOF

The following outputs the Oracle table and data.

<sel.sql>

sqlplus scott/tiger << EOF
desc sel_his;
select * from sel_his;
EOF
Client Program

The following is an example.

<oins_cli.c>

#include <stdio.h>
#include <usrinc/atmi.h>
#include <usrinc/tx.h>
#include "../sdl/demo.s"
#define NARRAY 10
#define NOTFOUND 1403

main(int argc,char *argv[])
{
       struct stru_his *transf;
       int i, j;
       long urcode, nrecv, narray = NARRAY;
       long account_id, teller_id, branch_id, amount;

       if (argc != 2) {
              fprintf(stderr,"Usage:$%s ACOUNT_ID !\n", argv[0]);
              exit(0);
       }

       if (tpstart((TPSTART_T *) NULL) == -1) {    /* connects to Tmax */
           fprintf(stderr,"TPSTART_T(tpinfo) failed -> %s!\n",
           tpstrerror(tperrno)) ;
           exit(1) ;
       }

       /* creates a c struct buffer */
       transf = (struct stru_his *) tpalloc("STRUCT", "stru_his",0);
       if (transf == (struct stru_his *)NULL) {
              fprintf(stderr,"Tpalloc failed->%s!\n",
              tpstrerror(tperrno)) ;
              tpend();
              exit(1);
       }
       memset(transf, 0x00, sizeof(struct stru_his));

       account_id = atoi(argv[1]);
       transf->ACCOUNT_ID = account_id;

       /* sets transaction timeout */
       tx_set_transaction_timeout(30);

       /* starts global transactions */
       if (tx_begin() < 0) {
              fprintf(stderr, "tx_begin() failed ->%s!\n",
              tpstrerror(tperrno));
              tpfree((char*)transf);
              tpend();
              exit(0) ;
       }

       if (tpcall("ORASEL",(char *)transf, 0, (char **)&transf, &nrecv,
                  TPNOFLAGS)== -1){
              /* request the"ORASEL" service with synchronous communication */
              fprintf(stderr,"Tpcall(SELECT...)error->%s ! ",
              tpstrerror(tperrno)) ;
              tpfree((char *)transf);
              /* cancels a transaction if failed */
              tx_rollback();
              tpend();
              exit(0) ;
       }
       /* commits a transaction if successful */
       if (tx_commit() == -1) {
              fprintf(stderr, "tx_commit() failed ->%s!\n",
              tpstrerror(tperrno)) ;
              tpfree((char *)transf);
                     tpend();
                     exit(0) ;
       }
        /* Received data is an array of a structure. */
       for (j =0 ; j < tpurcode ; j++) {
           /* prints data selected by Oracle */
          if (j == 0)
              printf("%-12s%-10s%-10s%-10s\n",
                   "ACCOUNT_ID","TELLER_ID", "BRANCH_ID", "AMOUNT");
              account_id=transf[j].ACCOUNT_ID;
              teller_id=transf[j].TELLER_ID;
              branch_id=(*(transf+j)).BRANCH_ID;
              amount=transf[j].AMOUNT;
              printf("%-12d %-10d %-10d %-10d\n", account_id,
                       teller_id,branch_id, amount);
       }
       /* if there is not selected data or it is the end */
       if (urcode == NOTFOUND) {
       printf("No records selected!\n");
              tpfree((char *)transf);
              tpend();
              return 0;
}
       tpfree((char *)transf);
       tpend();
}
Server program

The following is an example.

<oselsvc.pc>

#include <stdio.h>
#include <usrinc/atmi.h>
#include "../sdl/demo.s"
#define NARRAY 10
#define TOOMANY 2112
#define NOTFOUND 1403
EXEC SQL include sqlca.h;

EXEC SQL begin declare section;
       long key, rowno= NARRAY;
       long account_id[NARRAY],teller_id[NARRAY], branch_id[NARRAY],
       amount[NARRAY] ;
EXEC SQL end declare section;

ORASEL(TPSVCINFO *msg)
{
       struct stru_his *transf;
       int i , lastno;
       transf=(struct stru_his *) msg->data;

       /* transfers contents of the msg buffer to a program variable */
       key = transf->ACCOUNT_ID;

        /* adjusts the size of the transf buffer */
       if((transf=(struct stru_his *) tprealloc((char*)transf,
           sizeof(struct stru_his) * NARRAY ))==(struct stru_his*)NULL){
              fprintf(stderr, "tprealloc error ->%s\n",
              tpstrerror(tperrno));
              tpreturn(TPFAIL, tperrno, NULL, 0, TPNOFLAGS);
       }
       EXEC SQL select account_id, teller_id, branch_id, amount
                  into :account_id, :teller_id, :branch_id, :amount  from sel_his
                 where account_id > :key
              /* puts data that has account_id greater than the key value sent */
              order by account_id;       /* by a client to a global variable */

       /* sql error check (excludes no data or too many data) */
       if (sqlca.sqlcode!=0 && sqlca.sqlcode!=NOTFOUND && sqlca.sqlcode!=TOOMANY) {
              fprintf(stderr,"SQL ERROR ->NO(%d):%s\n", sqlca.sqlcode,
              sqlca.sqlerrm.sqlerrmc) ;
              tpreturn(TPFAIL, sqlca.sqlcode, NULL, 0, TPNOFLAGS);
       }

       /* puts the number of access to lastno */
       lastno = sqlca.sqlerrd[2];

       /* too many selected data */
       if (sqlca.sqlcode == TOOMANY)
              lastno =rowno;

       /* No records */
       if (lastno == 0)
              transf->ACCOUNT_ID = 0;

        /* puts data selected by Oracle to a buffer to be sent */
        for ( i = 0 ; i < lastno; i++) {
              transf[i].ACCOUNT_ID = account_id[i];
              transf[i].TELLER_ID = teller_id[i];
              transf[i].BRANCH_ID = branch_id[i];
              transf[i].AMOUNT = amount[i];
       }
       tpreturn(TPSUCCESS, lastno, transf, i * sizeof(struct stru_his),
       TPNOFLAGS );
}

3.3. Informix Insert Program

A client receives user input and calls a service through a struct buffer. A server receives the input and adds it to a corresponding table. A client can roll back by specifying the process as a single transaction when an error occurs.

Check the following before compiling Informix applications.

  1. Unix environment (.profile, .login, and .cshrc)

    Set the following items.

    INFORMIXDIR=/home/informix
    INFORMIXSERVER=tmax
    ONCONFIG=onconfig
    PATH=$INFORMIXDIR/bin: …
    LD_LIBRARY_PATH=/home/informix/lib:/home/informix/lib/esql:
    …
  2. Makefile

    Check the following operations and settings.

    # Server esql makefile
    
    TARGET  = <target filename>
    APOBJS  = $(TARGET).o
    SDLFILE = info.s
    
    LIBS    = -lsvr -linfs
    # For Solaris, add –lnsl –lsocket.
    
    OBJS    = $(APOBJS) $(SDLOBJ) $(SVCTOBJ)
    SDLOBJ  = ${SDLFILE:.s=_sdl.o}
    SDLC    = ${SDLFILE:.s=_sdl.c}
    SVCTOBJ = $(TARGET)_svctab.o
    
    CFLAGS =-O -I$(INFORMIXDIR)/incl/esql -I$(TMAXDIR)
    # Solaris 32bit, Compaq, Linux: CFLAGS = -O -I$(INFORMIXDIR)/incl/esql
                                             –I$(TMAXDIR)
    # Solaris 64bit: CFLAGS = -xarch=v9 -O -I$(INFORMIXDIR)/incl/esql –I$(TMAXDIR)
    # HP 32bit: CFLAGS = -Ae -O -I$(INFORMIXDIR)/incl/esql –I$(TMAXDIR)
    # HP 64bit: CFLAGS = -Ae +DA2.0W +DD64 +DS2.0 -O -I$(INFORMIXDIR)/incl/esql
                         –I$(TMAXDIR)
    # IBM 32bit: CFLAGS = -q32 –brtl -O -I$(INFORMIXDIR)/incl/esql –I$(TMAXDIR)
    # IBM 64bit: CFLAGS = -q64 –brtl -O -I$(INFORMIXDIR)/incl/esql –I$(TMAXDIR)
    
    INFLIBD = $(INFORMIXDIR)/lib/esql
    INFLIBDD = $(INFORMIXDIR)/lib
    INFLIBS = -lifsql -lifasf -lifgen -lifos -lifgls -lm -ldl -lcrypt
               $(INFORMIXDIR)/lib/esql/
    checkapi.o -lifglx -lifxa
    
    APPDIR  = $(TMAXDIR)/appbin
    SVCTDIR = $(TMAXDIR)/svct
    TMAXLIBDIR  = $(TMAXDIR)/lib
    
    #
    .SUFFIXES : .ec .s .c .o
    
    .ec.c :
            esql -e $*.ec
    
    #
    # server compile
    #
    all: $(TARGET)
    
    $(TARGET):$(OBJS)
            $(CC) $(CFLAGS) -L$(TMAXLIBDIR) -L$(INFLIBD) -L$(INFLIBDD) -o $(TARGET)
            $(OBJS) $(LIBS) $(INFLIBS)
            mv $(TARGET) $(APPDIR)/.
            rm -f $(OBJS)
    
    $(APOBJS): $(TARGET).ec
            esql -e -I$(TMAXDIR)/usrinc $(TARGET).ec
            $(CC) $(CFLAGS) -c $(TARGET).c
    
    $(SVCTOBJ):
            touch $(SVCTDIR)/$(TARGET)_svctab.c
            $(CC) $(CFLAGS) -c $(SVCTDIR)/$(TARGET)_svctab.c
    
    $(SDLOBJ):
            $(TMAXDIR)/bin/sdlc -i ../sdl/$(SDLFILE)
            $(CC) $(CFLAGS) -c ../sdl/$(SDLC)
    
    #
    clean:
    -rm -f *.o core $(TARGET) $(TARGET).lis

    <TMS Makefile>

    #
    TARGET  = info_tms
    
    INFOLIBDIR = ${INFORMIXDIR}/lib
    INFOELIBDIR = ${INFORMIXDIR}/esql
    INFOLIBD = ${INFORMIXDIR}/lib/esql
    INFOLIBS = -lifsql -lifasf -lifgen -lifos -lifgls -lm -ldl -lcrypt
               /opt/informix/lib/esql/checkapi.o
     -lifglx -lifxa
    # For Solaris, add –lnsl –lsocket –laio –lelf
    
    CFLAGS =-O -I$(INFORMIXDIR)/incl/esql -I$(TMAXDIR)
    # Solaris 32bit, Compaq, Linux: CFLAGS = -O -I$(INFORMIXDIR)/incl/esql
                                             –I$(TMAXDIR)
    # Solaris 64bit: CFLAGS = -xarch=v9 -O -I$(INFORMIXDIR)/incl/esql –I$(TMAXDIR)
    # HP 32bit: CFLAGS = -Ae -O -I$(INFORMIXDIR)/incl/esql –I$(TMAXDIR)
    # HP 64bit: CFLAGS = -Ae +DA2.0W +DD64 +DS2.0 -O -I$(INFORMIXDIR)/incl/esql
                         –I$(TMAXDIR)
    # IBM 32bit: CFLAGS = -q32 –brtl -O -I$(INFORMIXDIR)/incl/esql –I$(TMAXDIR
    # IBM 64bit: CFLAGS = -q64 –brtl -O -I$(INFORMIXDIR)/incl/esql –I$(TMAXDIR
    
    TMAXLIBDIR = $(TMAXDIR)/lib
    TMAXLIBS  = -ltms -linfs
    # CC = /opt/SUNWspro/bin/cc : solaris only
    
    
    $(TARGET): $(APOBJ)
            $(CC) $(CFLAGS) -o $(TARGET) -L$(TMAXLIBDIR) -L$(INFOLIBD)
            -L$(INFOLIBDIR) -L
    $(INFOELIBDIR) $(INFOLIBS) $(TMAXLIBS)
            mv $(TARGET) $(TMAXDIR)/appbin
    
    #
    clean:
            -rm -f  *.o core $(TARGET)
Program Files
  • Common program

    File Description

    demo.s

    Struct buffer configuration file.

    sample.m

    Tmax configuration file.

    mkdb.sql

    SQL script for creating a database. XA mode is supported when a database is created in logging mode.

    mktable.sql

    SQL script for creating a database table.

    sel.sql

    Script for outputting tables and data.

    info.s

    SDLFILE.

  • Client program

    File Description

    client.c

    Client program.

  • Server program

    File Description

    tdbsvr.ec

    Server program.

    Makefile

    Modifies the Makefile provided by Tmax.

Program Feature
  • Client program

    Feature Description

    Tmax connection

    Basic connection.

    Buffer type

    STRUCT.

    Communication type

    Synchronous communication using tpcall().

    Transaction handling

    Transaction scope is specified by a client.

  • Server program

    Feature Description

    Service

    INSERT.

    Database connection

    Informix database.

Struct Buffer

The following is an example.

<demo.s>

struct info {
     char seq[8];
     char data01[128];
     char data02[128];
     char data03[128];
};
Tmax Configuration File

The following is an example.

<sample.m>

*DOMAIN
resrc            SHMKEY = 77990, MAXUSER = 256

*NODE
tmax             TMAXDIR ="/home/tmax", A
                 APPDIR ="/home/tmax/appbin",
                 PATHDIR ="/home/tmax/path"

*SVRGROUP
svg1             NODENAME = tmax,
                 DBNAME = INFORMIX,
                 OPENINFO = "stores7",
                 CLOSEINFO = "",
                 TMSNAME = info_tms

*SERVER
tdbsvr          SVGNAME = svg1, MIN = 1, MAX = 5

*SERVICE
INSERT         SVRNAME = tdbsvr

The following items are added.

Item Description

DBNAME

Database name.

OPENINFO, CLOSEINFO

Informix database connection and disconnection information. tpsvrinfo() and tpsvrdone() use the information.

TMSNAME

Name of the process that handles transactions. Automatic transactions that become available due to OPENINFO are handled. The corresponding service included in svg1 is handled in the automatic transaction state.

Database Script

The following creates an Informix table.

<mktable.sql>

dbaccess << EOF
create database stores7 with buffered log;
grant connect to public;

database stores7;
drop table testdb1;
create table testdb1 (
        seq        VARCHAR(8) ,
        data01     VARCHAR(120) ,
        data02     VARCHAR(120) ,
        data03     VARCHAR(120)
) lock mode row;

create unique index idx_tdb1 on testdb1(seq);
EOF

The following outputs the Informix table and data.

<sel.sql>

dbaccess << EOF
database stores7;
select * from testdb1;
EOF
Client Program

The following is an example.

<client.c>

#include <stdio.h>
#include <usrinc/atmi.h>
#include <usrinc/tx.h>
#include "info.s"
main(int argc, char **argv)
{
       struct info *transf;
       char data[256];
       long nrecv;

       /* connects to Tmax */
       if ((tpstart((TPSTART_T *)NULL) == -1) {
            fprintf(stderr, "tpstart(TPINFO...) failed ->%s!\n",
            tpstrerror(tperrno)) ;
            exit(1) ;
       }

      /* allocates buffer memory to be used in an application program */
     if ((transf=(struct info *)tpalloc ("STRUCT","info",0))==(struct info *)NULL){
          fprintf(stderr, "tpalloc(struct info, ...) failed ->%s!\n",
          tpstrerror(tperrno)) ;
          tpend();
          exit(1) ;
       }

       /* fills the data fields to be transferred */
       strcpy(transf->seq, "000001");
       strcpy(transf->data01, "Hello");
       strcpy(transf->data02, "World");
       strcpy(transf->data03, "1234");

        /* sets transaction timeout * /
       tx_set_transaction_timeout (30);

       /* informs of transaction starts */
       if (tx_begin() < 0) {
              fprintf(stderr, "tx_begin() failed ->%s!\n",
              tpstrerror(tperrno)) ;
              tpfree ((char *)transf);
              tpend( ); exit(0);
       }

       /* calls a service */
     if (tpcall("INSERT",(char*) transf,0,(char **)&transf,&nrecv,TPNOFLAGS)==-1){
         fprintf(stderr,"tpcall(struct info, ...)
         failed ->%s!\n",tpstrerror(tperrno)) ;
         tx_rollback ();
         tpfree ((char *)transf),
         tpend();
          exit(0);
       }

      /* Transactions are complete. */
     if (tx_commit () < 0) {
          fprintf(stderr, "tx_commit() failed ->%s!\n", tpstrerror(tperrno)) ;
          tpfree ((char *)transf);
          tpend( );
          exit(0);
       }

       tpfree ((char *)transf );
       /* disconnects from Tmax */
       tpend( ) ;
}
Server program

The following is an example.

< tdbsvr.ec>

#include <stdio.h>
#include <ctype.h>
#include <usrinc/atmi.h>
#include "info.s"

EXEC SQL include sqlca.h;

/* a service name */
INSERT(TPSVCINFO *msg)
{
      /* declares a buffer type for the program */
      struct info *INFO;

       /* declares a buffer type for SQL statements */
       EXEC SQL begin declare section;
       varchar seq[8],buf01[128],buf02[128],buf03[128];
       EXEC SQL end declare section;

       /* receives data in a structure format from the message buffer */
       INFO = (struct info *)msg -> data;

       /* copies data received in a structure format to a database buffer */
       strcpy(seq, INFO->seq);
       strcpy(buf01, INFO->data01);
       strcpy(buf02, INFO->data02);
       strcpy(buf03, INFO->data03);

      /* performs an Insert SQL statement */
       EXEC SQL insert into testdb1 (seq,data01,data02,data03)
       values(:seq, :buf01, :buf02, :buf03);

      /* if an error occurs */
       if ( sqlca.sqlcode ! = 0)  {
             /* informs Insert is failed */
              printf("SQL error => %d !" ,sqlca.sqlcode);
              tpreturn (TPFAIL, sqlca.sqlcode, NULL, 0, TPNOFLAGS);
       }

       /* when Insert successfully completes */
       tpreturn (TPSUCCESS, 0, NULL, 0, TPNOFLAGS);
}

3.4. Informix Select Program

A client receives user input and calls a service through a struct buffer. A server receives all corresponding data and returns it using a structure array. If an error occurs, a client can roll back the database by specifying the process as a single transaction.

Program Files
  • Common program

    File Description

    acct.s

    SDLFILE.

    sample.m

    Tmax configuration file.

    mkdb.sql

    SQL script for creating a database.

    mktables.sql

    SQL script for creating a database table.

    sel.sql

    Script for outputting tables and data.

  • Client program

    File Description

    client.c

    Client program.

    cdate.c

    Function module used by client.c.

  • Server program

    File Description

    sel_acct.ec

    Informix source of a service program.

    Makefile

    Tmax makefile that must be modified.

Program Feature
  • Client program

    Feature Description

    Tmax connection

    Basic connection.

    Buffer type

    STRUCT.

    Communication type

    Synchronous communication using tpcall().

    Transaction handling

    Transaction scope is specified by a client.

  • Server program

    Feature Description

    Service

    SEL_ACCT.

    Database connection

    Informix database.

    Buffer usage

    A buffer can be resized if necessary.

Struct Buffer

The following is an example.

<acct.s>

struct stru_acct {
    int  ACCOUNT_ID;
    char PHONE[20];
    char ADDRESS[80];
};
Tmax Configuration File

The following is an example.

<sample.m>

*DOMAIN
resrc         SHMKEY = 77990, MAXUSER = 256

*NODE
tmax          TMAXDIR ="/home/tmax",
              APPDIR ="/home/tmax/appbin",
              PATHDIR ="/home/tmax/path"

*SVRGROUP
svg1          NODENAME = tmax,
              DBNAME = INFORMIX,
              OPENINFO = "stores7",
              CLOSEINFO = "",
              TMSNAME = info_tms
*SERVER
SEL_ACCT      SVGNAME = svg1, MIN = 1, MAX = 5

*SERVICE
SEL_ACCT      SVRNAME = sel_acct

The following items are added.

Item Description

DBNAME

Database name.

OPENINFO, CLOSEINFO

Informix database connection and disconnection information. tpsvrinfo() and tpsvrdone() use the information.

TMSNAME

Name of the process that handles transactions. Automatic transactions appointed by OPENINFO are handled. The corresponding service included in svg1 is handled in automatic transaction status.

Database Script

The following creates an Informix table.

<mkdb.sql>

dbaccess << EOF
create database stores7 with buffered log;
grant connect to public;

database stores7;
drop table ACCOUNT;

create table ACCOUNT (
       account_id INTEGER,
       phone VARCHAR(20),
       address VARCHAR(80)
) lock mode row;

create unique index idx_tdb1 on ACCOUNT(account_id);
EOF

The following outputs the Informix table and data.

<sel.sql>

dbaccess << EOF
database stores7;
select * from ACCOUNT;
EOF
Client Program

The following is an example.

<client.c>

#include <stdio.h>
#include <time.h>
#include <usrinc/atmi.h>
#include <usrinc/tx.h>
#include "acct.s"
#define NOTFOUND 1403

void htime(char *, int *);

main(int argc, char *argv[ ])
{
       struct stru_acct *transf;
       float tps;
       int i, j, loop, cnt_data = 0, sec1, sec2;
       long urcode, nrecv, narray;
       char ts[30], te[30], phone[20], address[80];
       int account_id, key;

       if(argc != 2) {
          fprintf(stderr,"Usage:$%sLOOP (NARRAY = 30) !\n", argv[0]);
          exit(0) ;
       }

       /* repeats the loop as many as times a user wants */
       loop = atoi(argv[1]);

        /* connects to Tmax */
       if (tpstart((TPSTART_T *)NULL) == -1) {
           fprintf(stderr, "tpstart(tpinfo) failed ->%s!\n",
           tpstrerror(tperrno));
           exit(1) ;
       }

      /* sec1 = start time */
       htime(ts,&sec1); key=0;

      /* allocates a message buffer */
     for( i = 0; i < loop; i++) {
         if ((transf=(struct stru_acct *)tpalloc("STRUCT","stru_acct",0))
                ==(struct stru_acct *)NULL) {
               fprintf(stderr,"Tpalloc(STRUCT.. )failed->%s!\n" ,
               tpstrerror(tperrno)) ;
                tpend(); exit(1);
              }
         transf -> ACCOUNT_ID = key;

         /* time-out value= 30 */
         tx_set_transaction_timeout(30) ;

         if (tx_begin() < 0) { /* starts transactions */
              fprintf(stderr, "tx_begin() failed ->%s!\n", tpstrerror(tperrno)) ;
              tpfree((char*)transf);
              tpend();
              exit(0);
         }

       /* calls a select service */
       if (tpcall("SEL_ACCT", (char *)transf, 0, (char **)&transf, &nrecv,
           TPNOFLAGS)== -1) {
           /* service error: the message buffer is freed, the transaction is
                             cancelled, and the connection is terminated */
            fprintf(stderr,"Tpcall(SELECT...)error->%s! " ,
                      tpstrerror(tperrno)) ;
            tpfree ((char *)transf);
            tx_rollback ( ) ;
            tpend( ) ;
            exit ( 1 ) ;
       }
       urcode = tpurcode;

      /* The service is successfully completed.
         The actual resource is changed as a result of the transaction */
       if (tx_commit() < 0 ) {
              fprintf(stderr, "tx_commit() failed ->%s!\n", tpstrerror(tperrno)) ;
              tpfree((char *)transf);
              tpend();
              exit(0);
       }

      /* if data is selected */
      if ( urcode != NOTFOUND) {
           narray =urcode;
           /* the last record of selected data */
           key=transf[narray-1].ACCOUNT_ID;
          /* outputs results to a user as many as the number of selected data */
          for ( j = 0 ; j < narray ; j++ ) {
               if ( j == 0)
                   printf("%-10s%-14s%s\n", "ACCOUNT_ID", "PHONE","ADDRESS") ;
                   account_id = transf[j].ACCOUNT_ID;
                   strcpy(phone, transf[j].PHONE);
                   strcpy(address, transf[j].ADDRESS);
                   printf("%-10d %-14s %s\n", account_id, phone, address);
            }/* for2 end */

           /* increases the number of results */
           cnt_data += j;

           /* message buffer free */
           tpfree ((char *)transf);
            if(urcode == NOTFOUND) {
               printf("No records selected!\n");
               break ;
             }
       }/* for1 end */

       /* message buffer free */
       tpfree ((char *)transf);
       /* disconnects from Tmax */
       tpend ();

       /* sec2 = end time */
       htime(te,&sec2);

       /* calculates processing time for each data */
       printf("TOT.COUNT = %d\n", cnt_data);
       printf("Start time = %s\n", ts);
       printf("End time = %s\n", te);
      if ((sec2-sec1) ! = 0)
           tps = (float) cnt_data / (sec2 - sec1);
       else
           tps = cnt_data;
       printf("Interval = %d secs ==> %10.2f T/S\n", sec2-sec1,tps);
}

htime(char *cdate, int *sec)
{
       long time(), timef, pt;
        char ct[20], *ap;
        struct tm *localtime(), *tmp;

        pt = time(&timef);
        *sec = pt;
        tmp = localtime(&timef);
        ap = asctime(tmp);

        sscanf(ap, "%*s%*s%*s%s",ct);
        sprintf( cdate, "%02d. %02d. %02d %s", tmp->tm_year, ++tmp->tm_mon,
                 tmp->tm_mday,ct);
}
Server program

The following is an example.

<sel_acct.pc>

#include <stdio.h>
#include <usrinc/atmi.h>
#include <usrinc/tx.h>
#include "acct.s"
#define NFETCH 5
#define NOTFOUND 100

EXEC SQL include sqlca.h;
EXEC SQL begin declare section;
long account_id, key;
varchar phone[20], address[80];
EXEC SQL end declare section;

SEL_ACCT(TPSVCINFO *msg)
{
       int i , j , nfetch;
       int return_code;
       struct stru_acct *ACCT_V;

       /* receives client data */
       ACCT_V = (struct stru_acct *) msg->data;

       /* moves an accound ID value to be selected to the key */
       key = ACCT_V->ACCOUNT_ID;

       /* reallocates the size of the client buffer */
       if ((ACCT_V = (struct stru_acct *)tprealloc((char *)ACCT_V,
           sizeof(struct stru_acct)*NFETCH )) == (struct stru_acct *)NULL) {
           fprintf(stderr, "tprealloc error =%s\n", tpstrerror(tperrno));
           tpreturn (TPFAIL, tperrno, NULL, 0, TPNOFLAGS);
       }

       /* initializes a buffer */
       ACCT_V->ACCOUNT_ID = 0;
       strcpy(ACCT_V->PHONE," " ) ;
       strcpy(ACCT_V->ADDRESS," " ) ;

       /* extracts phone and address fields from the ACCOUNT table */
       EXEC SQL declare CUR_1 cursor for
                 select account_id,phone,address
                  into :account_id, :pfone, :address
                  from ACCOUNT
               where account_id > :key;/* if an account ID is larger than
                                                              a field key */

       /* cursor open */
       EXEC SQL open CUR_1;
       /* cursor open error */
       if (sqlca.sqlcode ! = 0) {
              printf("open cursor error !\n");
              tpreturn(TPFAIL, sqlca.sqlcode, NULL, 0, TPNOFLAGS);
       }

       nfetch=0 ;
       return_code = NOTFOUND;

       /* cursor open success */
       while (sqlca.sqlcode == 0) {
           /* fetches data from the location a cursor points one at a time */
           EXEC SQL fetch CUR_1;

           /* fetch error */
           if (sqlca.sqlcode ! = 0) {
               if (sqlca.sqlcode == NOTFOUND)
                    break ;
                break ;
            }

           ACCT_V[nfetch].ACCOUNT_ID = account_id;
           strcpy(ACCT_V[nfetch].PHONE, phone );
           strcpy(ACCT_V[nfetch].ADDRESS, address );

            /* increases the number of selected data */
            nfetch++;
            return_code = nfetch

            /* exits from "while"
              if data is selected as many as the number of NFETCH */
           if (nfetch > NFETCH) {
               nfetch = NFETCH;
               return_code = nfetch;
               break ;
            }
       }
       /* cursor close */
       EXEC SQL close CUR_1;

       /* returns the result and its data to a client */
       tpreturn ( TPSUCCESS, return_code, (char *)ACCT_V,
                  sizeof(struct stru_acct)*nfetch, TPNOFLAGS);
}

3.5. DB2 Program

A client receives user input, saves EMPNO to a STRING buffer, and calls a service. A server receives all the data and adds it to the table. If an error occurs, a client can roll back the database by specifying the process as a single transaction.

Program Files
  • Common program

    File Description

    sample.m

    Tmax configuration file.

    create.ers

    SQL script for creating a database table.

  • Client program

    File Description

    clidb2tx.c

    Client program.

  • Server program

    File Description

    svr_db2.sqc

    DB2 source of a service program.

    Makefile

    Makefile for compiling TMS and the server program.

Program Feature
  • Client program

    Feature Description

    Tmax connection

    Basic connection.

    Buffer type

    STRING.

    Communication type

    Synchronous communication using tpcall().

    Transaction handling

    Transaction scope is specified by a client.

  • Server program

    Feature Description

    Service

    XASERVICE2.

    Database connection

    DB2 database.

Considerations before the DB2 integration test

Check the following when integrating to DB2.

  1. DB2 client engine (32-bit or 64-bit).

  2. DB2 client version.

  3. Set the XAOPTION item in the SVRGROUP section of the Tmax configuration file.

    • When the DB2 client version is 8.0 or previous

      • When the DB2 client engine is 32-bit

        XAOPTION = "DYNAMIC"
      • When the DB2 client engine is 64-bit and OS is Unix or Linux

        XAOPTION = "DYNAMIC XASWITCH32"
      • When the DB2 client engine is 64-bit and OS is Windows

        XAOPTION = "DYNAMIC"
    • When the DB2 client version is 9.0 or later (regardless of the DB2 client engine and OS)

      Do not set XAOPTION.
  4. Link appropriate libraries when compiling TMS and the server program.

    • When the DB2 client version is 8.0 or previous

      • When the DB2 client engine is 32-bit

        -ldb2s or $(TMAXDIR)/lib/libdb2s.a
      • When the DB2 client engine is 64-bit and OS is Unix or Linux

        -ldb2_64s or $(TMAXDIR)/lib64/libdb2_64s.a
      • When the DB2 client engine is 64-bit and OS is Windows

        -ldb2s or $(TMAXDIR)/lib/libdb2s.a
    • When the DB2 client version is 9.0 or later (regardless of the DB2 client engine and OS)

       -ldb2s_static or $(TMAXDIR)/lib/libdb2s_static.a

When the DB2 client version is 9.0 or later, you can link the library used for 8.0 or previous versions for dynamic registration. However, it is not recommended.

Tmax Configuration File

The following is an example.

<sample.m>

*DOMAIN
tmax1           SHMKEY = 71990, MINCLH = 1, MAXCLH = 3,
                TPORTNO = 7789, BLOCKTIME = 30,
                MAXCPC = 150

*NODE
phk        TMAXDIR = "/home/tmaxha/tmax",
                APPDIR  = "/home/tmaxha/tmax/appbin",
                PATHDIR = "/home/tmaxha/tmax/path",
                TLOGDIR = "/home/tmaxha/tmax/log/tlog",
                ULOGDIR = "/home/tmaxha/tmax/log/ulog",
                SLOGDIR = "/home/tmaxha/tmax/log/slog"

*SVRGROUP
xa_svg_db2      NODENAME = "phk",
                  DBNAME = IBMDB2,
#                 XAOPTION = "DYNAMIC XASWITCH32",
                  XAOPTION = "DYNAMIC",
                  OPENINFO = "db=test,uid=tmaxha,pwd=ha0115",
                  TMSNAME = tms_db2,
                  RESTART=N

*SERVER
svr_db2                  SVGNAME = xa_svg_db2

*SERVICE
XASERVICE2         SVRNAME = svr_db2

The following items are added.

Item Description

DBNAME

Database name.

OPENINFO

DB2 database connection information.

TMSNAME

Name of the process that handles transactions that meet OPENINFO.

Database Script

The following creates a DB2 table.

#'db2start' execution
$ db2start

# Creating a database named TPTEST
$ db2 "CREATE DATABASE TPTEST"

# Connecting to the TPTEST databse
$ db2 "CONNECT TO TPTEST"

# Creating a table named EMP
$ db2 -vf create.ers -t

<create.ers>
CREATE TABLE EMP (
         EMPNO                  DECIMAL(8) NOT NULL,
         ENAME                  VARCHAR(16),
         JOB                    VARCHAR(16),
         SAL                    DECIMAL(8),
         HIREDATE               DECIMAL(8),
         XID                    CHAR(32)
);

# Checking the table creation
$ db2 "LIST TABLES"

The following shows the DB2 table and sample data.

$ db2 "DESCRIBE TABLE EMP"

Column                         Type      Type
name                           schema    name               Length   Scale Nulls
------------------------------ --------- ------------------ -------- ----- ------
EMPNO                          SYSIBM    DECIMAL                   8     0 No
ENAME                          SYSIBM    VARCHAR                  16     0 Yes
JOB                            SYSIBM    VARCHAR                  16     0 Yes
SAL                            SYSIBM    DECIMAL                   8     0 Yes
HIREDATE                       SYSIBM    DECIMAL                   8     0 Yes
XID                            SYSIBM    CHARACTER                32     0 Yes

  6 record(s) selected.
Client Program

The following is an example.

<clidb2tx.c>

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <usrinc/atmi.h>

int main(int argc, char *argv[])
{
    char       *sndbuf, *rcvbuf;
    long       rcvlen;
    int        ret;

    if ( (ret = tmaxreadenv( "tmax.env","TMAX" )) == -1 ){
        printf( "tmax read env failed.[%s]\n", tpstrerror(tperrno));
        exit(1);
    }

    if (tpstart((TPSTART_T *)NULL) == -1){
        printf("tpstart failed.[%s]\n", tpstrerror(tperrno));
        exit(1);
    }

    if ((sndbuf = (char *)tpalloc("STRING", NULL, 0)) == NULL) {
        printf("sendbuf alloc failed! [%s]\n", tpstrerror(tperrno));
        tpend();
        exit(1);
    }

    if ((rcvbuf = (char *)tpalloc("STRING", NULL, 0)) == NULL) {
        printf("recvbuf alloc failed! [%s]\n", tpstrerror(tperrno));
        tpfree(sndbuf);
        tpend();
        exit(1);
    }

    strcpy(sndbuf, argv[1]);

    ret = tx_begin();
    if (ret < 0) {
        printf("tx_begin is failed.[%s]\n", tpstrerror(tperrno));
        resource_free(sndbuf, rcvbuf);
        exit(1);
    } else
        printf("tx_begin success.\n");

    if (tpcall("XASERVICE2", sndbuf, strlen(sndbuf), &rcvbuf, &rcvlen, 0) == -1){
        printf("Can't send request to service XASERVICE2.[%s]\n", tpstrerror(tperrno));
        ret = tx_rollback();
        if (ret < 0)
            printf("tx_rollback is failed. [%s]\n", tpstrerror(tperrno));

        resource_free(&sndbuf, &rcvbuf);
        exit(1);
    } else
        printf("XASERVCE2 success.\n");

    ret = tx_commit();
    if (ret < 0) {
        printf("tx_commit is failed. [%s]\n", tpstrerror(tperrno));
        ret = tx_rollback();
        if (ret < 0)
            printf("tx_rollback is failed. [%s]\n", tpstrerror(tperrno));
    } else
        printf("tx_commit success.\n");
    resource_free(sndbuf, rcvbuf);

    return 0;
}

resource_free(char* sndbuf, char *rcvbuf)
{
    if (rcvbuf != NULL)
        tpfree((char*)rcvbuf);

    if (sndbuf != NULL)
       tpfree((char*)sndbuf);

   tpend();
}
Server program

The following is an example.

<svr_db2.sqc>

#include <stdio.h>
#include <usrinc/atmi.h>

EXEC SQL INCLUDE SQLCA;

EXEC SQL begin declare section;
         sqlint32 h_empno;
         sqlint32 h_count;
EXEC SQL end declare section;

XASERVICE2(TPSVCINFO *msg)
{
         char         *res_msg;
         int  h_count=0;

          h_empno = atoi(msg->data);
         printf("h_empno = %d \n", h_empno);

         EXEC SQL
                  INSERT into EMP (EMPNO) VALUES (:h_empno);
         if (sqlca.sqlcode != 0) {
                  printf("insertion is failed : sqlcode[%d]%d\n", sqlca.sqlcode, sqlca.sqlstate);
                  tpreturn(TPFAIL, -1, 0, 0, 0);
         } else

        EXEC SQL SELECT COUNT(*)
        INTO    :h_count
        FROM    emp
        WHERE   empno = :h_empno;

         if (sqlca.sqlcode != 0) {
                  printf("insertion is failed : sqlcode[%d]%d\n", sqlca.sqlcode, sqlca.sqlstate);
                  tpreturn(TPFAIL, -1, 0, 0, 0);
         } else
                  printf("insertion is success. selcnt(%d) \n", h_count);

         tpreturn(TPSUCCESS, 0, 0, 0, 0);
}
Server Makefile

The following is an example.

# Server makefile for DB2
# Linux 64bit

DB2LIBDIR = $(DB2_HOME)/lib
DB2LIBS           = -ldb2

DB         = TEST
DB2USER = tmaxha
DB2PASS = ha0115

TARGET  = $(COMP_TARGET)
APOBJS  = $(TARGET).o
APOBJS2  = utilemb.o
NSDLOBJ = $(TMAXDIR)/lib64/sdl.o

#OBJS    = $(APOBJS) $(APOBJS2) $(SVCTOBJ)
OBJS    = $(APOBJS)  $(SVCTOBJ)
SVCTOBJ = $(TARGET)_svctab.o

#CFLAGS  = -m64 -O -I$(TMAXDIR) -I$(DB2_HOME)/include
CFLAGS  =  -O -I$(TMAXDIR) -I$(DB2_HOME)/include
LDFLAGS =

TMAXAPPDIR  = $(TMAXDIR)/appbin
TMAXSVCTDIR = $(TMAXDIR)/svct
TMAXLIBDIR  = $(TMAXDIR)/lib64

TMAXLIBS    = -lsvr -ldb2s          # dynmic XAOPTION=DYNAMIC (DB2 Client v8.0(below) 32bit  or  DB2 Client 64bit & Windows)
#TMAXLIBS    = -lsvr -ldb2_64s      # dynmic XAOPTION=DYNAMIC (DB2 Client v8.0(below) 64bit & Linux/Unix)
#TMAXLIBS    = -lsvr -ldb2s_static       #static XAOPTION=none (DB2 Client v9.0(above))
#
.SUFFIXES : .c

.c.o:
         $(CC) $(CFLAGS) $(LDFLAGS) -c $<

#
# server compile
#
all: $(TARGET)

$(TARGET): $(OBJS)
         $(CC) $(CFLAGS) $(LDFLAGS) -L$(TMAXLIBDIR) -o $(TARGET) -L$(DB2LIBDIR) $(DB2LIBS) $(OBJS) $(TMAXLIBS) $(NSDLOBJ)
         mv $(TARGET) $(TMAXAPPDIR)
         rm -f $(OBJS)

$(APOBJS): $(TARGET).sqc
         db2 connect to $(DB) user $(DB2USER) using $(DB2PASS)
         db2 prep $(TARGET).sqc bindfile
         db2 bind $(TARGET).bnd
         db2 connect reset
         db2 terminate
         $(CC) $(CFLAGS) $(LDFLAGS) -c $(TARGET).c

$(SVCTOBJ):
         cp -f $(TMAXSVCTDIR)/$(TARGET)_svctab.c .
         touch ./$(TARGET)_svctab.c
         $(CC) $(CFLAGS) -c ./$(TARGET)_svctab.c

#
clean:
         :-rm -f *.o core $(TMAXAPPDIR)/$(TARGET) $(TARGET).bnd
TMS Makefile

The following is an example.

# TMS Makefile for DB2
# Linux 64bit

TARGET  = tms_db2
APOBJ   = dumy.o

APPDIR  = $(TMAXDIR)/appbin
TMAXLIBD= $(TMAXDIR)/lib64
TMAXLIBS    = -lsvr -ldb2s          # dynmic XAOPTION=DYNAMIC (DB2 Client v8.0(below) 32bit  or  DB2 Client 64bit & Windows)
#TMAXLIBS    = -lsvr -ldb2_64s      # dynmic XAOPTION=DYNAMIC (DB2 Client v8.0(below) 64bit & Linux/Unix)
#TMAXLIBS    = -lsvr -ldb2s_static       #static XAOPTION=none (DB2 Client v9.0(above))

DB2PATH = $(DB2_HOME)
DB2LIBDIR= $(DB2PATH)/lib
DB2LIB  = -ldb2

CFLAGS  =
LDFLAGS =
SYSLIBS =

all: $(TARGET)

$(TARGET): $(APOBJ)
         $(CC) $(CFLAGS) $(LDFLAGS) -o $(TARGET) -L$(TMAXLIBD) $(TMAXLIBS) $(APOBJ) -L$(DB2LIBDIR) $(DB2LIB) $(SYSLIBS)
         mv $(TARGET) $(APPDIR)/.

$(APOBJ):
         $(CC) $(CFLAGS) -c dumy.c
#
clean:
         -rm -f *.o core $(APPDIR)/$(TARGET)

4. Database Integration Programs

This section describes actual programming that you can use when developing applications. A database can be integrated with homogeneous or heterogeneous databases.

4.1. Synchronous Mode (Homogeneous Database)

The following shows a program flow when accessing a homogeneous database in synchronous mode.

chap13 1
Synchronous Mode Flow (Homogeneous Database)
Program Files
  • Common program

    File Description

    demo.s

    SDLFILE.

    sample.m

    Tmax configuration file.

    tmax.env

    Configuration file.

    mktable.sql

    SQL script for creating a database table.

  • Client program

    File Description

    client.c

    Client program.

  • Server program

    File Description

    update.pc, insert.pc

    Server program.

    Makefile

    Tmax makefile that must be modified.

Program Feature
  • Client program

    Feature Description

    Tmax connection

    Connection with the NULL parameter.

    Buffer type

    STRUCT.

    Subtype

    SDL file must be created by using sdlc to compile an input structure file.

    Transaction

    Transaction is specified by a client.

  • Server program

    Feature Description

    The number of services

    INSERT service is requested from the UPDATE service.

    Database connection

    Oracle database is used. Database information is specified in the SVRGROUP section of the Tmax configuration file.

Program Environment
Classification Description

System

SunOS 5.7 32-bit

Database

Oracle 8.0.5

Struct Buffer

The following is an example.

<demo.s>

struct input {
        int     account_id;
        int     branch_id;
        char    phone[15];
        char    address[61];
};
Tmax Configuration File

The following is an example.

<sample.m>

*DOMAIN
res   SHMKEY=88000, MINCLH=1, MAXCLH=5, TPORTNO=8880, BLOCKTIME=60

*NODE
tmax          TMAXDIR = "/user/ tmax ",
              APPDIR  = "/user/ tmax /appbin",
              PATHDIR = "/user/ tmax /path",
              TLOGDIR = "/user/ tmax /log/tlog",
              ULOGDIR="/user/ tmax /log/ulog",
              SLOGDIR="/user/ tmax /log/slog"

*SVRGROUP
svg1          NODENAME = tmax, DBNAME = ORACLE,
              OPENINFO = "ORACLE_XA+Acc=P/bmt/bmt+SesTm=60",
              TMSNAME = svg1_tms

*SERVER
update        SVGNAME=svg1
insert        SVGNAME=svg1

*SERVICE
UPDATE        SVRNAME=update
INSERT        SVRNAME=insert
Configuration File

The following is an example.

<tmax.env>

[tmax]
TMAX_HOST_ADDR=192.168.1.39
TMAX_HOST_PORT=8880
SDLFILE=/user/tmax/sample/sdl/tmax.sdl
TMAX_CONNECT_TIMEOUT=5
Database Script

The following creates a database table.

<mktable.sql>

$ORACLE_HOME/bin/sqlplus bmt/bmt <<!
drop table ACCOUNT;
create table ACCOUNT (
        ACCOUNT_ID  integer,
        BRANCH_ID   integer not null,
        SSN     char(13) not null,
        BALANCE     number,
        ACCT_TYPE   char(1),
        LAST_NAME   char(21),
        FIRST_NAME  char(21),
        MID_INIT    char(1),
        PHONE       char(15),
        ADDRESS     char(61),
        CONSTRAINT ACCOUNT_PK PRIMARY KEY(ACCOUNT_ID)
);
quit
!
Client Program

The following is an example.

<client.c>

#include <stdio.h>
#include <usrinc/atmi.h>
#include "../sdl/demo.s"

#define TEMP_PHONE "6283-2114"
#define TEMP_ADDRESS "Korea"

int main(int argc, char *argv[])
{
        struct input *sndbuf;
        char    *rcvbuf;
        int acnt_id, n, timeout;
        long    len;

        if (argc != 2) {
            fprintf(stderr, "Usage:%s account_id \n", argv[0]);
            exit(1);
        }

        acnt_id = atoi(argv[1]);
        timeout = 5;

        n = tmaxreadenv("tmax.env", "tmax");
        if (n < 0) {
            fprintf(stderr, "tmaxreadenv fail! tperrno = %d\n", tperrno);
            exit(1);
        }

        n = tpstart((TPSTART_T *)NULL);
        if (n < 0) {
            fprintf(stderr, "tpstart fail! tperrno = %s\n", tperrno);
            exit(1);
        }

        sndbuf = (struct input *)tpalloc("STRUCT", "input", `
                  sizeof(struct input));
        if (sndbuf == NULL) {
            fprintf(stderr, "tpalloc fail: sndbuf tperrno = %d\n", tperrno);
            tpend();
            exit(1);
        }

        rcvbuf = (char *)tpalloc("STRING", NULL, 0);
        if (rcvbuf == NULL) {
            fprintf(stderr, "tpalloc fail: rcvbuf tperrno = %d\n", tperrno);
            tpend();
            exit(1);
        }

        sndbuf->account_id = acnt_id;
        sndbuf->branch_id = acnt_id;
        strcpy(sndbuf ->phone, TEMP_PHONE);
        strcpy(sndbuf ->address, TEMP_ADDRESS);

        tx_set_transaction_timeout(timeout);
        n = tx_begin();
        if (n < 0)
            fprintf(stderr, "tx begin fail! tperrno = %d\n", tperrno);

        n = tpcall("UPDATE", (char *)sndbuf, sizeof(struct input),
                   (char **)&rcvbuf, (long *)&len, TPNOFLAGS);
        if (n < 0) {
            fprintf(stderr, "tpcall fail! tperrno = %d\n", tperrno);
            tpend();
            exit(1);
        }

        n = tx_commit();
        if (n < 0) {
            fprintf(stderr, "tx commit fail! tx error = %d \n", n);
            tx_rollback();
            tpend();
            exit(1);
        }

        printf("rtn msg = %s\n", rcvbuf);
        tpfree((char *)sndbuf);
        tpfree((char *)rcvbuf);
        tpend();
}
Server program

The following example is a server program that performs UPDATE in a database.

<update.pc>

#include <stdio.h>
#include <ctype.h>
#include <usrinc/atmi.h>
#include <usrinc/sdl.h>
#include "../sdl/demo.s"

#define OKMSG "YOU COMPLETE THE TRANSACTION"

EXEC SQL include sqlca.h;
EXEC SQL BEGIN DECLARE SECTION;
        int     account_id;
        int     branch_id;
        char    ssn[15];
        char    phone[15];
        char    address[61];
EXEC SQL END DECLARE SECTION;

UPDATE(TPSVCINFO *msg)
{
        struct input *rcvbuf;
        int     ret;
        long    acnt_id, rcvlen;
        char    *send;

        rcvbuf = (struct input *)(msg->data);
            send = (char *)tpalloc("STRING", NULL, 0);
        if (send == NULL) {
            fprintf(stderr, "tpalloc fail errno = %s\n", strerror(tperrno));
            tpreturn(TPFAIL, 0, (char *)NULL, 0, 0);
        }
        account_id = rcvbuf->account_id;
        branch_id = rcvbuf->branch_id;
}

The following example is a server program that performs INSERT in a database.

< insert.pc>

#include <stdio.h>
#include <ctype.h>
#include <usrinc/atmi.h>
#include <usrinc/sdl.h>
#include "../sdl/demo.s"

#define OKMSG "YOU COMPLETE THE TRANSACTION"

EXEC SQL include sqlca.h;
EXEC SQL BEGIN DECLARE SECTION;
        int     account_id;
        int     branch_id;
        char    ssn[15];
        char    phone[15];
        char    address[61];
EXEC SQL END DECLARE SECTION;

INSERT(msg)
TPSVCINFO  *msg;
{
        struct input *rcvbuf;
        int     ret;
        long    acnt_id;
        char    *send;

        rcvbuf = (struct input *)(msg->data);
        send = (char *)tpalloc("STRING", NULL, 0);
        if (send == NULL) {
            fprintf(stderr, "tpalloc fail errno = %s\n", tpstrerror(tperrno));
            tpreturn(TPFAIL, 0, (char *)NULL, 0, TPNOFLAGS);
        }

        account_id = rcvbuf->account_id;
        branch_id = rcvbuf->branch_id;
        strcpy(phone, rcvbuf->phone);
        strcpy(address, rcvbuf->address);
        strcpy(ssn, "1234567");

        /*  Declare && Open Cursor for Fetch */
        EXEC SQL INSERT INTO ACCOUNT (
            ACCOUNT_ID,
            BRANCH_ID,
            SSN,
            PHONE,
            ADDRESS )
        VALUES (:account_id, :branch_id, :ssn, :phone, :address);

        if (sqlca.sqlcode != 0 && sqlca.sqlcode != 1403 )
        {
            printf("insert failed sqlcode = %d\n", sqlca.sqlcode);
            tpreturn(TPFAIL, -1, (char *)NULL, 0, TPNOFLAGS);
        }
        strcpy(send, OKMSG);
        tpreturn(TPSUCCESS, 1, (char *)send, strlen(send), TPNOFLAGS);
}

4.2. Synchronous Mode (Heterogeneous Database)

The following shows a program flow when accessing a heterogeneous database in synchronous mode.

chap13 2
Synchronous mode Flow (Heterogeneous Database)
Program Files
  • Common program

    File Description

    demo.s

    SDLFILE.

    sample.m

    Tmax configuration file.

    tmax.env

    Configuration file.

    mktable.sql

    SQL script for creating a database table.

  • Client program

    File Description

    client.c

    Client program.

  • Server program

    File Description

    update.pc, insert.pc

    Server program.

    Makefile

    Tmax makefile that must be modified.

The client and server programs are the same as in Synchronous Mode (Homogeneous Database). For more information about environment settings for multiple nodes, refer to Tmax Administration Guide.

Program Feature
  • Client program

    Feature Description

    Tmax connection

    Connection with the NULL parameter.

    Buffer type

    STRUCT.

    Subtype

    SDL file must be created by using sdlc to compile an input structure file.

    Transaction

    Transaction is explicitly specified by a client.

  • Server program

    Feature Description

    The number of services

    INSERT service is requested from the UPDATE service.

    Database connection

    Oracle database is used. Database information is specified in the SVRGROUP section of the Tmax configuration file.

Program Environment
Classification Description

System

SunOS 5.7 32-bit, SunOS 5.8 32-bit

Database

Oracle 8.0.5

Tmax Configuration File

The following is an example.

<sample.m>

*DOMAIN
res         SHMKEY=88000, MINCLH=1, MAXCLH=5, TPORTNO=8880, BLOCKTIME=60

*NODE
tmax1       TMAXDIR="/user/ tmax ",
            APPDIR="/user/ tmax /appbin",
            PATHDIR = "/user/ tmax /path",
            TLOGDIR = "/user/ tmax /log/tlog",
            ULOGDIR="/user/ tmax /log/ulog",
            SLOGDIR="/user/ tmax /log/slog"

tmax2       TMAXDIR="/user/ tmax ",
            APPDIR="/user/ tmax /appbin",
            PATHDIR = "/user/ tmax /path",
            TLOGDIR = "/user/ tmax /log/tlog",
            ULOGDIR="/user/ tmax /log/ulog",
            SLOGDIR="/user/ tmax /log/slog"

*SVRGROUP
svg1        NODENAME = tmax1, DBNAME = ORACLE,
            OPENINFO = "ORACLE_XA+Acc=P/bmt/bmt+SesTm=60",
            TMSNAME = svg1_tms

svg2        NODENAME = tmax2, DBNAME = ORACLE,
            OPENINFO = "ORACLE_XA+Acc=P/bmt/bmt+SesTm=60",
            TMSNAME = svg2_tms

*SERVER
update      SVGNAME=svg1
insert      SVGNAME=svg2

*SERVICE
UPDATE      SVRNAME=update
INSERT      SVRNAME=insert
Configuration File

The following is an example.

<tmax.env>

[tmax1]
TMAX_HOST_ADDR=192.168.1.39
TMAX_HOST_PORT=8880
SDLFILE=/user/tmax/sample/sdl/tmax.sdl
TMAX_CONNECT_TIMEOUT=5

4.3. Asynchronous Mode (Homogeneous Database)

The following shows a program flow when accessing a homogeneous database in asynchronous mode.

figure 11 4 3
Asynchronous Mode Flow (Homogeneous Database)
Program Files
  • Common program

    File Description

    demo.s

    SDLFILE.

    sample.m

    Tmax configuration file.

    tmax.env

    Configuration file.

    mktable.sql

    SQL script for creating a database table.

  • Client program

    File Description

    client.c

    Client program.

  • Server program

    File Description

    update.pc

    Server program.

    Makefile

    Tmax makefile that must be modified.

Program Feature
  • Client program

    Feature Description

    Tmax connection

    Connection with the NULL parameter.

    Buffer type

    STRUCT.

    Subtype

    SDL file must be created by using sdlc to compile an input structure file.

    Transaction

    Transaction is specified by a client.

  • Server program

    Feature Description

    The number of services

    INSERT service is requested.

    Database connection

    Oracle database is used. Database information is specified in the SVRGROUP section of the system configuration file.

Program Environment
Classification Description

System

SunOS 5.7 32-bit

Database

Oracle 8.0.5

Struct Buffer

The following is an example.

<demo.s>

struct input {
        int     account_id;
        int     branch_id;
        char    phone[15];
        char    address[61];
};
Tmax Configuration File

The following is an example.

<sample.m>

*DOMAIN
res         SHMKEY=88000, MINCLH=1, MAXCLH=5, TPORTNO=8880, BLOCKTIME=60

*NODE
tmax        TMAXDIR="/user/ tmax ",
            APPDIR="/user/ tmax /appbin",
            PATHDIR = "/user/ tmax /path",
            TLOGDIR = "/user/ tmax /log/tlog",
            ULOGDIR="/user/ tmax /log/ulog",
            SLOGDIR="/user/ tmax /log/slog"

*SVRGROUP
svg1        NODENAME = tmax, DBNAME = ORACLE,
            OPENINFO = "ORACLE_XA+Acc=P/bmt/bmt+SesTm=60",
            TMSNAME = svg1_tms

*SERVER
update      SVGNAME=svg1

*SERVICE
UPDATE      SVRNAME=update
Configuration File

The following is an example.

<tmax.env>

[tmax]
TMAX_HOST_ADDR=192.168.1.39
TMAX_HOST_PORT=8880
SDLFILE=/user/tmax/sample/sdl/tmax.sdl
TMAX_CONNECT_TIMEOUT=5
Database Script

The following creates a database table.

<mktable.sql>

$ORACLE_HOME/bin/sqlplus bmt/bmt <<!
drop table ACCOUNT;
create table ACCOUNT (
        ACCOUNT_ID  integer,
        BRANCH_ID   integer not null,
        SSN     char(13) not null,
        BALANCE     number,
        ACCT_TYPE   char(1),
        LAST_NAME   char(21),
        FIRST_NAME  char(21),
        MID_INIT    char(1),
        PHONE       char(15),
        ADDRESS     char(61),
        CONSTRAINT ACCOUNT_PK PRIMARY KEY(ACCOUNT_ID)
);
quit
!
Client Program

The following is an example.

<client.c>

#include <stdio.h>
#include <usrinc/atmi.h>
#include "../sdl/demo.s"

#define TEMP_PHONE "6283-2114"
#define TEMP_ADDRESS "Korea"

int main(int argc, char *argv[])
{
        struct input *sndbuf;
        char    *rcvbuf;
        int acnt_id, n, cd, timeout;
        long    len;

        if (argc != 2) {
            fprintf(stderr, "Usage:%s account_id \n", argv[0]);
            exit(1);
        }

        acnt_id = atoi(argv[1]);
        timeout = 5;

        n = tmaxreadenv("tmax.env", "tmax");
        if (n < 0) {
            fprintf(stderr, "tmaxreadenv fail! tperrno = %d\n", tperrno);
            exit(1);
        }

        n = tpstart((TPSTART_T *)NULL);
        if (n < 0) {
            fprintf(stderr, "tpstart fail! tperrno = %s\n", tperrno);
            exit(1);
        }

        sndbuf = (struct input *)tpalloc("STRUCT", "input", sizeof(struct input));
        if (sndbuf == NULL) {
            fprintf(stderr, "tpalloc fail: sndbuf tperrno = %d\n", tperrno);
            tpend();
            exit(1);
        }

        rcvbuf = (char *)tpalloc("STRING", NULL, 0);
        if (rcvbuf == NULL) {
            fprintf(stderr, "tpalloc fail: rcvbuf tperrno = %d\n", tperrno);
            tpend();
            exit(1);
        }
        sndbuf->account_id = acnt_id;
        sndbuf->branch_id = acnt_id;
        strcpy(sndbuf->phone, TEMP_PHONE);
        strcpy(sndbuf->address, TEMP_ADDRESS);
        tx_set_transaction_timeout(timeout);
        n = tx_begin();
        if (n < 0)
            fprintf(stderr, "tx begin fail! tperrno = %d\n", tperrno);

        cd = tpacall("UPDATE", (char *)sndbuf, sizeof(struct input), TPNOFLAGS);
        if (cd < 0) {
            fprintf(stderr, "tpacall fail! tperrno = %d\n", tperrno);
            tpend();
            exit(1);
        }

        n = tpgetrply(&cd, (char **)&rcvbuf, (long *)&len, TPNOFLAGS);
        if (n < 0) {
            fprintf(stderr, "tpgetrply fail! tperrno = %d\n", tperrno);
            tpend();
            exit(1);
        }

        n = tx_commit();
        if (n < 0) {
            fprintf(stderr, "tx commit fail! tx error = %d \n", n);
            tx_rollback();
            tpend();
            exit(1);
        }
        printf("rtn msg = %s\n", rcvbuf);
        tpfree((char *)sndbuf);
        tpfree((char *)rcvbuf);
        tpend();
}
Server program

The following is an example.

<update.pc>

#include <stdio.h>
#include <ctype.h>
#include <usrinc/atmi.h>
#include "../sdl/demo.s"

#define OKMSG "YOU COMPLETE THE TRANSACTION"

EXEC SQL include sqlca.h;
EXEC SQL BEGIN DECLARE SECTION;
        int     account_id;
        int     branch_id;
        char    ssn[15];
        char    phone[15];
        char    address[61];
EXEC SQL END DECLARE SECTION;

UPDATE(TPSVCINFO *msg)
{
        struct input *rcvbuf;
        int     ret, cd;
        long    acnt_id, rcvlen;
        char    *send;

        rcvbuf = (struct input *)(msg->data);
        send = (char *)tpalloc("STRING", NULL, 0);
        if (send == NULL) {
            fprintf(stderr, "tpalloc fail errno = %s\n", strerror(tperrno));
            tpreturn(TPFAIL, 0, (char *)NULL, 0, TPNOFLAGS);
        }
        account_id = rcvbuf->account_id;
        branch_id = rcvbuf->branch_id;
        strcpy(phone, rcvbuf->phone);
        strcpy(address, rcvbuf->address);
        strcpy(ssn, "1234567");

        EXEC SQL UPDATE ACCOUNT
        SET BRANCH_ID = :branch_id,
        PHONE = :phone,
        ADDRESS = :address,
        SSN = :ssn
        WHERE ACCOUNT_ID = :account_id;

        if (sqlca.sqlcode != 0 && sqlca.sqlcode != 1403 ) {
            fprintf(stderr, "update failed sqlcode = %d\n", sqlca.sqlcode);
            tpreturn(TPFAIL, -1, (char *)NULL, 0, TPNOFLAGS);
        }
        strcpy(send, OKMSG);
        tpreturn(TPSUCCESS, 1, (char *)send, strlen(send), TPNOFLAGS);
}

4.4. Interactive Mode (Homogeneous Database)

The following shows a program flow when accessing a homogeneous database in interactive mode.

chap13 3
Interactive Mode Flow (Homogeneous Database)
Program Files
  • Common program

    File Description

    demo.s

    SDLFILE.

    sample.m

    Tmax configuration file.

    tmax.env

    Configuration file.

    mktable.sql

    SQL script for creating a database table.

  • Client program

    File Description

    client.c

    Client program.

  • Server program

    File Description

    update.pc

    Server program.

    Makefile

    Tmax makefile that must be modified.

Program Feature
  • Client program

    Feature Description

    Tmax connection

    Connection with the NULL parameter.

    Buffer type

    STRUCT.

    Subtype

    SDL file must be created by using sdlc to compile an input structure file. (necessary to run an application)

    Transaction

    Transaction is specified by a client.

  • Server program

    Feature Description

    The number of services

    UPDATE service is requested.

    Database connection

    Oracle database is specified. Database information is specified in the SVRGROUP section of the Tmax configuration file.

Program Environment
Classification Description

System

SunOS 5.7 32-bit

Database

Oracle 8.0.5

Struct Buffer

The following is an example.

<demo.s>

struct input {
        int     account_id;
        int     branch_id;
        char    phone[15];
        char    address[61];
};
Tmax Configuration File

The following is an example.

*DOMAIN
res   SHMKEY=88000, MINCLH=1, MAXCLH=5, TPORTNO=8880, BLOCKTIME=60


*NODE
tmax        TMAXDIR="/user/ tmax ",
            APPDIR="/user/ tmax /appbin",
            PATHDIR = "/user/ tmax /path",
            TLOGDIR = "/user/ tmax /log/tlog",
            ULOGDIR="/user/ tmax /log/ulog",
            SLOGDIR="/user/ tmax /log/slog"

*SVRGROUP
svg1        NODENAME = tmax, DBNAME = ORACLE,
            OPENINFO = "ORACLE_XA+Acc=P/bmt/bmt+SesTm=60",
            TMSNAME = svg1_tms

*SERVER
update      SVGNAME=svg1, CONV=YES

*SERVICE
UPDATE      SVRNAME= update
Configuration File

The following is an example.

<tmax.env>

[tmax]
TMAX_HOST_ADDR=192.168.1.39
TMAX_HOST_PORT=8880
SDLFILE=/user/tmax/sample/sdl/tmax.sdl
TMAX_CONNECT_TIMEOUT=5
Database Script

The following creates a database table.

<mktable.sql>

$ORACLE_HOME/bin/sqlplus bmt/bmt <<!
drop table ACCOUNT;
create table ACCOUNT (
        ACCOUNT_ID  integer,
        BRANCH_ID   integer not null,
        SSN     char(13) not null,
        BALANCE     number,
        ACCT_TYPE   char(1),
        LAST_NAME   char(21),
        FIRST_NAME  char(21),
        MID_INIT    char(1),
        PHONE       char(15),
        ADDRESS     char(61),
        CONSTRAINT ACCOUNT_PK PRIMARY KEY(ACCOUNT_ID)
);
quit
!
Client Program

The following is an example.

<client.c>

#include <stdio.h>
#include <usrinc/atmi.h>
#include "../sdl/demo.s"

#define TEMP_PHONE "6283-2115"
#define TEMP_ADDRESS "Korea"

void main(int argc, char *argv[])
{
        struct input *sndbuf;
        char    *rcvbuf;
        int acntid, timeout;
        long revent, rcvlen;
        int cd, n;

        if (argc != 2) {
            fprintf(stderr, "Usage:%s acntid\n", argv[0]);
            exit(1);
        }

        acntid = atoi(argv[1]);
        timeout = 5;
        n = tmaxreadenv("tmax.env", "tmax");
        if (n < 0) {
            fprintf(stderr, "tmaxreadenv fail tperrno = %d\n", tperrno);
            exit(1);
        }

        n = tpstart((TPSTART_T *)NULL);
        if (n < 0) {
            fprintf(stderr, "tpstart fail tperrno = %s\n", tperrno);
            exit(1);
        }
        printf("tpstart ok!\n");
        sndbuf = (struct input *)tpalloc("STRUCT", "input", sizeof(struct input));
        if (sndbuf == NULL) {
            fprintf(stderr, "tpalloc fail: sndbuf tperrno = %d\n", tperrno);
            tpend();
            exit(1);
        }

        rcvbuf = (char *)tpalloc("CARRAY", NULL, 0);
        if (rcvbuf == NULL) {
            fprintf(stderr, "tpalloc fail: rcvbuf tperrno = %d\n", tperrno);
            tpend();
            exit(1);
        }

        sndbuf->account_id = acntid;
        sndbuf->branch_id = acntid;
        strcpy(sndbuf->phone, TEMP_PHONE);
        strcpy(sndbuf->address, TEMP_ADDRESS);

        tx_set_transaction_timeout(timeout);
        n = tx_begin();
        if (n < 0)
            fprintf(stderr, "tx begin fail tx error = %d\n", n);
        printf("tx begin ok!\n");

        cd = tpconnect("UPDATE", (char *)sndbuf, 0, TPSENDONLY);
        if (cd < 0) {
            fprintf(stderr, "tpconnect fail tperrno = %d\n", tperrno);
            tpend();
            exit(1);
        }

        while (1) {
            n = tpsend(cd, (char *)sndbuf, sizeof(struct input), TPRECVONLY,
                       &revent);
            if (n < 0) {
                fprintf(stderr, "tpsend fail revent = 0x%08x\n", revent);
             tx_rollback();
                tpend();
                exit(1);
            }
            printf("tpsend ok\n");

            n = tprecv(cd, (char **)&rcvbuf, (long *)&rcvlen, TPNOTIME, &revent);
            if (n < 0 && revent != TPEV_SENDONLY) {
                fprintf(stderr, "tprecv fail revent = 0x%08x\n", revent);
                tx_rollback();
                tpend();
                exit(1);
            }
            printf("tprecv ok\n");
            sndbuf->account_id++;

            if (revent != TPEV_SENDONLY)
            break;
        }
        n = tprecv(cd, (char **)&rcvbuf, (long *)&rcvlen, TPNOTIME, &revent);
        if (n < 0 && revent != TPEV_SVCSUCC) {
            fprintf(stderr, "tprecv fail revent = 0x%08x\n", revent);
            tx_rollback();
            tpend();
            exit(1);
        }
        printf("rcvbuf = [%s]\n", rcvbuf);

        n = tx_commit();
        if (n < 0) {
            fprintf(stderr, "tx commit fail tx error = %d\n", n);
            tx_rollback();
            tpend();
            exit(1);
        }
        printf("tx commit ok!\n");
        printf("rtn msg = %s\n", rcvbuf);
        tpfree((char *)sndbuf);
        tpfree((char *)rcvbuf);
        tpend();
}
Server program

The following is an example.

<update.pc>

#include <stdio.h>
#include <ctype.h>
#include <usrinc/atmi.h>
#include "../sdl/demo.s"

void _db_work();

#define OKMSG "YOU COMPLETE THE TRANSACTION"

EXEC SQL include sqlca.h;
EXEC SQL BEGIN DECLARE SECTION;
        int     account_id;
        int     branch_id;
        char    ssn[15];
        char    phone[15];
        char    address[61];
EXEC SQL END DECLARE SECTION;

struct input *rcvbuf;

UPDATE(TPSVCINFO *msg)
{
        int     ret, count;
        long    acnt_id;
        long    revent, rcvlen, flag;
        char    *send;

        rcvbuf = (struct input *)tpalloc("STRUCT", "input", 0);
        send = (char *)tpalloc("CARRAY", NULL, 0);

        count = 1;
        flag = 0;

        while (1) {
            ret = tprecv(msg->cd, (char **)&rcvbuf, &rcvlen, TPNOTIME, &revent);
            if (ret < 0 && revent != TPEV_SENDONLY) {
                fprintf(stderr, "tprecv fail revent = 0x%08x\n", revent);
                tpreturn(TPFAIL, -1, (char *)rcvbuf, 0, TPNOFLAGS);
            }
            printf("tprecv ok!\n");

            if (count == 10) {
                flag &= ~TPRECVONLY;
                flag |= TPNOTIME;
            }
            else
                flag |= TPRECVONLY;

            ret = tpsend(msg->cd, (char *)send, strlen(send), flag, &revent);
            if (ret < 0) {
                fprintf(stderr, "tpsend fail revent = 0x%08x\n", revent);
                tpreturn(TPFAIL, -1, (char *)NULL, 0, TPNOFLAGS);
            }
            printf("tpsend ok!\n");
            _db_work();

            /* break after 10 iterations */
            if (count == 10)
                break;

            count++;
        }

        strcpy(send, OKMSG);
        printf("tpreturn ok!\n");
        tpreturn(TPSUCCESS, 1, (char *)send, strlen(send), TPNOFLAGS);
}

void _db_work() {
        account_id = rcvbuf->account_id;
        branch_id = rcvbuf->branch_id;
        strcpy(phone, rcvbuf->phone);
        strcpy(address, rcvbuf->address);
        strcpy(ssn, "1234567");

        EXEC SQL UPDATE ACCOUNT
        SET BRANCH_ID = :branch_id,
            PHONE = :phone,
            ADDRESS = :address,
            SSN = :ssn
            WHERE ACCOUNT_ID = :account_id;

        if (sqlca.sqlcode != 0 && sqlca.sqlcode != 1403 )
        {
            fprintf(stderr, "update failed sqlcode = %d\n", sqlca.sqlcode);
            tpreturn(TPFAIL, -1, (char *)NULL, 0, 0);
        }
}

5. Programs Using TIP

Tmax Information Provider (TIP) is a function process that handles TIPSVC. The following features can be performed using TIP.

  • System environment information check: static environment information of a system can be checked.

  • System statistical information check: status of each process can be checked while a system is operating.

  • System operation management: processes are started or terminated.

5.1. TIP Structure

The TIP server has the SYS_SVR server type and is included in the TIP server group. The TIP server receives a request from a client or server, transfers the request to CLH/TMM, and then returns the result to the requester. The TIP server uses field keys to handle the service. The client or server saves data to be requested to a field buffer, sends a request, and then receives the result with the field buffer.

  • CHLOG section (log level change)

    CHLOG is the section in which the log levels of TMM, CLH, TMS, and SVR are changed. CHLOG performs the same action as chlog in tmadmin.

    When the TIP service is called, TIPSVC is called after the following are set in the field buffer.

    Item Description

    TIP_OPERATION (string)

    GET.

    TIP_SEGMENT (string)

    ADMINISTRATION.

    TIP_SECTION (string)

    CHLOG.

    TIP_MODULE (int)

    Module to dynamically change log. Options are:

    • TIP_TMM

    • TIP_CLH

    • TIP_TMS

    • TIP_SVR

    TIP_FLAGS (int)

    Flags. Options are:

    • TIP_VFLAG

    • TIP_GFLGA

    • TIP_NFLAG

    TIP_SVRNAME (string)

    Server name. Set only when TIP_FLAGS is TIP_VFLAG.

    TIP_SVGNAME (string)

    Server group name. Set only when TIP_FLAGS is TIP_GFLAG.

    TIP_NODENAME (string)

    Node name. Set only when TIP_FLAGS is TIP_NFLAG.

    TIP_LOGLVL (string)

    Log level. Value must be in lowercase letters. The result value is set in TIP_ERROR. Options are:

    • compact

    • basic

    • detail

    • debug1

    • debug2

    • debug3

    • debug4

    TIP_ERROR (int)

    Error value. Options are:

    • TIPESVCFAIL: corresponding service was not handled successfully

    • TIPEOS: memory allocation failed

    • TIPEBADFLD: value of TIP_MODULE is not set

  • CHTRC section

    TMAX_TRACE of TMS and SPR are specified to modify the trace log options in the CHTRC section. CHTRC performs the same action as chtrc in tmadmin.

    When the TIP service is called, TIPSVC is called after setting the following in a field buffer.

    Item Description

    TIP_OPERATION (string)

    GET.

    TIP_SEGMENT (string)

    ADMINISTRATION.

    TIP_SECTION (string)

    CHTRC.

    TIP_FLAGS (int)

    Flags. Options are:

    • TIP_PFLAG

    • TIP_VFLAG

    • TIP_GFLAG

    • TIP_NFLAG

    TIP_SPRI (int)

    Sets spri. Set only when TIP_FLAGS is TIP_PFLAG.

    TIP_SVGNAME (string)

    Server group name. Set only when TIP_FLAGS is TIP_GFLAG.

    TIP_NODENAME (string)

    Node name. Set only when TIP_FLAGS is TIP_NFLAG.

    TIP_SPEC (string)

    Filter spec, receiver spec, and trigger spec. The result value is set in TIP_ERROR.

    TIP_ERROR (int)

    Error value. Options are:

    • TIPESVCFAIL: corresponding service was not successfully handled

    • TIPEOS: memory allocation is failed

    • TIPEBADFLD: value of TIP_MODULE is not set

The following must be included in requests to TIPSVC.

  • Operation (TIP_OPERATION)

    Set Value Description

    GET

    To check statistical information and static environment information of a system or to operate and manage a system (BOOT/DOWN).

    SET

    To change system settings. Currently, only GET is supported.

  • Segment (TIP_SEGMENT)

    Used to determine which function to execute. The following can be set in the TIP_SEGMENT field.

    Set Value Description

    CONFIGURATION

    Checks static configuration information of a system.

    STATISTICS

    Checks statistical information while a system is operating.

    ADMINISTRATION

    Checks system operation and management (BOOT/DOWN).

  • Section (TIP_SECTION)

    When TIP_SECTION is set, the following values can be set.

    Set Value Description

    CONFIGURATION

    DOMAIN, NODE, SVRGROUP, SERVER, SERVICE, ROUTING, RQ, and GATEWAY

    STATISTICS

    NODE, TPROC, SPR, SERVICE, RQ, TMGW, NTMGW, TMS, TMMS, CLHS, and SERVER (SVR)

    ADMINISTRATION

    BOOT, DOWN, CHLOG, and CHTRC

  • Command (TIP_CMD)

    Used only when TIP_SECTION is ADMINISTRATION.

    Set Value Description

    TIP_BOOT

    Starts the Tmax system.

    TIP_DOWN

    Terminates the Tmax system.

5.2. TIP Usage

The following describes how to use TIP and check an error.

TIP Usage
  • Environment setting

    A user does not need to write a service because the TIP server is a function process provided by Tmax. However, a user must register the TIP server in a configuration file. The following example is setting an environment.

    *DOMAIN
    res             ..., TIPSVC = TIPSVC
    
    *NODE
    tmaxs1       ...
    
    *SVRGROUP
    tsvg            ..., SVGTYPE = TIP
    
    *SERVER
    TIP             SVGNAME = tsvg, SVRTYPE = SYS_SVR
    • TIPSVC is registered in the DOMAIN section. If unregistered, TIPSVC is registered by default.

    • A TIP server group (SVGTYPE=TIP) is registered in the SVRGROUP section.

    • A TIP server (SVRTYPE=SYS_SVR) is registered in the SERVER section.

  • System access

    A user must set .tpadmin in the usrname property of the TPSTART_T structure when accessing the Tmax system. usrname is set only when TIP_SEGMENT is ADMINISTRATION. If usrname is set incorrectly, the TIPEAUTH error is set in the TIP_ERROR field.

     strcpy(tpinfo->usrname, ".tpadmin");
  • Buffer allocation

    A client or a server program must allocate a field key buffer for a request because the TIP server uses field keys to handle a service.

  • TIP request items

    Item Description

    TIP_OPERATION

    Changes and checks system environment information.

    TIP_SEGMENT

    Checks information for system operation and management.

    TIP_SECTION

    Detailed property settings in SEGMENT.

    TIP_CMD

    Set only when TIP_SEGMENT is ADMINISTRATION.

    TIP_NODENAME

    Set only for multiple nodes. If only a single node exists, TIP_NODENAME is set to a local node by default. If it is incorrectly set, the TPEINVAL error occurs.

  • TIPSVC request

    After the required properties for TIP are set, set the configured field buffer to sndbuf and use tpcall or tpacall to send the TIPSVC request. Both client and server can request a service, and transactions are not supported.

  • Result reception

    The service result is saved in a reception field key buffer.

Error Check
  • If successfully handled

    The TIP_ERROR property of a reception field key buffer is set to 0.

  • If an error occurs

    Error Description

    TIP_STATUS

    Detailed error information set in TIP_ERROR can be checked.

    TIP_BADFIELD

    Field that caused the error can be checked.

    TIP_ERROR

    Value greater than 0 is set in TIP_ERROR of a reception field key buffer. It can be checked in /usrinc/tip.h.

    The following are the error values that can be set in TIP_ERROR.

    Set Value Description

    TIPNOERROR

    Error did not occur.

    TIPEBADFLD

    Invalid field key issued. In general, TIPEBADFLD is set when a field key not compiled by the fdlc utility.

    TIPEIMPL

    Unavailable feature is requested.

    TIPEAUTH

    Service not allowed under current privileges.

    TIPEOS

    OS or system error caused by a memory allocation failure, connection to Tmax system failed, or unstable network status.

    TIPENOENT

    Accessed nonexistent property.

    TIPESVCFAIL

    tpreturn() is called to TPFAIL due to a TIP service routine error.

5.3. TIP Usage Example

The following examples use TIP.

Configuration File

The following example uses a single node.

<cfg.m>

*DOMAIN
res          SHMKEY=78850,     MAXUSER=200, MINCLH=1, MAXCLH=5,
             TPORTNO=8850,     BLOCKTIME=60, TXTIME=50, RACPORT=3355

*NODE
tmaxh4         TMAXDIR="/data1/starbj81/tmax",
               APPDIR="/data1/starbj81/tmax/appbin",
               PATHDIR ="/data1/starbj81/tmax/path",
               TLOGDIR ="/data1/starbj81/tmax/log/tlog",
               ULOGDIR="/data1/starbj81/tmax/log/ulog",
               SLOGDIR="/data1/starbj81/tmax/log/slog"

*SVRGROUP
tsvg          NODENAME = "tmaxh4", SVGTYPE=TIP
svg1          NODENAME = "tmaxh4"

*SERVER
TIP            SVGNAME=tsvg, SVRTYPE=SYS_SVR, MIN=1, MAX=1
svr            SVGNAME=svg1, MIN=1

*SERVICE
TOUPPER        SVRNAME=svr

The following example uses multiple nodes.

<cfg.m>

*DOMAIN
tmax          SHMKEY=98850,
              TPORTNO=8850,
              BLOCKTIME=60,
              RACPORT=3355,
              MAXUSER=10

*NODE
Tmaxh4         TMAXDIR="/data1/starbj81/tmax",
               APPDIR="/data1/starbj81/tmax/appbin",
               PATHDIR = "/data1/starbj81/tmax/path",
               TLOGDIR = "/data1/starbj81/tmax/log/tlog",
               ULOGDIR="/data1/starbj81/tmax/log/ulog",
               SLOGDIR="/data1/starbj81/tmax/log/slog"

tmaxh2         TMAXDIR="/data1/starbj81/tmax",
               APPDIR="/data1/starbj81/tmax/appbin",
               PATHDIR = "/data1/starbj81/tmax/path",
               TLOGDIR = "/data1/starbj81/tmax/log/tlog",
               ULOGDIR="/data1/starbj81/tmax/log/ulog",
               SLOGDIR="/data1/starbj81/tmax/log/slog"

*SVRGROUP
tsvg          NODENAME = "tmaxh4", SVGTYPE=TIP

svg1          NODENAME = "tmaxh4", COUSIN = "svg2"
svg2          NODENAME = "tmaxh2"


*SERVER
TIP          SVGNAME=tsvg, SVRTYPE=SYS_SVR, MIN=1, MAX=1
svr          SVGNAME=svg1, MIN=1, MAX=5

*SERVICE
TOUPPER       SVRNAME=svr, ROUTING = "rout1"

*ROUTING
rout1          FIELD="STRING", RANGES = "'bbbbbbb'-'ccccccc' : svg1, * :
               svg2
Field Key Table

The following is an example.

< tip.f >

#
#       common field
#
# name          number  type    flags   comments
*base 16000001
TIP_OPERATION   0       string
TIP_SEGMENT     1       string
TIP_SECTION     2       string
TIP_NODE        3       string
TIP_OCCURS      4       int
TIP_FLAGS       5       int
TIP_CURSOR      6       string
TIP_SESTM       7       int
TIP_ERROR       8       int
TIP_STATE       9       int
TIP_MORE        10      int
TIP_BADFIELD    11      string
TIP_CMD         12      string
TIP_CLID        13      int
TIP_MSG         14      string

#
#       DOMAIN section fields
#
# name                  number  type    flags   comments
*base 16000100
TIP_NAME                0       string
TIP_SHMKEY              1       int
TIP_MINCLH              2       int
TIP_MAXCLH              3       int
TIP_MAXUSER             4       int
TIP_TPORTNO             5       int
TIP_RACPORT             6       int
TIP_MAXSACALL           7       int
TIP_MAXCACALL           8       int
TIP_MAXCONV_NODE        9       int
TIP_MAXCONV_SERVER      10      int
TIP_CMTRET              11      int
TIP_BLOCKTIME           12      int
TIP_TXTIME              13      int
TIP_IDLETIME            14      int
TIP_CLICHKINT           15      int
TIP_NLIVEINQ            16      int
TIP_SECURITY            17      string
TIP_OWNER               18      string
TIP_CPC                 19      int
#TIP_LOGINSVC           20      string
#TIP_LOGOUTSVC          21      string
TIP_NCLHCHKTIME         22      int
TIP_DOMAINID            23      int
TIP_IPCPERM             24      int
TIP_MAXNODE             25      int
TIP_MAXSVG              26      int
TIP_MAXSVR              27      int
TIP_MAXSVC              28      int
TIP_MAXSPR              29      int
TIP_MAXTMS              30      int
TIP_MAXCPC              31      int
TIP_MAXROUT             32      int
TIP_MAXROUTSVG          33      int
TIP_MAXRQ               34      int
TIP_MAXGW               35      int
TIP_MAXCOUSIN           36      int
TIP_MAXCOUSINSVG        37      int
TIP_MAXBACKUP           38      int
TIP_MAXBACKUPSVG        39      int
TIP_MAXTOTALSVG         40      int
TIP_MAXPROD             41      int
TIP_MAXFUNC             42      int
TIP_TXPENDINGTIME       43      int
TIP_NO                  44      int
TIP_TIPSVC              45      string
TIP_NODECOUNT           46      int
TIP_SVGCOUNT            47      int
TIP_SVRCOUNT            48      int
TIP_SVCCOUNT            49      int
TIP_COUSIN_COUNT                50      int
TIP_BACKUP_COUNT                51      int
TIP_ROUT_COUNT          52      int
TIP_STYPE               53      string
TIP_VERSION             54      string
TIP_EXPDATE             55      string
TIP_DOMAINCOUNT         56      int
TIP_RSVG_GCOUNT         57      int
TIP_RSVG_COUNT          58      int
TIP_CSVG_GCOUNT         59      int
TIP_CSVG_COUNT          60      int
TIP_BSVG_GCOUNT         61      int
TIP_BSVG_COUNT          62      int
TIP_PROD_COUNT          63      int
TIP_FUNC_COUNT          64      int
TIP_SHMSIZE             65      int
TIP_CRYPT               66      string
TIP_DOMAIN_TMMLOGLVL    67      string
TIP_DOMAIN_CLHLOGLVL    68      string
TIP_DOMAIN_TMSLOGLVL    69      string
TIP_DOMAIN_LOGLVL       70      string
TIP_DOMAIN_MAXTHREAD    71      int

#
#       NODE section fields
#
# name          number  type    flags   comments
*base 16000200
#TIP_NAME       0       string
TIP_DOMAINNAME  1       string
#TIP_SHMKEY     2       int
#TIP_MINCLH     3       int
#TIP_MAXCLH     4       int
TIP_CLHQTIMEOUT 5       int
#TIP_IDLETIME   6       int
#TIP_CLICHKINT  7       int
#TIP_TPORTNO    8       int
#TIP_TPORTNO2   9       int
#TIP_TPORTNO3   10      int
#TIP_TPORTNO4   11      int
#TIP_TPORTNO5   12      int
#TIP_RACPORT    13      int
#TIP_TMAXPORT   14      string
TIP_CMPRPORT    15      string
TIP_CMPRSIZE    16      int
#TIP_MAXUSER    17      int
TIP_TMAXDIR     18      string
TIP_TMAXHOME    19      string
TIP_APPDIR      20      string
TIP_PATHDIR     21      string
TIP_TLOGDIR     22      string
TIP_SLOGDIR     23      string
TIP_ULOGDIR     24      string
TIP_ENVFILE     25      string
#TIP_LOGINSVC   26      string
#TIP_LOGOUTSVC  27      string
TIP_IP          28      string
#TIP_PEER       29      string
TIP_TMMOPT      30      string
TIP_CLHOPT      31      string
#TIP_IPCPERM    32      int
#TIP_MAXSVG     33      int
#TIP_MAXSVR     34      int
#TIP_MAXSPR     35      int
#TIP_MAXTMS     36      int
#TIP_MAXCPC     37      int
TIP_MAXGWSVR    38      int
TIP_MAXRQSVR    39      int
TIP_MAXGWCPC    40      int
TIP_MAXRQCPC    41      int
TIP_CPORTNO     42      int
TIP_REALSVR     43      string
TIP_RSCPC       44      int
TIP_AUTOBACKUP  45      int
TIP_HOSTNAME    46      string
TIP_NODETYPE    47      int
TIP_CPU         48      int
#TIP_MAXRSTART  49      int
#TIP_GPERIOD    50      int
#TIP_RESTART    51      int
TIP_CURCLH      49      int
TIP_LIVECTIME   50      string
TIP_NODE_TMMLOGLVL      51      string
TIP_NODE_CLHLOGLVL      52      string
TIP_NODE_TMSLOGLVL      53      string
TIP_NODE_LOGLVL         54      string
TIP_NODE_MAXTHREAD      55      int
TIP_EXTPORT             56      int
TIP_EXTCLHPORT          57      int
TIP_MSGSIZEWARN 58      int
TIP_MSGSIZEMAX  59      int


#
#       SVRGROUP section fields
#
# name          number  type    flags   comments
*base 16000300
#TIP_NAME       0       string
#TIP_NODENAME   1       string
TIP_SVGTYPE     2       string
#TIP_PRODNAME   3       string
TIP_COUSIN      4       string
TIP_BACKUP      5       string
TIP_LOAD        6       int
#TIP_APPDIR     7       string
#TIP_ULOGDIR    8       string
TIP_DBNAME      9       string
TIP_OPENINFO    10      string
TIP_CLOSEINFO   11      string
TIP_MINTMS      12      int
#TIP_MAXTMS     13      int
TIP_TMSNAME     14      string
#TIP_SECURITY   15      string
#TIP_OWNER      16      string
#TIP_ENVFILE    17      string
#TIP_CPC                18      int
TIP_XAOPTION            19      string
TIP_SVG_TMSTYPE         20      string
TIP_SVG_TMSOPT          21      string
TIP_SVG_TMSTHREADS      22      int
TIP_SVG_TMSLOGLVL       23      string
TIP_SVG_LOGLVL          24      string
TIP_NODENAME            25      string

#
#       SERVER section fields
#
# name          number  type    flags   comments
*base 16000350
#TIP_NAME       0       string
TIP_SVGNAME     1       string
#TIP_NODENAME   2       string
TIP_CLOPT       3       string
TIP_SEQ         4       int
TIP_MIN         5       int
TIP_MAX         6       int
#TIP_ULOGDIR    7       string
TIP_CONV        8       int
TIP_MAXQCOUNT   9       int
TIP_ASQCOUNT    10      int
TIP_MAXRSTART   11      int
TIP_GPERIOD     12      int
TIP_RESTART     13      int
TIP_SVRTYPE     14      string
#TIP_CPC                15      int
TIP_SCHEDULE    16      int
#TIP_MINTHR     17      int
#TIP_MAXTHR     18      int
TIP_TARGET      19      string
TIP_DEPEND      20      string
TIP_CASCADE     21      int
TIP_PROCNAME    22      string
TIP_LIFESPAN    23      string
TIP_DDRI        24      string
TIP_CURSVR      25      int
TIP_SVGNO       26      int
TIP_SVR_LOGLVL  27      string


#
#       SERVICE section fields
#
# name          number  type    flags   comments
*base 16000400
#TIP_NAME       0       string
TIP_SVRNAME     1       string
TIP_PRI         2       int
TIP_SVCTIME     3       int
TIP_ROUTING     4       string
TIP_EXPORT      5       int
TIP_AUTOTRAN    6       int

#
#       ROUTING section fields
#
# name          number  type    flags   comments
*base 16000425
#TIP_NAME       0       string
TIP_FLDTYPE     1       string
TIP_RANGES      2       string
TIP_SUBTYPE     3       string
TIP_ELEMENT     4       string
TIP_BUFTYPE     5       string
TIP_OFFSET      6       int
TIP_FLDLEN      7       int
#TIP_FLDOFFSET  8       int


#
#       RQ section fields
#
# name          number  type    flags   comments
*base 16000450
#TIP_NAME       0       string
#TIP_SVGNAME    1       string
TIP_PRESVC      2       string
TIP_QSIZE       3       int
TIP_FILEPATH    4       string
TIP_BOOT        5       string
TIP_FSYNC       6       int
TIP_BUFFERING   7       int
#TIP_ENQSVC     8       int
#TIP_FAILINTERVAL 9     int
#TIP_FAILRETRY  10      int
#TIP_FAILSVC    11      string
#TIP_AFTERSVC   12      string


#
#       GATEWAY section fields
#
# name                  number  type    flags   comments
*base 16000500
#TIP_NAME               0       string
TIP_GWTYPE              1       string
TIP_PORTNO              2       int
#TIP_CPC                        3       int
TIP_RGWADDR             4       string
TIP_RGWPORTNO           5       int
#TIP_BACKUP             6       string
#TIP_NODENAME           7       string
TIP_KEY                 8       string
TIP_BACKUP_RGWADDR      9       string
TIP_BACKUP_RGWPORTNO    10      int
TIP_TIMEOUT             11      int
TIP_DIRECTION           12      string
TIP_MAXINRGW            13      int
TIP_GWOWNER             15      string
TIP_RGWOWNER            16      string
TIP_RGWPASSWD           17      string
TIP_PTIMEOUT            18      int
TIP_PTIMEINT            19      int

#
#       FUNCTION section fields
#
# name          number  type    flags   comments
*base 16000550
#TIP_NAME       0       string
#TIP_SVRNAME    1       string
TIP_FQSTART     2       int
TIP_FQEND       3       int
TIP_ENTRY       4       string


#
#       STATISTICS segment fields
#
# name          number  type    flags   comments
*base 16000600
#TIP_NAME       0       string
TIP_STATUS      1       string
TIP_STIME       2       string
TIP_TTIME       3       int
TIP_SVC_STIME   4       int
TIP_COUNT       5       int
#TIP_NO         6       int
TIP_NUM_FREE    7       int
TIP_NUM_REPLY   8       int
TIP_NUM_FAIL    9       int
TIP_NUM_REQ     10      int
TIP_ENQ_REQS    11      int
TIP_DEQ_REQS    12      int
TIP_ENQ_REPLYS  13      int
TIP_DEQ_REPLYS  14      int
TIP_CLHNO       15      int
TIP_SVR_NAME    16      string
TIP_SVC_NAME    17      string
TIP_AVERAGE     18      float
TIP_QCOUNT      19      int
TIP_CQCOUNT     20      int
TIP_QAVERAGE    21      float
TIP_MINTIME     22      float
TIP_MAXTIME     23      float
TIP_FAIL_COUNT  24      int
TIP_ERROR_COUNT 25      int
TIP_PID         26      int
TIP_TOTAL_COUNT 27      int
TIP_TOTAL_SVCFAIL_COUNT 28      int
TIP_TOTAL_ERROR_COUNT   29      int
TIP_TOTAL_AVG   30      float
TIP_TOTAL_RUNNING_COUNT 31      int
TIP_TMS_NAME    32      string
TIP_SVG_NAME    33      string
TIP_SPRI        34      int
TIP_TI_THRI     35      int
TIP_TI_AVG      36      float
TIP_TI_XID      37      string
TIP_TI_XA_STATUS        38      string
TIP_GW_NAME     39      string
TIP_GW_NO       40      int
TIP_GW_HOSTN    41      string
TIP_GW_CTYPE    42      string
TIP_GW_CTYPE2   43      string
TIP_GW_IPADDR   44      string
TIP_GW_PORT     45      int
TIP_GW_STATUS   46      string

#
#       ADMIN segment fields
#
# name          number  type    flags   comments
*base 16000650
TIP_IPADDR      0       string
TIP_USRNAME     1       string
TIP_MODULE      2       int
TIP_LOGLVL      3       string
TIP_SPEC        4       string

#
#       boot time
#
# name          number  type    flags   comments
TIP_BOOTTIME_SEC        5       int
TIP_BOOTTIME_MSEC       6       int

#
#       EXTRA flag fields
#
# name          number  type    flags   comments
*base 16000700
TIP_EXTRA_OPTION        0       int
TIP_SVRI        1       int
TIP_QPCOUNT     2       int
TIP_EMCOUNT     3       int
TIP_SVR_STATUS  4       string

5.4. Program for Checking System Environment Information

The following example is a client program that checks system environment information.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <usrinc/atmi.h>
#include <usrinc/fbuf.h>
#include <usrinc/tip.h>

#define SEC_DOMAIN          1
#define SEC_NODE            2
#define SEC_SVGROUP         3
#define SEC_SERVER          4
#define SEC_SERVICE         5
#define SEC_ROUTING         6
#define SEC_RQ              7
#define SEC_GATEWAY         8

main(int argc, char *argv[])
{
        FBUF    *sndbuf, *rcvbuf;
        TPSTART_T *tpinfo;
        int   i, n, sect;
        long  rcvlen;
        char  nodename[NAMELEN];
        int   pid, count = 0;

        if (argc != 3) {
            printf("Usage: %s section nodename\n", argv[0]);
            printf("section:\n");
            printf("\t1: domain\n");
            printf("\t2: node\n");
            printf("\t3: svrgroup\n");
            printf("\t4: server\n");
            printf("\t5: service\n");
            printf("\t6: routing\n");
            printf("\t7: rq\n");
            printf("\t8: gateway\n");
            exit(1);
        }

        if (!isdigit(argv[3][0])) {
            printf("fork count must be a digit\n");
            exit(1);
        }
        count = atoi(argv[3]);

        sect = atoi(argv[1]);
        if (sect < SEC_DOMAIN || sect > SEC_GATEWAY) {
            printf("out of section [%d - %d]\n", SEC_DOMAIN, SEC_GATEWAY);
            exit(1);
        }

        strncpy(nodename, argv[2], sizeof(nodename) - 1);

        n = tmaxreadenv("tmax.env", "TMAX");
        if (n < 0) {
           fprintf(stderr, "can't read env\n");
           exit(1);
        }

        tpinfo = (TPSTART_T *)tpalloc("TPSTART", NULL, 0);
        if (tpinfo == NULL) {
            printf("tpalloc fail tperrno = %d\n", tperrno);
            exit(1);
        }
        strcpy(tpinfo->usrname, ".tpadmin");
        if (tpstart((TPSTART_T *)tpinfo) == -1){
            printf("tpstart fail [%s]\n", tpstrerror(tperrno));
            exit(1);
        }

        if ((sndbuf = (FBUF *)tpalloc("FIELD", NULL, 0)) == NULL) {
            printf("tpalloc failed! errno = %d\n", tperrno);
            tpend();
            exit(1);
        }

        if ((rcvbuf = (FBUF *)tpalloc("FIELD", NULL, 0)) == NULL) {
            printf("tpalloc failed! errno = %d\n", tperrno);
            tpend();
            exit(1);
        }

        n = fbput(sndbuf, TIP_OPERATION, "GET", 0);
        n = fbput(sndbuf, TIP_SEGMENT, "CONFIGURATION", 0);
        switch (sect) {
            case SEC_DOMAIN:
                n = fbput(sndbuf, TIP_SECTION, "DOMAIN", 0);
                break;
            case SEC_NODE:
                n = fbput(sndbuf, TIP_SECTION, "NODE", 0);
                break;
            case SEC_SVGROUP:
                n = fbput(sndbuf, TIP_SECTION, "SVGROUP", 0);
                break;
            case SEC_SERVER:
                n = fbput(sndbuf, TIP_SECTION, "SERVER", 0);
                break;
            case SEC_SERVICE:
                n = fbput(sndbuf, TIP_SECTION, "SERVICE", 0);
                break;
            case SEC_ROUTING:
                n = fbput(sndbuf, TIP_SECTION, "ROUTING", 0);
                break;
            case SEC_RQ:
                n = fbput(sndbuf, TIP_SECTION, "RQ", 0);
                break;
            case SEC_GATEWAY:
                n = fbput(sndbuf, TIP_SECTION, "GATEWAY", 0);
                break;
        }

        n = fbput(sndbuf, TIP_NODENAME, nodename, 0);

        n = tpcall("TIPSVC", (char *)sndbuf, 0, (char **)&rcvbuf,  &rcvlen,
                    TPNOFLAGS);

        if (n < 0) {
                printf("tpcall fail [%s]\n", tpstrerror(tperrno));
                fbprint(rcvbuf);
                tpfree((char *)sndbuf);
                tpfree((char *)rcvbuf);
                tpend();
                exit(1);
        }

#if 1
        fbprint(rcvbuf);
#endif

        tpfree((char *)sndbuf);
        tpfree((char *)rcvbuf);
        tpend();
}

[Result]

The following is the result (Domain Conf) of the previous program.

$ client 1 tmaxh4
fkey = 217326601, fname = TIP_ERROR, type = int, value = 0
...
fkey = 485762214, fname = TIP_CRYPT, type = string, value = NO
    fkey = 485762215, fname = TIP_DOMAIN_TMMLOGLVL, type = string, value = DEBUG1
    fkey = 485762216, fname = TIP_DOMAIN_CLHLOGLVL, type = string, value = DEBUG2
    fkey = 485762217, fname = TIP_DOMAIN_TMSLOGLVL, type = string, value = DEBUG3
    fkey = 485762218, fname = TIP_DOMAIN_LOGLVL, type = string, value = DEBUG4
    fkey = 217326763, fname = TIP_DOMAIN_MAXTHREAD, type = int, value = 128

5.5. Program for Checking System Statistical Information

The following example is a program that checks system statistics.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <usrinc/atmi.h>
#include <usrinc/fbuf.h>
#include <usrinc/tip.h>

#define SEC_NODE        1
#define SEC_TPROC       2
#define SEC_SPR         3
#define SEC_SERVICE     4
#define SEC_RQ          5
#define SEC_TMS         6
#define SEC_TMMS        7
#define SEC_CLHS        8
#define SEC_SERVER        9

#define NODE_NAME_SIZE 32

main(int argc, char *argv[])
{
        FBUF    *sndbuf, *rcvbuf;
        TPSTART_T *tpinfo;
        int   i, n, sect;
        long  rcvlen;
        char  nodename[NODE_NAME_SIZE];
        int stat;

        if (argc != 3) {
            printf("Usage: %s section node\n", argv[0]);
            printf("section:\n");
            printf("\t1: node\n");
            printf("\t2: tproc\n");
            printf("\t3: spr\n");
            printf("\t4: service\n");
            printf("\t5: rq\n");
            printf("\t6: tms\n");
            printf("\t7: tmms\n");
            printf("\t8: clhs\n");
            printf("\t9: server\n");
            exit(1);
        }

        sect = atoi(argv[1]);
        if (sect < SEC_NODE || sect > SEC_SERVER) {
            printf("out of section [%d - %d]\n",SEC_NODE, SEC_SERVER);
            exit(1);
        }

        memset(nodename, 0x00, NODE_NAME_SIZE);
        strncpy(nodename, argv[2], NODE_NAME_SIZE - 1);

        n = tmaxreadenv("tmax.env", "TMAX");
        if (n < 0) {
           fprintf(stderr, "can't read env\n");
           exit(1);
        }

        tpinfo = (TPSTART_T *)tpalloc("TPSTART", NULL, 0);
        if (tpinfo == NULL) {
            printf("tpalloc fail tperrno = %d\n", tperrno);
            exit(1);
        }
        strcpy(tpinfo->dompwd, "xamt123");

        if (tpstart((TPSTART_T *)tpinfo) == -1){
            printf("tpstart fail tperrno = %d\n", tperrno);
            exit(1);
        }

        if ((sndbuf = (FBUF *)tpalloc("FIELD", NULL, 0)) == NULL) {
            printf("tpalloc failed! errno = %d\n", tperrno);
            tpend();
            exit(1);
        }

        if ((rcvbuf = (FBUF *)tpalloc("FIELD", NULL, 0)) == NULL) {
            printf("tpalloc failed! errno = %d\n", tperrno);
            tpend();
            exit(1);
        }

        n = fbput(sndbuf, TIP_OPERATION, "GET", 0);
        n = fbput(sndbuf, TIP_SEGMENT, "STATISTICS", 0);
        switch (sect) {
            case SEC_NODE:
                n = fbput(sndbuf, TIP_SECTION, "NODE", 0);
                break;
            case SEC_TPROC:
                n = fbput(sndbuf, TIP_SECTION, "TPROC", 0);
                break;
            case SEC_SPR:
                n = fbput(sndbuf, TIP_SECTION, "SPR", 0);
                break;
            case SEC_SERVICE:
                n = fbput(sndbuf, TIP_SECTION, "SERVICE", 0);
                break;
            case SEC_RQ:
                n = fbput(sndbuf, TIP_SECTION, "RQ", 0);
                break;
            case SEC_TMS:
                stat = 1;
                n = fbput(sndbuf, TIP_SECTION, "TMS", 0);
                n = fbput(sndbuf, TIP_EXTRA_OPTION, (char *)&stat, 0);
                break;
            case SEC_TMMS:
                n = fbput(sndbuf, TIP_SECTION, "TMMS", 0);
                break;
            case SEC_CLHS:
                n = fbput(sndbuf, TIP_SECTION, "CLHS", 0);
                break;
            case SEC_SERVER:
                n = fbput(sndbuf, TIP_SECTION, "SERVER", 0);
                break;
        }
        n = fbput(sndbuf, TIP_NODENAME, nodename, 0);

        n = tpcall("TIPSVC", (char *)sndbuf, 0, (char **)&rcvbuf,
                    &rcvlen, TPNOFLAGS);
        if (n < 0) {
            printf("tpcall fail [%s]\n", tpstrerror(tperrno));
            fbprint(rcvbuf);
            tpfree((char *)sndbuf);
            tpfree((char *)rcvbuf);
            tpend();
            exit(1);
        }

        fbprint(rcvbuf);

        tpfree((char *)sndbuf);
        tpfree((char *)rcvbuf);
        tpend();
}

[Result]

The following is the result (TMS STATISTICS) of the previous program.

$  client 3000 1 2
fkey = 217326601, fname = TIP_ERROR, type = int, value = 0
fkey = 485762680, fname = TIP_TMS_NAME, type = string, value = tms_ora2
fkey = 485762681, fname = TIP_SVG_NAME, type = string, value = xa1
fkey = 217327226, fname = TIP_SPRI, type = int, value = 0
fkey = 485762649, fname = TIP_STATUS, type = string, value = RUN
fkey = 217327197, fname = TIP_COUNT, type = int, value = 0
fkey = 351544938, fname = TIP_AVERAGE, type = float, value = 0.000000
fkey = 217327212, fname = TIP_CQCOUNT, type = int, value = 0
fkey = 217327227, fname = TIP_TI_THRI, type = int, value = 1
fkey = 351544956, fname = TIP_TI_AVG, type = float, value = 0.000000
fkey = 485762685, fname = TIP_TI_XID, type = string, value = 00000013664
fkey = 485762686, fname = TIP_TI_XA_STATUS, type = string, value = COMMIT

5.6. Program for Starting and Terminating a Server Process

Example 1

The following program starts and terminates a server process.

< cli.c >

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <usrinc/atmi.h>
#include <usrinc/fbuf.h>
#include <usrinc/tmaxapi.h>
#include <usrinc/tip.h>

#define NODE_NAME_SIZE  32

main(int argc, char *argv[])
{
        FBUF    *sndbuf, *rcvbuf;
        TPSTART_T *tpinfo;
        int   i, n, type, clid, count, flags;
        long  rcvlen;
        char  svrname[TMAX_NAME_SIZE];
        char  svgname[TMAX_NAME_SIZE];
        char  nodename[NODE_NAME_SIZE];
        int   pid, forkcnt;

        if (argc != 6) {
            printf("Usage: %s type svrname count nodename forkcnt\n", argv[0]);
            printf("type 1: BOOT, 2: DOWN, 3: DISCON\n");
            exit(1);
        }

        type = atoi(argv[1]);
        if ((type != 1) && (type != 2) && (type != 3)) {
            printf("couldn't support such a type %d\n", type);
            exit(1);
        }

        if (strlen(argv[2]) >= TMAX_NAME_SIZE) {
            printf("too large name [%s]\n", argv[1]);
            exit(1);
        }
        strcpy(svrname, argv[2]);
        count = atoi(argv[3]);
        flags = 0;

        strncpy(nodename, argv[4], NODE_NAME_SIZE - 1);
        forkcnt = atoi(argv[5]);

        n = tmaxreadenv("tmax.env", "TMAX");
        if (n < 0) {
           fprintf(stderr, "can't read env\n");
           exit(1);
        }

        tpinfo = (TPSTART_T *)tpalloc("TPSTART", NULL, 0);
        if (tpinfo == NULL) {
            printf("tpalloc fail tperrno = %d\n", tperrno);
            exit(1);
        }
        strcpy(tpinfo->usrname, ".tpadmin");

        for (i = 1; i < forkcnt; i++) {
            if ((pid = fork()) < 0)
                exit(1);
            else if (pid == 0)
                break;
        }

        if (tpstart((TPSTART_T *)tpinfo) == -1){
            printf("tpstart fail tperrno = %d\n", tperrno);
            exit(1);
        }

        if ((sndbuf = (FBUF *)tpalloc("FIELD", NULL, 0)) == NULL) {
            printf("tpalloc failed! errno = %d\n", tperrno);
            tpend();
            exit(1);
        }

        if ((rcvbuf = (FBUF *)tpalloc("FIELD", NULL, 0)) == NULL) {
            printf("tpalloc failed! errno = %d\n", tperrno);
            tpend();
            exit(1);
        }

        n = fbput(sndbuf, TIP_OPERATION, "GET", 0);
        n = fbput(sndbuf, TIP_SEGMENT, "ADMINISTRATION", 0);
        if (type == 1)
            n = fbput(sndbuf, TIP_CMD, "BOOT", 0);
        else if (type == 2)
            n = fbput(sndbuf, TIP_CMD, "DOWN", 0);
        else
            n = fbput(sndbuf, TIP_CMD, "DISCON", 0);

        if (type == 3) {
            clid = count;       /* at type 3 */
            flags |= TIP_SFLAG;
            n = fbput(sndbuf, TIP_CLID, (char *)&clid, 0);
            n = fbput(sndbuf, TIP_FLAGS, (char *)&flags, 0);
        } else {
            flags |= TIP_SFLAG;
            n = fbput(sndbuf, TIP_SVRNAME, svrname, 0);
            n = fbput(sndbuf, TIP_COUNT, (char *)&count, 0);
            n = fbput(sndbuf, TIP_FLAGS, (char *)&flags, 0);
        }

        n = fbput(sndbuf, TIP_NODENAME, nodename, 0);

        n = tpcall("TIPSVC", (char *)sndbuf, 0, (char **)&rcvbuf,
                    &rcvlen, TPNOFLAGS);
        if (n < 0) {
           printf("tpcall failed! errno = %d[%s]\n", tperrno, tpstrerror(tperrno));
           fbprint(rcvbuf);
           tpfree((char *)sndbuf);
           tpfree((char *)rcvbuf);
           tpend();
           exit(1);
        }

        fbprint(rcvbuf);

        tpfree((char *)sndbuf);
        tpfree((char *)rcvbuf);
        tpend();
Example 2

The following program changes the log level of a server named 'vr23_stat_ins' to debug4.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <usrinc/atmi.h>
#include <usrinc/fbuf.h>
#include <usrinc/tmaxapi.h>
#include <usrinc/tip.h>
#include "../fdl/tip_fdl.h"

#define NFLAG 32
#define GFLAG 8
#define VFLAG 1024

int case_chlog(int, char *[], FBUF *);

#define NODE_NAME_SIZE  32

main(int argc, char *argv[])
{
      FBUF    *sndbuf, *rcvbuf;
      TPSTART_T *tpinfo;
      int   i, ret, n, type, clid, count, flags = 0;
      long  rcvlen;
      char  svrname[TMAX_NAME_SIZE];
      char  svgname[TMAX_NAME_SIZE];
      char  nodename[NODE_NAME_SIZE];
      int   pid, forkcnt;

      if (argc < 6) {
            printf("Usage: %s svgname svrname nodename  [chlogmodule] [flags]
                                                        [loglvl]\n", argv[0]);
            printf("chlogmodule 1: TIP_TMM, 2: TIP_CLH, 4: TIP_TMS, 8: TIP_SVR\n");
            printf("flags 1: NFLAGS, 2: GFLAGS, 3: VFLAGS\n");
            printf("loglvl : 1: compact, 2: basic, 3: detail, 4: debug1,
                    5: debug2, 6: debug3, 7: debug4\n");
            exit(1);
      }

        n = tmaxreadenv("tmax.env", "TMAX");
        if (n < 0) {
           fprintf(stderr, "can't read env\n");
           exit(1);
        }

        tpinfo = (TPSTART_T *)tpalloc("TPSTART", NULL, 0);
        if (tpinfo == NULL) {
            printf("tpalloc fail tperrno = %d\n", tperrno);
            exit(1);
        }
        strcpy(tpinfo->usrname, ".tpadmin");
        strcpy(svgname, argv[1]);
        strcpy(svrname, argv[2]);
        strncpy(nodename, argv[3], NODE_NAME_SIZE - 1);

        if (tpstart((TPSTART_T *)tpinfo) == -1){
            printf("tpstart fail tperrno = %d\n", tperrno);
            exit(1);
        }

        if ((sndbuf = (FBUF *)tpalloc("FIELD", NULL, 0)) == NULL) {
            printf("tpalloc failed! errno = %d\n", tperrno);
            tpend();
            exit(1);
        }

        if ((rcvbuf = (FBUF *)tpalloc("FIELD", NULL, 0)) == NULL) {
            printf("tpalloc failed! errno = %d\n", tperrno);
            tpend();
            exit(1);
        }

        ret = case_chlog(argc, argv, sndbuf);
        n = fbput(sndbuf, TIP_OPERATION, "GET", 0);
        n = fbput(sndbuf, TIP_SEGMENT, "ADMINISTRATION", 0);
        n = fbput(sndbuf, TIP_CMD, "CHLOG", 0);
        n = fbput(sndbuf, TIP_NODENAME, nodename, 0);
        n = fbput(sndbuf, TIP_SVGNAME, svgname , 0);
        n = fbput(sndbuf, TIP_SVRNAME, svrname, 0);

        n=tpcall("TIPSVC", (char *)sndbuf, 0, (char **)&rcvbuf, &rcvlen, TPNOFLAGS);
        if (n < 0) {
             printf("tpcall failed! errno = %d[%s]\n", tperrno,
                     tpstrerror(tperrno));
             fbprint(rcvbuf);
             tpfree((char *)sndbuf);
             tpfree((char *)rcvbuf);
             tpend();
             exit(1);
        }

        fbprint(rcvbuf);
        tpfree((char *)sndbuf);
        tpfree((char *)rcvbuf);
        tpend();
}

int case_chlog(int argc2, char *argv2[], FBUF *sndbuf)
{
        int  chlogmdl, loglvl, flags, n=0;
        char  cloglvl[TMAX_NAME_SIZE];
        const int true = 1, false = 0;

        chlogmdl = atoi(argv2[4]);
        if( (chlogmdl != 1) && (chlogmdl != 2) && (chlogmdl != 4) &&
            (chlogmdl != 8)
        {
                printf("couldn't support such a chlogmdl\n");
                exit(1);
        }

        flags = atoi(argv2[5]);
        if( (flags != NFLAG) && (flags != GFLAG) && (flags != VFLAG) )
        {
                printf("couldn't support such a flags\n");
                exit(1);
        }

        loglvl = atoi(argv2[6]);
        if( (loglvl < 1) || (loglvl > 7) )
        {
                printf("couldn't support such a loglvl\n");
                exit(1);
        }

        switch (loglvl)
        {
                case 1 :
                        strcpy(cloglvl, "compact");
                        break;
                case 2 :
                        strcpy(cloglvl, "basic");
                        break;
                case 3 :
                        strcpy(cloglvl, "detail");
                        break;
                case 4 :
                        strcpy(cloglvl, "debug1");
                        break;
                case 5 :
                        strcpy(cloglvl, "debug2");
                        break;
                case 6 :
                        strcpy(cloglvl, "debug3");
                        break;
                case 7 :
                        strcpy(cloglvl, "debug4");
                        break;
        }
        n = fbput(sndbuf, TIP_MODULE, (char *)&chlogmdl, 0);
        n = fbput(sndbuf, TIP_FLAGS, (char *)&flags , 0);
        n = fbput(sndbuf, TIP_LOGLVL, cloglvl , 0);
        return 1;
}

[Result] (TIP_SVR, => DEBUG4)

$ client  xa1 svr23_stat_ins $HOSTNAME 8 1024 7
fkey = 217326601, fname = TIP_ERROR, type = int, value = 0
>>> tmadmin (cfg -v)

         loglvl = DEBUG4

6. Local Recursive Calls

When tpcall() is executed in a server, the recursive service call feature is added. Only tpcall() can make recursive calls through the multicontexting technique in a server. The recursion depth is limited to 8 to prevent an infinite loop.

To use a local recursive call, –D_MCONTEXT must be added to CFLAGS when a server program is compiled and the libsvrmc.so server library must be used instead of libsvr.so.

Server program

The following is an example.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <usrinc/atmi.h>


SVC15004_1(TPSVCINFO *msg)
{
         int     i;
         char    *rcvbuf;
         long    rcvlen;

         if ((rcvbuf = (char *)tpalloc("STRING", NULL, 0)) == NULL)
              printf("rcvbuf tpalloc fail[%s]\n",tpstrerror(tperrno));
         if (tpcall("SVC15004_2", msg->data, 0, &rcvbuf, &rcvlen, 0) == -1)
         {
              printf("tpcall fail [%s]\n", tpstrerror(tperrno));
              tpfree((char *)rcvbuf);
              tpreturn(TPFAIL, 0, 0, 0, 0);
         }

         strcat(rcvbuf, "_Success");

         tpreturn(TPSUCCESS,0,(char *)rcvbuf, 0,0);
}

SVC15004_2(TPSVCINFO *msg)
{
         int     i;
         char    *rcvbuf;
         long    rcvlen;

         if ((rcvbuf = (char *)tpalloc("STRING", NULL, 0)) == NULL)
             printf("rcvbuf tpalloc fail \n");
}

         if (tpcall("SVC15004_3", msg->data, 0, &rcvbuf, &rcvlen, 0) == -1)
         {
             printf("tpcall fail [%s]\n", tpstrerror(tperrno));
             tpfree((char *)rcvbuf);
             tpreturn(TPFAIL, 0, 0, 0, 0);
         }
         strcat(rcvbuf, "_Success");
         tpreturn(TPSUCCESS,0,(char *)rcvbuf, 0,0);
}

SVC15004_3(TPSVCINFO *msg)
{
         int     i;
         char    *rcvbuf;
         long    rcvlen;

         if ((rcvbuf = (char *)tpalloc("STRING", NULL, 0)) == NULL)
              printf("rcvbuf tpalloc fail \n");

         if (tpcall("SVC15004_4", msg->data, 0, &rcvbuf, &rcvlen, 0) == -1)
         {
             printf("tpcall fail [%s]\n", tpstrerror(tperrno));
             tpfree((char *)rcvbuf);
             tpreturn(TPFAIL, 0, 0, 0, 0);
          }

         strcat(rcvbuf, "_Success");
         tpreturn(TPSUCCESS,0,(char *)rcvbuf, 0,0);
}
Makefile

The following is an example.

<Makefile.c.mc>

# Server makefile

TARGET  = $(COMP_TARGET)
APOBJS  = $(TARGET).o
NSDLOBJ = $(TMAXDIR)/lib64/sdl.o

LIBS    = -lsvrmc -lnodb
OBJS    = $(APOBJS) $(SVCTOBJ)

SVCTOBJ = $(TARGET)_svctab.o

CFLAGS  = -O -Ae -w +DSblended +DD64 -D_HP -I$(TMAXDIR) -D_MCONTEXT

APPDIR  = $(TMAXDIR)/appbin
SVCTDIR = $(TMAXDIR)/svct
LIBDIR  = $(TMAXDIR)/lib64

#
.SUFFIXES : .c

.c.o:
        $(CC) $(CFLAGS) -c $<

#
# server compile
#

$(TARGET): $(OBJS)
        $(CC) $(CFLAGS) -L$(LIBDIR) -o $(TARGET) $(OBJS) $(LIBS) $(NSDLOBJ)
        mv $(TARGET) $(APPDIR)/.
        rm -f $(OBJS)

$(APOBJS): $(TARGET).c
        $(CC) $(CFLAGS) -c $(TARGET).c

$(SVCTOBJ):
        cp -f $(SVCTDIR)/$(TARGET)_svctab.c .
        touch ./$(TARGET)_svctab.c
        $(CC) $(CFLAGS) -c ./$(TARGET)_svctab.c

#
clean:
        -rm -f *.o core $(APPDIR)/$(TARGET)