Back to home page

Enduro/X

 
 

    


0001 /**
0002  *
0003  * @file convsv21.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 extern int __write_to_tx_file(char *buf);
0044 
0045 void CONVSV (TPSVCINFO *p_svc)
0046 {
0047     int ret=EXSUCCEED;
0048     long revent;
0049     int i;
0050     UBFH *p_ub = (UBFH *)p_svc->data;
0051     char tmp[128];
0052     NDRX_LOG(log_debug, "CONVSV got call");
0053 
0054     /* Just print the buffer */
0055     Bprint(p_ub);
0056 
0057     /* allocate some stuff for more data to put in  */
0058     if (NULL==(p_ub = (UBFH *)tprealloc((char *)p_ub, 6000)))
0059     {
0060         ret=EXFAIL;
0061         goto out;
0062     }
0063 
0064     for (i=0; i<100; i++)
0065     {
0066         snprintf(tmp, sizeof(tmp), "SRV SND: %d", i);
0067         Bchg(p_ub, T_STRING_FLD, 0, (char *)tmp, 0);
0068 
0069         if (p_svc->flags & TPSENDONLY)
0070         {
0071             NDRX_LOG(log_debug, "Doing some send!");
0072             /* Lets send some data back to client */
0073             if (EXFAIL==tpsend(p_svc->cd, (char *)p_ub, 0L, 0L, &revent))
0074             {
0075                 NDRX_LOG(log_error, "Failed to send to client!");
0076             }
0077         }
0078     }
0079 
0080     /* Now we will become as listeners, OK? */
0081     if (EXFAIL==tpsend(p_svc->cd, (char *)p_ub, 0L, TPRECVONLY, &revent))
0082     {
0083         NDRX_LOG(log_error, "Failed to send to client!");
0084         goto out;
0085     }
0086 
0087     /* now wait for messages to come in! */
0088     while (EXSUCCEED==tprecv(p_svc->cd, (char **)&p_ub, 0L, 0L, &revent))
0089     {
0090     Bget(p_ub, T_STRING_FLD, 0, tmp, 0L);
0091     /* write off transaction */
0092     __write_to_tx_file(tmp);
0093     
0094         NDRX_LOG(log_debug, "Received MSG OK!");
0095     }
0096 
0097     /* Dump the buffer */
0098     Bfprint(p_ub, stderr);
0099 
0100     if (TPEEVENT==tperrno)
0101     {
0102         if (TPEV_SENDONLY==revent)
0103         {
0104             NDRX_LOG(log_debug, "We are senders - FINISH UP!");
0105         }
0106         else
0107         {
0108             NDRX_LOG(log_debug, "Did not get TPEV_SENDONLY!!!");
0109             ret=EXFAIL;
0110         }
0111     }
0112 
0113 out:
0114     tpreturn(  ret==EXSUCCEED?TPSUCCESS:TPFAIL,
0115                 0L,
0116                 (char *)p_ub,   /* Note ! we might return NULL buffer here! */
0117                 0L,
0118                 0L);
0119 }
0120 
0121 /*
0122  * Do initialization
0123  */
0124 int NDRX_INTEGRA(tpsvrinit)(int argc, char **argv)
0125 {
0126     int ret = EXSUCCEED;
0127     NDRX_LOG(log_debug, "tpsvrinit called");
0128 
0129     if (EXSUCCEED!=tpopen())
0130     {
0131         NDRX_LOG(log_error, "TESTERROR: tpopen() fail: %d:[%s]", 
0132                                             tperrno, tpstrerror(tperrno));
0133         ret=EXFAIL;
0134         goto out;
0135     }
0136 
0137     if (EXSUCCEED!=tpadvertise("CONVSV", CONVSV))
0138     {
0139         NDRX_LOG(log_error, "Failed to initialize CONVSV!");
0140     }
0141 out:
0142     return ret;
0143 }
0144 
0145 /**
0146  * Do de-initialization
0147  */
0148 void NDRX_INTEGRA(tpsvrdone)(void)
0149 {
0150     NDRX_LOG(log_debug, "tpsvrdone called");
0151 
0152     if (EXSUCCEED!=tpclose())
0153     {
0154         NDRX_LOG(log_error, "TESTERROR: tpclose() fail: %d:[%s]", 
0155                                             tperrno, tpstrerror(tperrno));
0156     }
0157 
0158 }
0159 
0160 /* vim: set ts=4 sw=4 et smartindent: */