Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief TPEXIT and tpexit() tests - server
0003  *
0004  * @file atmisv80.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 "test80.h"
0044 #include <ndrxdiag.h>
0045 #include <pthread.h>
0046 /*---------------------------Externs------------------------------------*/
0047 /*---------------------------Macros-------------------------------------*/
0048 /*---------------------------Enums--------------------------------------*/
0049 /*---------------------------Typedefs-----------------------------------*/
0050 /*---------------------------Globals------------------------------------*/
0051 /*---------------------------Statics------------------------------------*/
0052 /*---------------------------Prototypes---------------------------------*/
0053 
0054 exprivate pthread_t M_shutdown_thread;
0055 exprivate int M_has_shutdown_thread = EXFALSE;
0056 
0057 /**
0058  * Standard service entry
0059  */
0060 void TESTSV (TPSVCINFO *p_svc)
0061 {
0062     int ret=EXSUCCEED;
0063     char testbuf[1024];
0064     UBFH *p_ub = (UBFH *)p_svc->data;
0065 
0066     NDRX_LOG(log_debug, "%s got call", __func__);
0067 
0068     /* Just print the buffer */
0069     Bprint(p_ub);
0070     
0071     if (EXFAIL==Bget(p_ub, T_STRING_FLD, 0, testbuf, 0))
0072     {
0073         NDRX_LOG(log_error, "TESTERROR: Failed to get T_STRING_FLD: %s", 
0074                  Bstrerror(Berror));
0075         ret=EXFAIL;
0076         goto out;
0077     }
0078     
0079     if (0!=strcmp(testbuf, VALUE_EXPECTED))
0080     {
0081         NDRX_LOG(log_error, "TESTERROR: Expected: [%s] got [%s]",
0082             VALUE_EXPECTED, testbuf);
0083         ret=EXFAIL;
0084         goto out;
0085     }
0086         
0087     
0088 out:
0089     tpreturn(  TPEXIT,
0090                 0L,
0091                 (char *)p_ub,
0092                 0L,
0093                 0L);
0094 }
0095 
0096 /**
0097  * Do the shutdown for posix thread
0098  * @param arg
0099  * @return 
0100  */
0101 exprivate void * shutdown_thread_func(void* arg)
0102 {
0103     sleep(1);
0104     tpinit(NULL);
0105     tpexit();
0106     tpterm();
0107     return NULL;
0108 }
0109 
0110 /**
0111  * Standard service entry
0112  */
0113 void TESTSV2 (TPSVCINFO *p_svc)
0114 {
0115     int ret = EXSUCCEED;
0116     
0117     pthread_attr_t pthread_custom_attr;
0118     pthread_attr_init(&pthread_custom_attr);
0119     
0120     ndrx_platf_stack_set(&pthread_custom_attr);
0121     
0122     if (EXSUCCEED!=(ret=pthread_create(&M_shutdown_thread, &pthread_custom_attr, 
0123             &shutdown_thread_func, NULL)))
0124     {
0125         NDRX_PLATF_DIAG(NDRX_DIAG_PTHREAD_CREATE, errno, "shutdown_thread_func thread");
0126     }
0127     
0128     tpreturn(  TPFAIL,
0129             0L,
0130             NULL,
0131             0L,
0132             0L);
0133 }
0134 
0135 /**
0136  * Do initialisation
0137  */
0138 int NDRX_INTEGRA(tpsvrinit)(int argc, char **argv)
0139 {
0140     int ret = EXSUCCEED;
0141     NDRX_LOG(log_debug, "tpsvrinit called");
0142 
0143     if (EXSUCCEED!=tpadvertise("TESTSV", TESTSV))
0144     {
0145         NDRX_LOG(log_error, "Failed to initialise TESTSV!");
0146         EXFAIL_OUT(ret);
0147     }
0148     
0149     if (EXSUCCEED!=tpadvertise("TESTSV2", TESTSV2))
0150     {
0151         NDRX_LOG(log_error, "Failed to initialise TESTSV2!");
0152         EXFAIL_OUT(ret);
0153     }
0154     
0155 out:
0156     return ret;
0157 }
0158 
0159 /**
0160  * Do de-initialisation
0161  */
0162 void NDRX_INTEGRA(tpsvrdone)(void)
0163 {
0164     
0165     if (M_has_shutdown_thread)
0166     {
0167         pthread_join(M_shutdown_thread, NULL);
0168     }
0169     
0170     NDRX_LOG(log_debug, "tpsvrdone called");
0171     
0172 }
0173 
0174 /* vim: set ts=4 sw=4 et smartindent: */