Examples

This chapter describes a Makefile and a Tmax XA service call example.

1. Tmax XA Service Call Example

/* Tmax xa switch openinfo */
#define OPENINFO
"host=192.168.1.43:7000+dbglvl=1+timeout=10"
/* Tmax xa switch closeinfo */
#define CLOSEINFO       ""
extern struct xa_switch_t tmaxxaosw;
struct xa_switch_t _xasw;
int _xa_load(int xaoption)
{
        _xasw.name[0] = 0;
        _xasw = tmaxxaosw;
        if (_xasw.name[0] == 0)
            return -1;
        return 1;
}
int main(int argc, char **argv)
{
    ….
    XID xid;

   // Load XA information
    ret = _xa_load(0);
    if (ret < 0) {
        error processing…
    }

    // xa open
    ret = xa_open(OPENINFO, rmid, TMNOFLAGS);
    if (ret < 0) {
        error processing…
    }
    ….

    // xa start
    ret = xa_start(&xid, rmid, TMNOFLAGS);
    if (ret < 0) {
        error processing…
}

    // Tmax xa service call
    ret = call_tmax(“SVCA”, sndbuf, rcvbuf);
    if (ret < 0) {
        error processing…
    }

    // xa end
    ret = xa_end(&xid, rmid, TMSUSPEND);
    if (ret < 0) {
        error processing…
    }

    // xa start
    ret = xa_start(&xid2, rmid, TMRESUME | TMJOIN);
    if (ret < 0) {
        error processing…
    }
    /* function that includes tpcall */

    // Tmax xa service call
    ret = call_tmax(svcname, sndbuf, rcvbuf);
    if (ret < 0) {
         error processing…
    }

    // xa end
    ret = xa_end(&xid2, rmid, TMSUCCESS);
    if (ret < 0) {
        error processing…
    }

    // xa prepare
    ret = xa_prepare(&xid, rmid, TMNOFLAGS);
    if (ret < 0) {
        error processing…
    }
    // xa prepare
    ret = xa_prepare(&xid2, rmid, TMNOFLAGS);
    if (ret < 0) {
        error processing…
    }
        else if (ret == XA_RDONLY) {
        // xa commit
        ret = xa_commit(&xid, rmid, TMNOFLAGS);
        if (ret < 0) {
            error processing…
        }
    }
    else {
        ret = xa_commit(&xid, rmid, TMNOFLAGS);
        if (ret < 0) {
            error processing…
        }
        ret = xa_commit(&xid2, rmid, TMNOFlAGS);
        if (ret < 0) {
            error processing…
        }
    }

    // xa close
    ret = xa_close(CLOSEINFO, rmid, TMNOFLAGS);
    if (ret < 0) {
         error processing…
    }
…
}

// Tmax service call routine
int call_tmax(char *svcname, char * sndbuf, char * rcvbuf)
{
    …
    ret = tpcall(svcname, (char *)sndbuf, strlen(sndbuf), (char **)&rcvbuf,
                (long *)&rcvlen, TPNOFLAGS);
    if(ret < 0) {
         error processing…
    }
    …
}

2. Makefile

# makefile
TARGET  = $(COMP_TARGET)
APOBJS  = $(TARGET).o

TMAXLIBD= $(TMAXDIR)/lib64

TMAXLIBS= -ltxa
# for hp-pa
CFLAGS = -g -Ae +DA2.0W +DD64 +DS2.0 -O -I$(TMAXDIR)

#
.SUFFIXES : .c

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

#
# client compile
#

$(TARGET): $(APOBJS)
#       proc iname=$(TARGET) include=$(TMAXDIR)
        $(CC) $(CFLAGS) -L$(TMAXLIBD) -o $(TARGET) $(APOBJS) $(TMAXLIBS)

$(APOBJS): $(TARGET).c
#       proc iname=$(TARGET) include=$(TMAXDIR)
        $(CC) $(CFLAGS) -c $(TARGET).c
#
clean:
        -rm -f *.o core $(TARGET)