Back to home page

Enduro/X

 
 

    


0001 /**
0002  *
0003  * @file atmisv.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 
0042 
0043 void TESTSVFN (TPSVCINFO *p_svc);
0044 
0045 /**
0046  * Advertise the service.
0047  * @param p_svc
0048  */
0049 void DOADV(TPSVCINFO *p_svc)
0050 {
0051     int ret=EXSUCCEED;
0052     UBFH *p_ub = (UBFH *)p_svc->data;
0053     
0054     /* Advertise test service */
0055     ret=tpadvertise("TESTSVFN", TESTSVFN);
0056 
0057     tpreturn(  ret==EXSUCCEED?TPSUCCESS:TPFAIL,
0058                 0L,
0059                 (char *)p_ub,
0060                 0L,
0061                 0L);
0062 }
0063 
0064 /**
0065  * Undvertise the service!
0066  * @param p_svc
0067  */
0068 void UNADV (TPSVCINFO *p_svc)
0069 {
0070     int ret=EXSUCCEED;
0071     UBFH *p_ub = (UBFH *)p_svc->data;
0072     
0073     
0074     /* Unadvertise test service */
0075     ret=tpunadvertise("TESTSVFN");
0076 
0077     tpreturn(  ret==EXSUCCEED?TPSUCCESS:TPFAIL,
0078                 0L,
0079                 (char *)p_ub,
0080                 0L,
0081                 0L);
0082 }
0083 
0084 /*
0085  * This is test service!
0086  */
0087 void TESTSVFN (TPSVCINFO *p_svc)
0088 {
0089     int ret=EXSUCCEED;
0090 
0091     char *str = "THIS IS TEST - OK!";
0092 
0093     UBFH *p_ub = (UBFH *)p_svc->data;
0094 
0095     NDRX_LOG(log_debug, "TESTSVFN got call");
0096 
0097     /* Just print the buffer */
0098     Bprint(p_ub);
0099 
0100     if (NULL==(p_ub = (UBFH *)tprealloc((char *)p_ub, 4096))) /* allocate some stuff for more data to put in  */
0101     {
0102         ret=EXFAIL;
0103         goto out;
0104     }
0105 
0106     if (EXFAIL==Bchg(p_ub, T_STRING_FLD, 0, (char *)str, 0))
0107     {
0108         ret=EXFAIL;
0109         goto out;
0110     }
0111 
0112 out:
0113     tpreturn(  ret==EXSUCCEED?TPSUCCESS:TPFAIL,
0114                 0L,
0115                 (char *)p_ub,
0116                 0L,
0117                 0L);
0118 }
0119 
0120 /*
0121  * Do initialization
0122  */
0123 int NDRX_INTEGRA(tpsvrinit)(int argc, char **argv)
0124 {
0125     int ret = EXSUCCEED;
0126     NDRX_LOG(log_debug, "tpsvrinit called");
0127 
0128     if (EXSUCCEED!=tpadvertise("DOADV", DOADV))
0129     {
0130         NDRX_LOG(log_error, "Failed to initialize DOADV!");
0131         EXFAIL_OUT(ret);
0132     }
0133     
0134     /* OK continue as normal */
0135     
0136     if (EXSUCCEED!=tpadvertise("UNADV", UNADV))
0137     {
0138         NDRX_LOG(log_error, "Failed to initialize UNADV (first)!");
0139         EXFAIL_OUT(ret);
0140     }
0141     
0142     NDRX_LOG(log_debug, "Checking advertise exceptions:");
0143     
0144     
0145         /* Do it twice..., same func all OK */
0146     if (EXSUCCEED!=tpadvertise("DOADV", DOADV))
0147     {
0148         NDRX_LOG(log_error, "Failed to initialize DOADV!");
0149         EXFAIL_OUT(ret);
0150     }
0151     
0152     /* Do it twice..., ptrs different -> match error */
0153     if (EXSUCCEED==tpadvertise("DOADV", UNADV))
0154     {
0155         NDRX_LOG(log_error, "TESTERROR: re-advertise different func must fail!");
0156         EXFAIL_OUT(ret);
0157     }
0158     
0159     if (TPEMATCH!=tperrno)
0160     {
0161         NDRX_LOG(log_error, "TESTERROR: Expected %d (TPEMATCH) but got %d err!",
0162                 TPEMATCH, tperrno);
0163         EXFAIL_OUT(ret);
0164     }
0165     
0166     /* try empty */
0167     if (EXSUCCEED==tpadvertise("", UNADV))
0168     {
0169         NDRX_LOG(log_error, "TESTERROR: Empty advertise not allowed");
0170         EXFAIL_OUT(ret);
0171     }
0172     
0173     if (TPEINVAL!=tperrno)
0174     {
0175         NDRX_LOG(log_error, "TESTERROR: Expected %d (TPEINVAL) but got %d err!",
0176                 TPEINVAL, tperrno);
0177         EXFAIL_OUT(ret);
0178     }
0179     
0180     /* try NULL */
0181     if (EXSUCCEED==tpadvertise(NULL, UNADV))
0182     {
0183         NDRX_LOG(log_error, "TESTERROR: NULL advertise not allowed");
0184         EXFAIL_OUT(ret);
0185     }
0186     
0187     if (TPEINVAL!=tperrno)
0188     {
0189         NDRX_LOG(log_error, "TESTERROR: Expected %d (TPEINVAL) but got %d err!",
0190                 TPEINVAL, tperrno);
0191         EXFAIL_OUT(ret);
0192     }
0193     
0194     /* try too long name  */
0195     if (EXSUCCEED==tpadvertise("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB", UNADV))
0196     {
0197         NDRX_LOG(log_error, "TESTERROR: Must fail with too long svcnm");
0198         EXFAIL_OUT(ret);
0199     }
0200     
0201     if (TPEINVAL!=tperrno)
0202     {
0203         NDRX_LOG(log_error, "TESTERROR: Expected %d (TPEINVAL) but got %d err!",
0204                 TPEINVAL, tperrno);
0205         EXFAIL_OUT(ret);
0206     }
0207     
0208     
0209     /* try long name */
0210     if (EXSUCCEED!=tpadvertise("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", UNADV))
0211     {
0212         NDRX_LOG(log_error, "TESTERROR: Long name (30 symb) shall be OK!");
0213         EXFAIL_OUT(ret);
0214     }
0215 
0216     /* try NULL func  */
0217     if (EXSUCCEED==tpadvertise("AAAAAAAAAA", NULL))
0218     {
0219         NDRX_LOG(log_error, "TESTERROR: Null func adv shall fail");
0220         EXFAIL_OUT(ret);
0221     }
0222     
0223     if (TPEINVAL!=tperrno)
0224     {
0225         NDRX_LOG(log_error, "TESTERROR: Expected %d (TPEINVAL) but got %d err!",
0226                 TPEINVAL, tperrno);
0227         EXFAIL_OUT(ret);
0228     }
0229 
0230     
0231     
0232 out:
0233     return ret;
0234 }
0235 
0236 /**
0237  * Do de-initialization
0238  */
0239 void NDRX_INTEGRA(tpsvrdone)(void)
0240 {
0241     NDRX_LOG(log_debug, "tpsvrdone called");
0242 }
0243 /* vim: set ts=4 sw=4 et smartindent: */