Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Service reply responder
0003  *
0004  * @file atmisv86.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 <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 #include <string.h>
0042 #include <unistd.h>
0043 
0044 /*---------------------------Externs------------------------------------*/
0045 /*---------------------------Macros-------------------------------------*/
0046 /*---------------------------Enums--------------------------------------*/
0047 /*---------------------------Typedefs-----------------------------------*/
0048 /*---------------------------Globals------------------------------------*/
0049 /*---------------------------Statics------------------------------------*/
0050 
0051 exprivate long M_seq = 0;
0052 
0053 /*---------------------------Prototypes---------------------------------*/
0054 
0055 /**
0056  * Sequence validator
0057  */
0058 void SEQVALID (TPSVCINFO *p_svc)
0059 {
0060     int ret = EXSUCCEED;
0061     long l;
0062     UBFH *p_ub = (UBFH *)p_svc->data;
0063     
0064     /* read the sequence field T_LONG_FLD must start from 1 */
0065     if (EXSUCCEED!=Bget(p_ub, T_LONG_FLD, 0, (char *)&l, NULL))
0066     {
0067         NDRX_LOG(log_always, "TESTERROR: T_LONG_FLD is missing!");
0068         EXFAIL_OUT(ret);
0069     }
0070     
0071     /* Validate the sequence of the call: */
0072     if (M_seq+1!=l)
0073     {
0074         NDRX_LOG(log_always, "TESTERROR: Invalid service call sequence: got %ld expected %ld", 
0075                 l, M_seq+1);
0076         userlog("TESTERROR: Invalid service call sequence: got %ld expected %ld", 
0077                 l, M_seq+1);
0078         EXFAIL_OUT(ret);
0079     }
0080     M_seq = l;
0081 
0082 out:
0083     tpreturn(  (EXSUCCEED==ret?TPSUCCESS:TPFAIL),
0084                 0L,
0085                 (char *)p_ub,
0086                 0L,
0087                 0L);
0088 }
0089 
0090 /**
0091  * Standard service entry
0092  */
0093 void FAILSVC (TPSVCINFO *p_svc)
0094 {
0095     UBFH *p_ub = (UBFH *)p_svc->data;
0096 
0097     NDRX_LOG(log_debug, "%s got call", __func__);
0098     
0099     
0100     if (EXSUCCEED!=Bchg(p_ub, T_STRING_FLD, 0, "RSP", 0))
0101     {
0102         NDRX_LOG(log_error, "TESTERROR: failed to update buffer: %s",
0103             Bstrerror(Berror));
0104     }
0105     
0106     
0107 out:
0108     tpreturn(  TPFAIL,
0109                 0L,
0110                 (char *)p_ub,
0111                 0L,
0112                 0L);
0113 }
0114 
0115 /**
0116  * Standard service entry
0117  */
0118 void OKSVC (TPSVCINFO *p_svc)
0119 {
0120     UBFH *p_ub = (UBFH *)p_svc->data;
0121 
0122 out:
0123     tpreturn(  TPSUCCESS,
0124                 0L,
0125                 (char *)p_ub,
0126                 0L,
0127                 0L);
0128 }
0129 
0130 /**
0131  * Standard service entry
0132  */
0133 void TOUT_SLEEP (TPSVCINFO *p_svc)
0134 {
0135     UBFH *p_ub = (UBFH *)p_svc->data;
0136     
0137     sleep(35);
0138 
0139 out:
0140     tpreturn(  TPSUCCESS,
0141                 0L,
0142                 (char *)p_ub,
0143                 0L,
0144                 0L);
0145 }
0146 
0147 /**
0148  * Do initialisation
0149  */
0150 int NDRX_INTEGRA(tpsvrinit)(int argc, char **argv)
0151 {
0152     int ret = EXSUCCEED;
0153     NDRX_LOG(log_debug, "tpsvrinit called");
0154 
0155     if (EXSUCCEED!=tpadvertise("FAILSVC", FAILSVC))
0156     {
0157         NDRX_LOG(log_error, "Failed to initialise FAILSVC!");
0158         EXFAIL_OUT(ret);
0159     }
0160 
0161     if (EXSUCCEED!=tpadvertise("OKSVC", OKSVC))
0162     {
0163         NDRX_LOG(log_error, "Failed to initialise OKSVC!");
0164         EXFAIL_OUT(ret);
0165     }
0166     
0167     if (EXSUCCEED!=tpadvertise("SEQVALID", SEQVALID))
0168     {
0169         NDRX_LOG(log_error, "Failed to initialise SEQVALID!");
0170         EXFAIL_OUT(ret);
0171     }
0172     
0173     
0174     if (EXSUCCEED!=tpadvertise("T_OK", TOUT_SLEEP))
0175     {
0176         NDRX_LOG(log_error, "Failed to initialise T_OK!");
0177         EXFAIL_OUT(ret);
0178     }
0179     
0180     if (EXSUCCEED!=tpadvertise("T_NOK", TOUT_SLEEP))
0181     {
0182         NDRX_LOG(log_error, "Failed to initialise T_NOK!");
0183         EXFAIL_OUT(ret);
0184     }
0185     
0186     if (EXSUCCEED!=tpadvertise("NS_OK", TOUT_SLEEP))
0187     {
0188         NDRX_LOG(log_error, "Failed to initialise NS_OK!");
0189         EXFAIL_OUT(ret);
0190     }
0191     
0192     if (EXSUCCEED!=tpadvertise("ND_OK", TOUT_SLEEP))
0193     {
0194         NDRX_LOG(log_error, "Failed to initialise ND_OK!");
0195         EXFAIL_OUT(ret);
0196     }
0197     
0198     if (EXSUCCEED!=tpadvertise("ND_NOK", TOUT_SLEEP))
0199     {
0200         NDRX_LOG(log_error, "Failed to initialise ND_NOK!");
0201         EXFAIL_OUT(ret);
0202     }
0203     
0204     
0205     if (EXSUCCEED!=tpopen())
0206     {
0207         NDRX_LOG(log_error, "tpopen() failed: %s", tpstrerror(tperrno));
0208         EXFAIL_OUT(ret);
0209     }
0210     
0211 out:
0212     return ret;
0213 }
0214 
0215 /**
0216  * Do de-initialisation
0217  */
0218 void NDRX_INTEGRA(tpsvrdone)(void)
0219 {
0220     NDRX_LOG(log_debug, "tpsvrdone called");
0221     tpclose();
0222 }
0223 
0224 /* vim: set ts=4 sw=4 et smartindent: */