Back to home page

Enduro/X

 
 

    


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