Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Test Enduro/X server dispatch threading - server
0003  *
0004  * @file atmisv75.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 #include <thlock.h>
0044 #include "test75.h"
0045 #include "exassert.h"
0046 
0047 /*---------------------------Externs------------------------------------*/
0048 /*---------------------------Macros-------------------------------------*/
0049 /*---------------------------Enums--------------------------------------*/
0050 /*---------------------------Typedefs-----------------------------------*/
0051 /*---------------------------Globals------------------------------------*/
0052 /*---------------------------Statics------------------------------------*/
0053 exprivate volatile short M_counter = 0; /** thread number */
0054 exprivate __thread short M_thr_id = 0;
0055 MUTEX_LOCKDECL(M_counter_lock);
0056 /*---------------------------Prototypes---------------------------------*/
0057 
0058 /**
0059  * Standard service entry
0060  */
0061 void TESTSV (TPSVCINFO *p_svc)
0062 {
0063     int ret=EXSUCCEED;
0064     char testbuf[1024];
0065     UBFH *p_ub = (UBFH *)p_svc->data;
0066 
0067     NDRX_LOG(log_debug, "%s got call", __func__);
0068 
0069     /* Just print the buffer */
0070     Bprint(p_ub);
0071     
0072     if (EXFAIL==Bget(p_ub, T_STRING_FLD, 0, testbuf, 0))
0073     {
0074         NDRX_LOG(log_error, "TESTERROR: Failed to get T_STRING_FLD: %s", 
0075                  Bstrerror(Berror));
0076         ret=EXFAIL;
0077         goto out;
0078     }
0079     
0080     sleep (1);
0081     
0082     if (0!=strcmp(testbuf, VALUE_EXPECTED))
0083     {
0084         NDRX_LOG(log_error, "TESTERROR: Expected: [%s] got [%s]",
0085             VALUE_EXPECTED, testbuf);
0086         ret=EXFAIL;
0087         goto out;
0088     }
0089     
0090     /* set the thread id back */
0091     if (EXSUCCEED!=Bchg(p_ub, T_SHORT_FLD, 0, (char *)&M_thr_id, 0L))
0092     {
0093         NDRX_LOG(log_error, "TESTERROR: Failed to set T_SHORT_FLD to %d: %s", 
0094                 M_thr_id, Bstrerror(Berror));
0095         ret=EXFAIL;
0096         goto out;
0097     }
0098     
0099 out:
0100     tpreturn(  ret==EXSUCCEED?TPSUCCESS:TPFAIL,
0101                 0L,
0102                 (char *)p_ub,
0103                 0L,
0104                 0L);
0105 }
0106 
0107 /**
0108  * Multi-init from tpacall from thread init
0109  * @param p_svc
0110  */
0111 void MULTI_INIT (TPSVCINFO *p_svc)
0112 {
0113     tpreturn(  TPSUCCESS,
0114                 0L,
0115                 (char *)p_svc->data,
0116                 0L,
0117                 0L);
0118 }
0119 /**
0120  * Do initialisation
0121  */
0122 int tpsvrinit(int argc, char **argv)
0123 {
0124     int ret = EXSUCCEED;
0125     NDRX_LOG(log_debug, "tpsvrinit called");
0126 
0127     if (EXSUCCEED!=tpadvertise("TESTSV", TESTSV))
0128     {
0129         NDRX_LOG(log_error, "Failed to initialise TESTSV!");
0130         EXFAIL_OUT(ret);
0131     }
0132 out:
0133     return ret;
0134 }
0135 
0136 /**
0137  * Do de-initialisation
0138  */
0139 void tpsvrdone(void)
0140 {
0141     NDRX_LOG(log_debug, "tpsvrdone called");
0142 }
0143 
0144 /**
0145  * Do initialisation
0146  */
0147 int tpsvrthrinit(int argc, char **argv)
0148 {
0149     int ret = EXSUCCEED;
0150     
0151     MUTEX_LOCK_V(M_counter_lock);
0152     
0153     M_thr_id = M_counter;
0154     M_counter++;
0155     
0156     MUTEX_UNLOCK_V(M_counter_lock);
0157     
0158     /* advertise here the func... */
0159     NDRX_ASSERT_TP_OUT((EXSUCCEED==tpadvertise("MULTI_INIT", MULTI_INIT)), 
0160             "Advertise fail");
0161     
0162     /* call the service, this will call number of times as number of threads
0163      * we have
0164      */
0165     NDRX_ASSERT_TP_OUT((EXSUCCEED==tpacall("MULTI_INIT", NULL, 0, TPNOREPLY)), 
0166             "Failed to acall MULTI_INIT");
0167     
0168     NDRX_LOG(log_debug, "tpsvrthrinit called argc=[%d] argv[0]=[%s] thr_id=[%hd]", 
0169             argc, argv[0], M_thr_id);
0170     
0171 out:
0172     return ret;
0173 }
0174 
0175 /**
0176  * Do de-initialisation
0177  */
0178 void tpsvrthrdone(void)
0179 {
0180     NDRX_LOG(log_debug, "tpsvrthrdone called");
0181 }
0182 
0183 /* Auto generated system advertise table */
0184 expublic struct tmdsptchtbl_t ndrx_G_tmdsptchtbl[] = {
0185     { NULL, NULL, NULL, 0, 0 }
0186 };
0187 /*---------------------------Prototypes---------------------------------*/
0188 
0189 /**
0190  * Main entry for tmsrv
0191  */
0192 int main( int argc, char** argv )
0193 {
0194     _tmbuilt_with_thread_option=EXTRUE;
0195     struct tmsvrargs_t tmsvrargs =
0196     {
0197         &tmnull_switch,
0198         &ndrx_G_tmdsptchtbl[0],
0199         0,
0200         tpsvrinit,
0201         tpsvrdone,
0202         NULL,
0203         NULL,
0204         NULL,
0205         NULL,
0206         NULL,
0207         tpsvrthrinit,
0208         tpsvrthrdone
0209     };
0210     
0211     return( _tmstartserver( argc, argv, &tmsvrargs ));
0212     
0213 }
0214 
0215 
0216 /* vim: set ts=4 sw=4 et smartindent: */