Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Typed CARRAY tests
0003  *
0004  * @file atmisv23.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 
0035 #include <stdio.h>
0036 #include <stdlib.h>
0037 #include <ndebug.h>
0038 #include <atmi.h>
0039 #include <ndrstandard.h>
0040 #include <ubf.h>
0041 #include <test.fd.h>
0042 #include <string.h>
0043 #include "test023.h"
0044 
0045 long M_subs_to_unsibscribe = -1;
0046 
0047 /**
0048  * Receive some carray & reply back with carray, ok?
0049  */
0050 void TEST23_CARRAY(TPSVCINFO *p_svc)
0051 {
0052     int ret = EXSUCCEED;
0053     char *buf = p_svc->data;
0054     char type[16+1]={EXEOS};
0055     int i;
0056     
0057     if (EXFAIL==tptypes(buf, type, NULL))
0058     {
0059         NDRX_LOG(log_error, "TESTERROR: TEST23_CARRAY cannot "
0060                 "determine buffer type");
0061         EXFAIL_OUT(ret);
0062     }
0063     
0064     if (0!=strcmp(type, "CARRAY"))
0065     {
0066         NDRX_LOG(log_error, "TESTERROR: Buffer not CARRAY!");
0067         EXFAIL_OUT(ret);
0068     }
0069     
0070     for (i=0; i<TEST_REQ_SIZE; i++)
0071     {
0072         if (((char)buf[i]) != ((char)i))
0073         {
0074             NDRX_LOG(log_error, "TESTERROR: Buffer pos %d not equal to %d!",
0075                             i, i);
0076             EXFAIL_OUT(ret);
0077         }
0078     }
0079     
0080     if (NULL== (buf = tprealloc(buf, TEST_REPLY_SIZE)))
0081     {
0082         NDRX_LOG(log_error, "TESTERROR: TEST23_CARRAY failed "
0083                 "to realloc the buffer");
0084     }
0085     
0086     /* fill all the buffer with  */
0087     for (i=0; i<TEST_REPLY_SIZE; i++)
0088     {
0089         buf[i]=i%256;
0090     }
0091     
0092     NDRX_LOG(log_debug, "Sending buffer: [%s]", buf);
0093     
0094 out:
0095     
0096     tpreturn(EXSUCCEED==ret?TPSUCCESS:TPFAIL, 0, buf, TEST_REPLY_SIZE, 0L);
0097     
0098 }
0099 
0100 /**
0101  * This should match the regex of caller (extra filter test func)
0102  */
0103 void TEST23 (TPSVCINFO *p_svc)
0104 {
0105     int ret=EXSUCCEED;
0106     
0107 out:
0108 
0109     tpreturn(0, 0, NULL, 0L, 0L);
0110 
0111 }
0112 
0113 /**
0114  * This shall not match the regex of caller (extra filter test func)
0115  */
0116 void TEST23_2(TPSVCINFO *p_svc)
0117 {
0118     long ret;
0119     
0120     NDRX_LOG(log_debug, "TEST23_2 - Called");
0121     
0122     tpreturn(0, 0, NULL, 0L, 0L);
0123 }
0124 
0125 /*
0126  * Do initialization
0127  */
0128 int NDRX_INTEGRA(tpsvrinit)(int argc, char **argv)
0129 {
0130     int ret=EXSUCCEED;
0131     
0132     NDRX_LOG(log_debug, "tpsvrinit called");
0133     TPEVCTL evctl;
0134 
0135     memset(&evctl, 0, sizeof(evctl));
0136 
0137     if (EXSUCCEED!=tpadvertise("TEST23_CARRAY", TEST23_CARRAY))
0138     {
0139         NDRX_LOG(log_error, "Failed to initialize TEST23_CARRAY!");
0140         ret=EXFAIL;
0141     }
0142     else if (EXSUCCEED!=tpadvertise("TEST23", TEST23))
0143     {
0144         NDRX_LOG(log_error, "Failed to initialize TEST23 (first)!");
0145         ret=EXFAIL;
0146     }
0147     else if (EXSUCCEED!=tpadvertise("TEST23_2", TEST23_2))
0148     {
0149         NDRX_LOG(log_error, "Failed to initialize TEST23_2!");
0150         ret=EXFAIL;
0151     }
0152     
0153     if (EXSUCCEED!=ret)
0154     {
0155         goto out;
0156     }
0157 
0158     NDRX_STRCPY_SAFE(evctl.name1, "TEST23");
0159     evctl.flags|=TPEVSERVICE;
0160 
0161     /* Subscribe to event server */
0162     if (EXFAIL==tpsubscribe("TEST23EV", NULL, &evctl, 0L))
0163     {
0164         NDRX_LOG(log_error, "Failed to subscribe TEST23 "
0165                                         "to EV..TEST event failed");
0166         ret=EXFAIL;
0167     }
0168 
0169 #if 0
0170     strcpy(evctl.name1, "TEST23_2");
0171     /* Subscribe to event server */
0172     if (EXFAIL==(M_subs_to_unsibscribe=tpsubscribe("TEST23EV", "Hello (.*) Pluto", &evctl, 0L)))
0173     {
0174         NDRX_LOG(log_error, "Failed to subscribe TEST23 "
0175                                         "to EV..TEST event failed");
0176         ret=EXFAIL;
0177     }
0178 #endif
0179     
0180 out:
0181     return ret;
0182 }
0183 
0184 /**
0185  * Do de-initialization
0186  */
0187 void NDRX_INTEGRA(tpsvrdone)(void)
0188 {
0189     NDRX_LOG(log_debug, "tpsvrdone called");
0190 }
0191 
0192 /* vim: set ts=4 sw=4 et smartindent: */