Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief List queue configuration
0003  *
0004  * @file cmd_mqlc.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 <string.h>
0035 #include <stdio.h>
0036 #include <stdlib.h>
0037 #include <memory.h>
0038 #include <sys/param.h>
0039 
0040 #include <ndrstandard.h>
0041 #include <ndebug.h>
0042 #include <nstdutil.h>
0043 
0044 #include <ndrxdcmn.h>
0045 #include <atmi_int.h>
0046 #include <gencall.h>
0047 #include <utlist.h>
0048 #include <Exfields.h>
0049 
0050 #include "xa_cmn.h"
0051 #include <ndrx.h>
0052 #include <qcommon.h>
0053 /*---------------------------Externs------------------------------------*/
0054 /*---------------------------Macros-------------------------------------*/
0055 /*---------------------------Enums--------------------------------------*/
0056 /*---------------------------Typedefs-----------------------------------*/
0057 /*---------------------------Globals------------------------------------*/
0058 /*---------------------------Statics------------------------------------*/
0059 /*---------------------------Prototypes---------------------------------*/
0060 
0061 /**
0062  * Print header
0063  * @return
0064  */
0065 exprivate void print_hdr(void)
0066 {
0067     fprintf(stderr, "Nd SRVID QSPACE    QNAME     FLAGS QDEF\n");
0068     fprintf(stderr, "-- ----- --------- --------- ----- --------------------\n");
0069 }
0070 
0071 /**
0072  * List queue definitions
0073  * We will run in conversation mode.
0074  * @param svcnm
0075  * @return SUCCEED/FAIL
0076  */
0077 exprivate int print_buffer(UBFH *p_ub, char *svcnm)
0078 {
0079     int ret = EXSUCCEED;
0080     
0081     short nodeid;
0082     short srvid;
0083     char qspace[XATMI_SERVICE_NAME_LENGTH+1];
0084     char qname[TMQNAMELEN+1];
0085     char qdef[TMQ_QDEF_MAX];
0086     char strflags[128];
0087     
0088     if (
0089             EXSUCCEED!=Bget(p_ub, EX_QSPACE, 0, qspace, 0L) ||
0090             EXSUCCEED!=Bget(p_ub, EX_QNAME, 0, qname, 0L) ||
0091             EXSUCCEED!=Bget(p_ub, TMNODEID, 0, (char *)&nodeid, 0L) ||
0092             EXSUCCEED!=Bget(p_ub, TMSRVID, 0, (char *)&srvid, 0L) ||
0093             EXSUCCEED!=CBget(p_ub, EX_DATA, 0, qdef, 0L, BFLD_STRING) ||
0094             EXSUCCEED!=Bget(p_ub, EX_QSTRFLAGS, 0, strflags, 0L)
0095         )
0096     {
0097         fprintf(stderr, "Protocol error - TMQ did not return data, see logs!\n");
0098         NDRX_LOG(log_error, "Failed to read fields: [%s]", 
0099                 Bstrerror(Berror));
0100         EXFAIL_OUT(ret);
0101     }    
0102     
0103     FIX_SVC_NM_DIRECT(qspace, 9);
0104     FIX_SVC_NM_DIRECT(qname, 9);
0105     
0106     fprintf(stdout, "%2d %5d %-9.9s %-9.9s %-5.5s %s",
0107             nodeid, 
0108             srvid, 
0109             qspace, 
0110             qname,
0111             strflags,
0112             qdef
0113             );
0114     
0115     printf("\n");
0116     
0117 out:
0118     return ret;
0119 }
0120 
0121 /**
0122  * This basically tests the normal case when all have been finished OK!
0123  * @return
0124  */
0125 exprivate int call_tmq(char *svcnm)
0126 {
0127     UBFH *p_ub = (UBFH *)tpalloc("UBF", "", 1024);
0128     int ret=EXSUCCEED;
0129     int cd;
0130     long revent;
0131     int recv_continue = 1;
0132     int tp_errno;
0133     int rcv_count = 0;
0134     char cmd = TMQ_CMD_MQLC;
0135     
0136     /* Setup the call buffer... */
0137     if (NULL==p_ub)
0138     {
0139         NDRX_LOG(log_error, "Failed to alloc FB!");        
0140         EXFAIL_OUT(ret);
0141     }
0142     
0143     if (EXSUCCEED!=Bchg(p_ub, EX_QCMD, 0, &cmd, 0L))
0144     {
0145         NDRX_LOG(log_error, "Failed to install command code");
0146         EXFAIL_OUT(ret);
0147     }
0148     
0149     if (EXFAIL == (cd = tpconnect(svcnm,
0150                                     (char *)p_ub,
0151                                     0,
0152                                     TPNOTRAN |
0153                                     TPRECVONLY)))
0154     {
0155         NDRX_LOG(log_error, "Connect error [%s]", tpstrerror(tperrno) );
0156         ret = EXFAIL;
0157         goto out;
0158     }
0159     NDRX_LOG(log_debug, "Connected OK, cd = %d", cd );
0160 
0161     while (recv_continue)
0162     {
0163         recv_continue=0;
0164         if (EXFAIL == tprecv(cd,
0165                             (char **)&p_ub,
0166                             0L,
0167                             0L,
0168                             &revent))
0169         {
0170             ret = EXFAIL;
0171             tp_errno = tperrno;
0172             if (TPEEVENT == tp_errno)
0173             {
0174                     if (TPEV_SVCSUCC == revent)
0175                             ret = EXSUCCEED;
0176                     else
0177                     {
0178                         NDRX_LOG(log_error,
0179                                  "Unexpected conv event %lx", revent );
0180                         EXFAIL_OUT(ret);
0181                     }
0182             }
0183             else
0184             {
0185                 NDRX_LOG(log_error, "recv error %d", tp_errno  );
0186                 EXFAIL_OUT(ret);
0187             }
0188         }
0189         else
0190         {
0191             if (EXSUCCEED!=print_buffer(p_ub, svcnm))
0192             {
0193                 EXFAIL_OUT(ret);
0194             }
0195             rcv_count++;
0196             recv_continue=1;
0197         }
0198     }
0199 
0200 out:
0201 
0202     if (NULL!=p_ub)
0203     {
0204         tpfree((char *)p_ub);
0205     }
0206 
0207     return ret;
0208 }
0209 
0210 /**
0211  * List queues
0212  * @param p_cmd_map
0213  * @param argc
0214  * @param argv
0215  * @return SUCCEED
0216  */
0217 expublic int cmd_mqlc(cmd_mapping_t *p_cmd_map, int argc, char **argv, int *p_have_next)
0218 {
0219     int ret = EXSUCCEED;
0220     atmi_svc_list_t *el, *tmp, *list;
0221     
0222     /* we need to init TP subsystem... */
0223     if (EXSUCCEED!=tpinit(NULL))
0224     {
0225         fprintf(stderr, "Failed to tpinit(): %s\n", tpstrerror(tperrno));
0226         EXFAIL_OUT(ret);
0227     }
0228     
0229     print_hdr();
0230     
0231     list = ndrx_get_svc_list(mqfilter);
0232     
0233     LL_FOREACH_SAFE(list,el,tmp)
0234     {
0235         
0236         NDRX_LOG(log_info, "About to call service: [%s]\n", el->svcnm);
0237 
0238         call_tmq(el->svcnm);
0239         /* Have some housekeep. */
0240         LL_DELETE(list,el);
0241         NDRX_FREE(el);
0242     }
0243     
0244 out:
0245     return ret;
0246 }
0247 
0248 /* vim: set ts=4 sw=4 et smartindent: */