Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Dispatch thread xa on cluster, null switch, buildtools - server
0003  *  We need: OKTX->OKTX2, FAILTX->FAILTX2, NOTX->NOTX2. The atmi client from threads shall call
0004  *  these services number of times
0005  *
0006  * @file atmisv76.c
0007  */
0008 /* -----------------------------------------------------------------------------
0009  * Enduro/X Middleware Platform for Distributed Transaction Processing
0010  * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0011  * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0012  * This software is released under one of the following licenses:
0013  * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0014  * See LICENSE file for full text.
0015  * -----------------------------------------------------------------------------
0016  * AGPL license:
0017  * 
0018  * This program is free software; you can redistribute it and/or modify it under
0019  * the terms of the GNU Affero General Public License, version 3 as published
0020  * by the Free Software Foundation;
0021  *
0022  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0023  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0024  * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0025  * for more details.
0026  *
0027  * You should have received a copy of the GNU Affero General Public License along 
0028  * with this program; if not, write to the Free Software Foundation, Inc., 
0029  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0030  *
0031  * -----------------------------------------------------------------------------
0032  * A commercial use license is available from Mavimax, Ltd
0033  * contact@mavimax.com
0034  * -----------------------------------------------------------------------------
0035  */
0036 #include <stdio.h>
0037 #include <stdlib.h>
0038 #include <ndebug.h>
0039 #include <atmi.h>
0040 #include <ndrstandard.h>
0041 #include <ubf.h>
0042 #include <test.fd.h>
0043 #include <string.h>
0044 #include <unistd.h>
0045 #include <exassert.h>
0046 #include "test76.h"
0047 
0048 /*---------------------------Externs------------------------------------*/
0049 /*---------------------------Macros-------------------------------------*/
0050 /*---------------------------Enums--------------------------------------*/
0051 /*---------------------------Typedefs-----------------------------------*/
0052 /*---------------------------Globals------------------------------------*/
0053 /*---------------------------Statics------------------------------------*/
0054 /*---------------------------Prototypes---------------------------------*/
0055 
0056 /**
0057  * Add transaction flag
0058  * @param p_ub buffer where to add
0059  * @return EXSCUCEED/EXFAIL
0060  */
0061 exprivate int add_tx_flag(UBFH *p_ub)
0062 {
0063     int ret = EXSUCCEED;
0064     
0065     if (tpgetlev())
0066     {
0067         NDRX_ASSERT_UBF_OUT((EXSUCCEED==Badd(p_ub, T_STRING_FLD, "INTX", 0)), 
0068                 "Failed to add T_STRING_FLD");
0069     }
0070     else
0071     {
0072         NDRX_ASSERT_UBF_OUT((EXSUCCEED==Badd(p_ub, T_STRING_FLD, "NOTX", 0)), 
0073                 "Failed to add T_STRING_FLD");
0074     }
0075     
0076 out:
0077     return ret;    
0078 }
0079 
0080 /**
0081  * Second service returns OK or fail
0082  */
0083 void SVC2 (TPSVCINFO *p_svc)
0084 {
0085     int ret=EXSUCCEED;
0086     UBFH *p_ub = (UBFH *)p_svc->data;
0087     
0088     NDRX_LOG(log_debug, "%s got call", __func__);
0089     
0090     /* realloc the buffer */
0091     p_ub = (UBFH *)tprealloc((char *)p_ub, 1024);
0092     
0093     NDRX_ASSERT_TP_OUT((NULL!=p_ub), "Failed to realloc");
0094     
0095     /* add transaction flag */
0096     if (EXSUCCEED!=add_tx_flag(p_ub))
0097     {
0098         EXFAIL_OUT(ret);
0099     }
0100     
0101     /* check the service is it failure or not? */
0102     
0103     if (NULL!=strstr(p_svc->name, "FAIL"))
0104     {
0105         ret=EXFAIL;
0106     }
0107     
0108 out:
0109     
0110     tpreturn(  EXSUCCEED==ret?TPSUCCESS:TPFAIL,
0111                     0L,
0112                     (char *)p_ub,
0113                     0L,
0114                     0L);
0115 }
0116 
0117 /**
0118  * Standard service entry.
0119  * Forward to OK returned. Add to buffer infos that we are in transaction
0120  */
0121 void SVC1 (TPSVCINFO *p_svc)
0122 {
0123     int ret=EXSUCCEED;
0124     UBFH *p_ub = (UBFH *)p_svc->data;
0125     char svcnm2[MAXTIDENT+1];
0126     long rsplen;
0127     
0128     NDRX_LOG(log_debug, "%s got call", __func__);
0129     
0130     /* realloc the buffer */
0131     
0132     p_ub = (UBFH *)tprealloc((char *)p_ub, 1024);
0133     
0134     NDRX_ASSERT_TP_OUT((NULL!=p_ub), "Failed to realloc");
0135     
0136     /* add transaction flag */
0137     if (EXSUCCEED!=add_tx_flag(p_ub))
0138     {
0139         EXFAIL_OUT(ret);
0140     }
0141     
0142     /* call target service, ignore result we will check buffer later
0143      * and also transaction shall be marked for failure if failed 
0144      */
0145     
0146     snprintf(svcnm2, sizeof(svcnm2), "%s2", p_svc->name);
0147     tpcall(svcnm2, (char *)p_ub, 0, (char **)&p_ub, &rsplen, 0);
0148     
0149 out:
0150 
0151     tpreturn(  EXSUCCEED==ret?TPSUCCESS:TPFAIL,
0152                 0L,
0153                 (char *)p_ub,
0154                 0L,
0155                 0L);
0156 }
0157 
0158 /* system advertise table */
0159 expublic struct tmdsptchtbl_t ndrx_G_tmdsptchtbl[] = {
0160     { "TXOK", "SVC1", SVC1, 0, 0 }
0161     ,{ "TXFAIL", "SVC1", SVC1, 0, 0 }
0162     ,{ "NOTX", "SVC1", SVC1, 0, 0 }
0163     ,{ "TXOK2", "SVC2", SVC2, 0, 0 }
0164     ,{ "TXFAIL2", "SVC2", SVC2, 0, 0 }
0165     ,{ "NOTX2", "SVC2", SVC2, 0, 0 }
0166     ,{ NULL, NULL, NULL, 0, 0 }
0167 };
0168 
0169 /**
0170  * Main entry for tmsrv
0171  */
0172 int main( int argc, char** argv )
0173 {
0174     _tmbuilt_with_thread_option=EXTRUE;
0175     struct tmsvrargs_t tmsvrargs =
0176     {
0177         &tmnull_switch,
0178         &ndrx_G_tmdsptchtbl[0],
0179         0,
0180         tpsvrinit,
0181         tpsvrdone,
0182         NULL,
0183         NULL,
0184         NULL,
0185         NULL,
0186         NULL,
0187         tpsvrthrinit,
0188         tpsvrthrdone
0189     };
0190     
0191     return( _tmstartserver( argc, argv, &tmsvrargs ));
0192     
0193 }
0194 
0195 /* vim: set ts=4 sw=4 et smartindent: */