Back to home page

Enduro/X

 
 

    


0001 /**
0002  *
0003  * @file atmisv4_1ST.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 #include <string.h>
0042 
0043 long M_subs_to_unsibscribe = -1;
0044 
0045 void TEST4_1ST (TPSVCINFO *p_svc)
0046 {
0047     int ret=EXSUCCEED;
0048 
0049     static double d = 55.66;
0050 
0051     UBFH *p_ub = (UBFH *)p_svc->data;
0052 
0053     NDRX_LOG(log_debug, "TEST4_1ST got call");
0054 
0055     /* Just print the buffer */
0056     Bprint(p_ub);
0057     
0058     /* allocate some stuff for more data to put in  */
0059     if (NULL==(p_ub = (UBFH *)tprealloc((char *)p_ub, 4096)))
0060     {
0061         ret=EXFAIL;
0062         goto out;
0063     }
0064 
0065     d+=1;
0066 
0067     if (EXFAIL==Badd(p_ub, T_DOUBLE_FLD, (char *)&d, 0))
0068     {
0069         ret=EXFAIL;
0070         goto out;
0071     }
0072 out:
0073 
0074     tpreturn(0, 0, NULL, 0L, 0L);
0075 
0076 }
0077 
0078 /**
0079  * This service does automatically unsubscribe.
0080  * @param p_svc
0081  */
0082 void TEST4_1ST_2(TPSVCINFO *p_svc)
0083 {
0084     long ret;
0085     
0086     NDRX_LOG(log_debug, "TEST4_1ST_2 - Called");
0087     
0088     if (1!=(ret=tpunsubscribe(M_subs_to_unsibscribe, 0L)))
0089     {
0090         NDRX_LOG(log_error, "TESTERROR: Failed to unsubscribe, should "
0091                                 "be 1, but got %ld", ret);
0092     }
0093 
0094     if (3!=(ret=tpunsubscribe(-1, 0L)))
0095     {
0096         NDRX_LOG(log_error, "TESTERROR: Failed to unsubscribe to all events should "
0097                                 "be 3, but got %ld", ret);
0098     }
0099 
0100     tpreturn(0, 0, NULL, 0L, 0L);
0101 }
0102 
0103 /*
0104  * Do initialization
0105  */
0106 int NDRX_INTEGRA(tpsvrinit)(int argc, char **argv)
0107 {
0108     int ret=EXSUCCEED;
0109     
0110     NDRX_LOG(log_debug, "tpsvrinit called");
0111     TPEVCTL evctl;
0112 
0113     memset(&evctl, 0, sizeof(evctl));
0114 
0115     if (EXSUCCEED!=tpadvertise("TEST4_1ST", TEST4_1ST))
0116     {
0117         NDRX_LOG(log_error, "Failed to initialize TEST4_1ST (first)!");
0118         ret=EXFAIL;
0119     }
0120     else if (EXSUCCEED!=tpadvertise("TEST4_1ST_AL", TEST4_1ST))
0121     {
0122         NDRX_LOG(log_error, "Failed to initialize TEST4_1ST_AL (alias)!");
0123         ret=EXFAIL;
0124     }
0125     else if (EXSUCCEED!=tpadvertise("TEST4_1ST_2", TEST4_1ST_2))
0126     {
0127         NDRX_LOG(log_error, "Failed to initialize TEST4_1ST_2!");
0128         ret=EXFAIL;
0129     }
0130     
0131     if (EXSUCCEED!=ret)
0132     {
0133         goto out;
0134     }
0135 
0136     NDRX_STRCPY_SAFE(evctl.name1, "TEST4_1ST");
0137     evctl.flags|=TPEVSERVICE;
0138 
0139     /* Subscribe to event server */
0140     if (EXFAIL==tpsubscribe("EV..TEST", NULL, &evctl, 0L))
0141     {
0142         NDRX_LOG(log_error, "Failed to subscribe TEST4_1ST "
0143                                         "to EV..TEST event failed");
0144         ret=EXFAIL;
0145     }
0146 
0147     NDRX_STRCPY_SAFE(evctl.name1, "TEST4_1ST_2");
0148     /* Subscribe to event server */
0149     if (EXFAIL==(M_subs_to_unsibscribe=tpsubscribe("TEST2EV", NULL, &evctl, 0L)))
0150     {
0151         NDRX_LOG(log_error, "Failed to subscribe TEST4_1ST "
0152                                         "to EV..TEST event failed");
0153         ret=EXFAIL;
0154     }
0155 
0156     NDRX_STRCPY_SAFE(evctl.name1, "TEST4_1ST_2");
0157     /* Subscribe to event server */
0158     if (EXFAIL==(M_subs_to_unsibscribe=tpsubscribe("TEST2EV2", NULL, &evctl, 0L)))
0159     {
0160         NDRX_LOG(log_error, "Failed to subscribe TEST4_1ST "
0161                                         "to EV..TEST event failed");
0162         ret=EXFAIL;
0163     }
0164 
0165     NDRX_STRCPY_SAFE(evctl.name1, "TEST4_1ST_2");
0166     /* Subscribe to event server */
0167     if (EXFAIL==(M_subs_to_unsibscribe=tpsubscribe("TEST2EV3", NULL, &evctl, 0L)))
0168     {
0169         NDRX_LOG(log_error, "Failed to subscribe TEST4_1ST "
0170                                         "to EV..TEST event failed");
0171         ret=EXFAIL;
0172     }
0173 
0174 out:
0175     return ret;
0176 }
0177 
0178 /**
0179  * Do de-initialization
0180  */
0181 void NDRX_INTEGRA(tpsvrdone)(void)
0182 {
0183     NDRX_LOG(log_debug, "tpsvrdone called");
0184 }
0185 
0186 /* vim: set ts=4 sw=4 et smartindent: */