Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Buffer type switch + null - server
0003  *
0004  * @file atmisv64.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 "test64.h"
0044 #include <tpadm.h>
0045 #include <extest.h>
0046 #include <typed_buf.h>
0047 
0048 /*---------------------------Externs------------------------------------*/
0049 /*---------------------------Macros-------------------------------------*/
0050 /*---------------------------Enums--------------------------------------*/
0051 /*---------------------------Typedefs-----------------------------------*/
0052 /*---------------------------Globals------------------------------------*/
0053 /*---------------------------Statics------------------------------------*/
0054 /*---------------------------Prototypes---------------------------------*/
0055 
0056 /**
0057  * Provides null response back. No matter of request buffer...
0058  * @param p_svc request infos
0059  */
0060 void NULLRSP(TPSVCINFO *p_svc)
0061 {
0062     tpreturn(TPSUCCESS, 0, NULL, 0, 0L);
0063 }
0064 
0065 /**
0066  * JSON responder
0067  * @param p_svc
0068  */
0069 void JSONRSP(TPSVCINFO *p_svc)
0070 {
0071     char *data = NULL;
0072     int ret = TPSUCCESS;
0073     
0074     if (NULL==(data = tpalloc("JSON", NULL, 100)))
0075     {
0076         NDRX_LOG(log_error, "TESTERROR ! Failed to alloc JSON data!");
0077         ret = TPFAIL;
0078         goto out;
0079     }
0080     
0081     strcpy(data, "{}");
0082     
0083 out:
0084     
0085     tpreturn(ret, 0, data, 0, 0L);
0086 }
0087 
0088 /**
0089  * String responder
0090  * @param p_svc
0091  */
0092 void STRINGRSP(TPSVCINFO *p_svc)
0093 {
0094     char *data = NULL;
0095     int ret = TPSUCCESS;
0096     
0097     if (NULL==(data = tpalloc("STRING", NULL, 100)))
0098     {
0099         NDRX_LOG(log_error, "TESTERROR ! Failed to alloc STRING data!");
0100         ret = TPFAIL;
0101         goto out;
0102     }
0103     
0104     strcpy(data, "WORLD");
0105     
0106 out:
0107     
0108     tpreturn(ret, 0, data, 0, 0L);
0109 }
0110 
0111 /**
0112  * Carray responder
0113  * @param p_svc
0114  */
0115 void CARRAYRSP(TPSVCINFO *p_svc)
0116 {
0117     char *data = NULL;
0118     int ret = TPSUCCESS;
0119     
0120     if (NULL==(data = tpalloc("CARRAY", NULL, 100)))
0121     {
0122         NDRX_LOG(log_error, "TESTERROR ! Failed to alloc CARRAY data!");
0123         ret = TPFAIL;
0124         goto out;
0125     }
0126     
0127     strcpy(data, "SPACE");
0128     
0129 out:
0130     
0131     tpreturn(ret, 0, data, strlen(data), 0L);
0132 }
0133 
0134 /**
0135  * VIEW responder
0136  * @param p_svc
0137  */
0138 void VIEWRSP(TPSVCINFO *p_svc)
0139 {
0140     int ret = TPSUCCESS;   
0141     struct UBTESTVIEW2 *v = NULL;
0142     
0143     
0144     if (NULL==(v = (struct UBTESTVIEW2 *)tpalloc("VIEW", "UBTESTVIEW2", 
0145             sizeof(struct UBTESTVIEW2))))
0146     {
0147         NDRX_LOG(log_error, "TESTERROR ! Failed to alloc UBTESTVIEW2 data!");
0148         ret = TPFAIL;
0149         goto out;
0150     }
0151     
0152     memset(v, 0, sizeof(*v));
0153     
0154     NDRX_STRCPY_SAFE(v->tstring1, "TEST 55");
0155     
0156 out:    
0157     tpreturn(ret, 0, (char *)v, 0, 0L);    
0158 }
0159 
0160 /**
0161  * UBF Responder
0162  * @param p_svc
0163  */
0164 void UBFRSP(TPSVCINFO *p_svc)
0165 {
0166     UBFH *data = NULL;
0167     int ret = TPSUCCESS;
0168     
0169     if (NULL==(data = (UBFH *)tpalloc("UBF", NULL, 1024)))
0170     {
0171         NDRX_LOG(log_error, "TESTERROR ! Failed to alloc UBF data!");
0172         ret = TPFAIL;
0173         goto out;
0174     }
0175     
0176     if (EXSUCCEED!=Bchg(data, T_STRING_FLD, 1, "HELLO WORLD", 0L))
0177     {
0178         NDRX_LOG(log_error, "TESTERROR ! Failed to set T_STRING_FLD: %s", 
0179                 Bstrerror(Berror));
0180         ret = TPFAIL;
0181         goto out;
0182     }
0183     
0184 out:
0185     
0186     tpreturn(ret, 0, (char *)data, 0, 0L);
0187 }
0188 
0189 /**
0190  * Do initialisation
0191  */
0192 int NDRX_INTEGRA(tpsvrinit)(int argc, char **argv)
0193 {
0194     int ret = EXSUCCEED;
0195     
0196     NDRX_LOG(log_debug, "tpsvrinit called");
0197     
0198     if (EXSUCCEED!=tpadvertise("NULLRSP", NULLRSP))
0199     {
0200         NDRX_LOG(log_error, "Failed to initialise NULLRSP!");
0201         EXFAIL_OUT(ret);
0202     }
0203     
0204     if (EXSUCCEED!=tpadvertise("JSONRSP", JSONRSP))
0205     {
0206         NDRX_LOG(log_error, "Failed to initialise JSONRSP!");
0207         EXFAIL_OUT(ret);
0208     }
0209     
0210     if (EXSUCCEED!=tpadvertise("STRINGRSP", STRINGRSP))
0211     {
0212         NDRX_LOG(log_error, "Failed to initialise STRINGRSP!");
0213         EXFAIL_OUT(ret);
0214     }
0215     
0216     if (EXSUCCEED!=tpadvertise("CARRAYRSP", CARRAYRSP))
0217     {
0218         NDRX_LOG(log_error, "Failed to initialise CARRAYRSP!");
0219         EXFAIL_OUT(ret);
0220     }
0221     
0222     if (EXSUCCEED!=tpadvertise("VIEWRSP", VIEWRSP))
0223     {
0224         NDRX_LOG(log_error, "Failed to initialise VIEWRSP!");
0225         EXFAIL_OUT(ret);
0226     }
0227     
0228     if (EXSUCCEED!=tpadvertise("UBFRSP", UBFRSP))
0229     {
0230         NDRX_LOG(log_error, "Failed to initialise UBFRSP!");
0231         EXFAIL_OUT(ret);
0232     }
0233     
0234 out:    
0235     return ret;
0236 }
0237 
0238 /**
0239  * Do de-initialisation
0240  */
0241 void NDRX_INTEGRA(tpsvrdone)(void)
0242 {
0243     ndrx_growlist_t list;
0244     
0245     NDRX_LOG(log_debug, "tpsvrdone called");
0246     
0247     /* count buffer allocated.. shall be 0!!!! */
0248     
0249     if (EXSUCCEED!=ndrx_buffer_list(&list))
0250     {
0251         NDRX_LOG(log_error, "TESTERROR! Failed to build buffer list!");
0252     }
0253     else
0254     {
0255         if (EXFAIL < list.maxindexused)
0256         {
0257             NDRX_LOG(log_error, "TESTERROR! Max buffer index: %d, shall be -1 (as all free)!",
0258                     list.maxindexused);
0259         }
0260         
0261         ndrx_growlist_free(&list);   
0262     }
0263     
0264 }
0265 
0266 /* vim: set ts=4 sw=4 et smartindent: */