Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief TMSRV State Driving verification - client
0003  *
0004  * @file atmiclt87.c
0005  */
0006 /* -----------------------------------------------------------------------------
0007  * Enduro/X Middleware Platform for Distributed Transaction Processing
0008  * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0009  * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0010  * This software is released under one of the following licenses:
0011  * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0012  * See LICENSE file for full text.
0013  * -----------------------------------------------------------------------------
0014  * AGPL license:
0015  * 
0016  * This program is free software; you can redistribute it and/or modify it under
0017  * the terms of the GNU Affero General Public License, version 3 as published
0018  * by the Free Software Foundation;
0019  *
0020  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0021  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0022  * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0023  * for more details.
0024  *
0025  * You should have received a copy of the GNU Affero General Public License along 
0026  * with this program; if not, write to the Free Software Foundation, Inc., 
0027  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0028  *
0029  * -----------------------------------------------------------------------------
0030  * A commercial use license is available from Mavimax, Ltd
0031  * contact@mavimax.com
0032  * -----------------------------------------------------------------------------
0033  */
0034 #include <string.h>
0035 #include <stdio.h>
0036 #include <stdlib.h>
0037 #include <memory.h>
0038 #include <math.h>
0039 
0040 #include <atmi.h>
0041 /*---------------------------Externs------------------------------------*/
0042 /*---------------------------Macros-------------------------------------*/
0043 /*---------------------------Enums--------------------------------------*/
0044 /*---------------------------Typedefs-----------------------------------*/
0045 /*---------------------------Globals------------------------------------*/
0046 /*---------------------------Statics------------------------------------*/
0047 /*---------------------------Prototypes---------------------------------*/
0048 
0049 /**
0050  * Do the test call to the server
0051  */
0052 int main(int argc, char** argv)
0053 {
0054     int ret = 0;
0055     char *odata=NULL;
0056     long olen;
0057     int do_tran = EXTRUE;
0058     
0059     
0060     if (argc>1 && argv[1][0]=='N')
0061     {
0062         do_tran=EXFALSE;
0063     }
0064         
0065     if (0!=tpopen())
0066     {
0067         fprintf(stderr, "Failed to topopen: %s\n", tpstrerror(tperrno));
0068         ret=-1;
0069         goto out;
0070     }
0071     
0072     if (do_tran && 0!=tpbegin(15, 0))
0073     {
0074         fprintf(stderr, "Failed to tpbegin: %s\n", tpstrerror(tperrno));
0075         ret=-1;
0076         goto out;
0077     }
0078     
0079     /* custom service */
0080     if (argc>2)
0081     {
0082         if (0==strcmp(argv[2], "SUSPEND"))
0083         {
0084             TPTRANID tid;
0085             
0086             if (0!=(ret=tpsuspend (&tid, 0)))
0087             {
0088                 fprintf(stdout, "Failed to tpsuspend: %s (ret=%d)\n", tpstrerror(tperrno), ret);
0089                 ret=-1;
0090                 goto out;
0091             }
0092             
0093             /* lets resume... */
0094             if (0!=(ret=tpresume (&tid, 0)))
0095             {
0096                 fprintf(stdout, "Failed to tpresume: %s (ret=%d)\n", tpstrerror(tperrno), ret);
0097                 ret=-1;
0098                 goto out;
0099             }
0100             
0101         }
0102         else if (0!=(ret=tpcall(argv[2], NULL, 0, &odata, &olen, 0)))
0103         {
0104             fprintf(stdout, "Failed to tpcall: %s (ret=%d)\n", tpstrerror(tperrno), ret);
0105             ret=-1;
0106             goto out;
0107         }
0108     }
0109     else
0110     {
0111         if (0!=(ret=tpcall("TESTSV1", NULL, 0, &odata, &olen, 0)))
0112         {
0113             fprintf(stdout, "Failed to tpcall: %s (ret=%d)\n", tpstrerror(tperrno), ret);
0114             ret=-1;
0115             goto out;
0116         }
0117     }
0118     
0119     if (do_tran && argc>1 && argv[1][0]=='A')
0120     {
0121         if (0!=tpabort(0))
0122         {
0123             fprintf(stdout, "TPABORT: %s\n", tpstrerror(tperrno));
0124             ret=-1;
0125             goto out;
0126         }
0127         else
0128         {
0129             fprintf(stdout, "TPABORT OK\n");
0130         }
0131     }
0132     else if (do_tran && tpgetlev())
0133     {
0134         if (0!=tpcommit(0))
0135         {
0136             fprintf(stdout, "TPCOMMIT: %s\n", tpstrerror(tperrno));
0137             ret=-1;
0138             goto out;
0139         }
0140         else
0141         {
0142             fprintf(stdout, "TPCOMMIT OK\n");
0143         }
0144     }
0145     
0146 out:
0147     tpterm();
0148     tpclose();
0149     fprintf(stderr, "Exit with %d\n", ret);
0150 
0151     return ret;
0152 }
0153 
0154 /* vim: set ts=4 sw=4 et smartindent: */