Back to home page

Enduro/X

 
 

    


0001 #include <string.h>
0002 #include <stdio.h>
0003 #include <stdlib.h>
0004 #include <memory.h>
0005 #include <math.h>
0006 
0007 #include <atmi.h>
0008 #include <ubf.h>
0009 #include <bank.fd.h>
0010 
0011 #define SUCCEED     0
0012 #define FAIL        -1
0013 
0014 /**
0015  * Do the test call to the server
0016  */
0017 int main(int argc, char** argv) {
0018 
0019     int ret=SUCCEED;
0020     UBFH *p_ub;
0021     long rsplen;
0022     double balance;
0023     
0024     /* allocate the call buffer */
0025     if (NULL== (p_ub = (UBFH *)tpalloc("UBF", NULL, 1024)))
0026     {
0027         fprintf(stderr, "Failed to realloc the UBF buffer - %s\n", 
0028             tpstrerror(tperrno));
0029         ret=FAIL;
0030         goto out;
0031     }
0032     
0033     /* Set the data */
0034     if (SUCCEED!=Badd(p_ub, T_ACCNUM, "ACC00000000001", 0) ||
0035         SUCCEED!=Badd(p_ub, T_ACCCUR, "USD", 0))
0036     {
0037         fprintf(stderr, "Failed to get T_ACCNUM[0]! -  %s\n", 
0038             Bstrerror(Berror));
0039         ret=FAIL;
0040         goto out;
0041     }
0042     
0043     /* Call the server */
0044     if (FAIL == tpcall("BALANCE", (char *)p_ub, 0L, (char **)&p_ub, &rsplen,0))
0045     {
0046         fprintf(stderr, "Failed to call BALANCE - %s\n", 
0047             tpstrerror(tperrno));
0048         
0049         ret=FAIL;
0050         goto out;
0051     }
0052     
0053     /* Read the balance field */
0054     
0055     if (SUCCEED!=Bget(p_ub, T_AMTAVL, 0, (char *)&balance, 0L))
0056     {
0057         fprintf(stderr, "Failed to get T_AMTAVL[0]! -  %s\n", 
0058             Bstrerror(Berror));
0059         ret=FAIL;
0060         goto out;
0061     }
0062     
0063     printf("Account balance is: %.2lf USD\n", balance);
0064     
0065 out:
0066     /* free the buffer */
0067     if (NULL!=p_ub)
0068     {
0069         tpfree((char *)p_ub);
0070     }
0071     
0072     /* Terminate ATMI session */
0073     tpterm();
0074     return ret;
0075 }