Back to home page

Enduro/X

 
 

    


0001 /**
0002  *
0003  * @file atmisv28.c
0004  */
0005 /* -----------------------------------------------------------------------------
0006  * Enduro/X Middleware Platform for Distributed Transaction Processing
0007  * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0008  * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0009  * This software is released under one of the following licenses:
0010  * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0011  * See LICENSE file for full text.
0012  * -----------------------------------------------------------------------------
0013  * AGPL license:
0014  *
0015  * This program is free software; you can redistribute it and/or modify it under
0016  * the terms of the GNU Affero General Public License, version 3 as published
0017  * by the Free Software Foundation;
0018  *
0019  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0020  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0021  * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0022  * for more details.
0023  *
0024  * You should have received a copy of the GNU Affero General Public License along 
0025  * with this program; if not, write to the Free Software Foundation, Inc.,
0026  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0027  *
0028  * -----------------------------------------------------------------------------
0029  * A commercial use license is available from Mavimax, Ltd
0030  * contact@mavimax.com
0031  * -----------------------------------------------------------------------------
0032  */
0033 
0034 #include <stdio.h>
0035 #include <stdlib.h>
0036 #include <ndebug.h>
0037 #include <atmi.h>
0038 #include <ndrstandard.h>
0039 #include <ubf.h>
0040 #include <test.fd.h>
0041 
0042 /**
0043  * This service will add T_STRING
0044  * @param p_svc
0045  */
0046 void SVCOK (TPSVCINFO *p_svc)
0047 {
0048     int ret=EXSUCCEED;
0049     UBFH *p_ub = (UBFH *)p_svc->data;
0050     
0051     if (EXSUCCEED!=Bchg(p_ub, T_STRING_FLD, 0, "OK", 0L))
0052     {
0053         NDRX_LOG(log_error, "TESTERROR: Failed to set T_STRING_FLD!");
0054     }
0055 
0056 out:
0057     tpreturn(  ret==EXSUCCEED?TPSUCCESS:TPFAIL,
0058                 0L,
0059                 (char *)p_ub,
0060                 0L,
0061                 0L);
0062 }
0063 
0064 /**
0065  * Fail 'randomly'
0066  * @param p_svc
0067  */
0068 void FAILRND (TPSVCINFO *p_svc)
0069 {
0070     int ret=EXSUCCEED;
0071     static int cnt = 0;
0072     UBFH *p_ub = (UBFH *)p_svc->data;
0073     
0074     cnt++;
0075     
0076     if (1 == (cnt % 4) )
0077     {
0078         ret=EXFAIL;
0079         goto out;
0080     }
0081     
0082     if (EXSUCCEED!=Bchg(p_ub, T_STRING_FLD, 0, "OK", 0L))
0083     {
0084         NDRX_LOG(log_error, "TESTERROR: Failed to set T_STRING_FLD!");
0085     }
0086     
0087     if (!tpgetlev())
0088     {
0089         NDRX_LOG(log_error, "TESTERROR: invocation must be transactional!");
0090     }
0091 
0092 out:
0093     tpreturn(  ret==EXSUCCEED?TPSUCCESS:TPFAIL,
0094                 0L,
0095                 (char *)p_ub,
0096                 0L,
0097                 0L);
0098 }
0099 
0100 /**
0101  * Returns failure to caller
0102  * @param p_svc
0103  */
0104 void SVCFAIL (TPSVCINFO *p_svc)
0105 {
0106     int ret=EXFAIL;
0107     UBFH *p_ub = (UBFH *)p_svc->data;
0108     
0109 out:
0110     tpreturn(  ret==EXSUCCEED?TPSUCCESS:TPFAIL,
0111                 0L,
0112                 (char *)p_ub,
0113                 0L,
0114                 0L);
0115 }
0116 
0117 /**
0118  * Broadcast to the message to the client
0119  */
0120 void CLTBCAST(TPSVCINFO *p_svc)
0121 {
0122     int ret=EXFAIL;
0123     UBFH *p_ub = (UBFH *)p_svc->data;
0124 
0125     if (EXSUCCEED!=tpbroadcast(NULL, NULL, "atmiclt28", (char *)p_ub, 0L, 0))
0126     {
0127         NDRX_LOG(log_error, "TESTERROR: Failed to broadcast: %s", tpstrerror(tperrno));
0128         goto out;
0129     }
0130     
0131 out:
0132     tpreturn(  ret==EXSUCCEED?TPSUCCESS:TPFAIL,
0133                 0L,
0134                 (char *)p_ub,
0135                 0L,
0136                 0L);
0137 }
0138 /*
0139  * Do initialization
0140  */
0141 int NDRX_INTEGRA(tpsvrinit)(int argc, char **argv)
0142 {
0143     int ret = EXSUCCEED;
0144     NDRX_LOG(log_debug, "tpsvrinit called");
0145     
0146     if (EXSUCCEED!=tpopen())
0147     {
0148         NDRX_LOG(log_error, "TESTERROR: Failed to tpopen: %s", tpstrerror(tperrno));
0149         EXFAIL_OUT(ret);
0150     }
0151 
0152     if (EXSUCCEED!=tpadvertise("SVCOK", SVCOK))
0153     {
0154         NDRX_LOG(log_error, "TESTERROR: Failed to initialize SVCOK!");
0155         EXFAIL_OUT(ret);
0156     }
0157     else if (EXSUCCEED!=tpadvertise("SVCFAIL", SVCFAIL))
0158     {
0159         NDRX_LOG(log_error, "TESTERROR: Failed to initialize SVCFAIL!");
0160         EXFAIL_OUT(ret);
0161     }
0162     else if (EXSUCCEED!=tpadvertise("FAILRND", FAILRND))
0163     {
0164         NDRX_LOG(log_error, "TESTERROR: Failed to initialize FAILRND!");
0165         EXFAIL_OUT(ret);
0166     }
0167     else if (EXSUCCEED!=tpadvertise("CLTBCAST", CLTBCAST))
0168     {
0169         NDRX_LOG(log_error, "TESTERROR: Failed to initialize CLTBCAST!");
0170         EXFAIL_OUT(ret);
0171     }
0172     
0173 out:
0174     return ret;
0175     
0176 }
0177 
0178 /**
0179  * Do de-initialization
0180  */
0181 void NDRX_INTEGRA(tpsvrdone)(void)
0182 {
0183     NDRX_LOG(log_debug, "tpsvrdone called");
0184     
0185     if (EXSUCCEED!=tpclose())
0186     {
0187         NDRX_LOG(log_error, "TESTERROR: Failed to tpclose: %s", tpstrerror(tperrno));
0188     }
0189 }
0190 /* vim: set ts=4 sw=4 et smartindent: */