Back to home page

Enduro/X

 
 

    


0001 /**
0002  *
0003  * @file atmisv31FIRST.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 #include <ndebug.h>
0042 
0043 void TEST31_1ST (TPSVCINFO *p_svc)
0044 {
0045     int ret=EXSUCCEED;
0046     UBFH *p_ub = (UBFH *)p_svc->data;
0047 
0048     if (EXSUCCEED!=tplogsetreqfile((char **)&p_ub, NULL, NULL))
0049     {
0050         NDRX_LOG(log_error, "TESTERROR: Failed to set request file! :%s", tpstrerror(tperrno));
0051         EXFAIL_OUT(ret);
0052     }
0053     
0054     /* Just print the buffer */
0055     tplogprintubf(log_debug, "TEST31_1ST request buffer", p_ub);
0056     
0057     tplog(log_warn, "Hello from TEST31_1ST!");
0058     
0059 
0060 out:
0061 
0062     if (EXSUCCEED==ret)
0063     {
0064         tplog(log_warn, "Request ok, forwarding to 2ND service");
0065         tplogclosereqfile();
0066         tpforward(  "TEST31_2ND",
0067                     (char *)p_ub,
0068                     0L,
0069                     0L);
0070     }
0071     else
0072     {
0073         tplog(log_warn, "Request FAIL, returning...");
0074         tplogclosereqfile();
0075         tpreturn(TPFAIL,
0076                 0L,
0077                 (char *)p_ub,
0078                 0L,
0079                 0L);
0080     }
0081 }
0082 
0083 /**
0084  * Service for setting request file for new request...
0085  * @param p_svc
0086  */
0087 void SETREQFILE(TPSVCINFO *p_svc)
0088 {
0089     int ret = EXSUCCEED;
0090     UBFH *p_ub = (UBFH *)p_svc->data;
0091     char filename[256];
0092     static int req_no = 0;
0093     
0094     req_no++;
0095     
0096     sprintf(filename, "./logs/request_%d.log", req_no);
0097     
0098     /* allocate bit space for new file name to be set */
0099     if (NULL==(p_ub = (UBFH *)tprealloc((char *)p_ub, 4000)))
0100     {
0101         NDRX_LOG(log_error, "TESTERROR: realloc failed: %s", 
0102                 filename, tpstrerror(tperrno));
0103         EXFAIL_OUT(ret);
0104     }
0105     
0106     if (EXSUCCEED!=tplogsetreqfile((char **)&p_ub, filename, NULL))
0107     {
0108         NDRX_LOG(log_error, "TESTERROR: Failed to set request file to [%s]:%s", 
0109                 filename, tpstrerror(tperrno));
0110         EXFAIL_OUT(ret);
0111     }
0112     
0113     tplog(log_debug, "Hello from SETREQFILE!");
0114     
0115     tplogclosereqfile();
0116     
0117     tplog(log_debug, "SETREQFILE closed req file - logging in main");
0118     
0119 out:
0120     tpreturn(  ret==EXSUCCEED?TPSUCCESS:TPFAIL,
0121                 0L,
0122                 (char *)p_ub,
0123                 0L,
0124                 0L);
0125 }
0126 
0127 /**
0128  * Do initialization
0129  */
0130 int NDRX_INTEGRA(tpsvrinit)(int argc, char **argv)
0131 {
0132     NDRX_LOG(log_debug, "tpsvrinit called");
0133     
0134     /* configure main logger */
0135     if (EXSUCCEED!=tplogconfig(LOG_FACILITY_NDRX|LOG_FACILITY_UBF|LOG_FACILITY_TP, 
0136             EXFAIL, "file=./1sv.log tp=5 ndrx=5 ubf=0", "1SRV", NULL))
0137     {
0138         NDRX_LOG(log_error, "TESTERROR: Failed to configure logger!");
0139     }
0140 
0141     if (EXSUCCEED!=tpadvertise("TEST31_1ST", TEST31_1ST))
0142     {
0143         NDRX_LOG(log_error, "TESTERROR: Failed to initialize TEST31_1ST (first)!");
0144     }
0145     else if (EXSUCCEED!=tpadvertise("SETREQFILE", SETREQFILE))
0146     {
0147         NDRX_LOG(log_error, "TESTERROR: Failed to initialize SETREQFILE!");
0148     }
0149     
0150 
0151     return EXSUCCEED;
0152 }
0153 
0154 /**
0155  * Do de-initialization
0156  */
0157 void NDRX_INTEGRA(tpsvrdone)(void)
0158 {
0159     NDRX_LOG(log_debug, "tpsvrdone called");
0160 }
0161 
0162 /* vim: set ts=4 sw=4 et smartindent: */