Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief `prtsvc' Print routing services
0003  *
0004  * @file cmd_prtvsc.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 <errno.h>
0038 #include <memory.h>
0039 #include <sys/types.h>
0040 #include <sys/stat.h>
0041 #include <ndrstandard.h>
0042 #include <ndebug.h>
0043 
0044 #include <ndrx.h>
0045 #include <ndrxdcmn.h>
0046 #include <atmi_int.h>
0047 #include <gencall.h>
0048 
0049 #include <nstopwatch.h>
0050 #include <nclopt.h>
0051 #include <sys_unix.h>
0052 #include <utlist.h>
0053 #include <lcfint.h>
0054 #include <ndrx_ddr.h>
0055 #include <atmi_shm.h>
0056 /*---------------------------Externs------------------------------------*/
0057 /*---------------------------Macros-------------------------------------*/
0058 /*---------------------------Enums--------------------------------------*/
0059 /*---------------------------Typedefs-----------------------------------*/
0060 /*---------------------------Globals------------------------------------*/
0061 /*---------------------------Statics------------------------------------*/
0062 /*---------------------------Prototypes---------------------------------*/
0063 
0064 
0065 /**
0066  * Print header
0067  * @return
0068  */
0069 exprivate void print_hdr(void)
0070 {
0071     
0072     fprintf(stderr, "  SLOT SERVICE NAME                   PRIO ROUTE           T TRANTIME FLAGS\n");
0073     fprintf(stderr, "------ ------------------------------ ---- --------------- - -------- ---------\n");
0074 }
0075 
0076 /**
0077  * Print routing data, requires that Enduro/X is started
0078  * @param p_cmd_map
0079  * @param argc
0080  * @param argv
0081  * @return SUCCEED
0082  */
0083 expublic int cmd_prtsvc(cmd_mapping_t *p_cmd_map, int argc, char **argv, int *p_have_next)
0084 {
0085     int ret=EXSUCCEED;
0086     short print_all =  EXFALSE;
0087     short print_isused =  EXFALSE;
0088     short print_wasused =  EXFALSE;
0089     int i;
0090     ndrx_services_t *el;
0091     ndrx_services_t *ptr;
0092     char flagsstr[128];
0093     int total = 0;
0094     int page;
0095     ncloptmap_t clopt[] =
0096     {
0097         {'a', BFLD_SHORT, (void *)&print_all, 0, 
0098                                 NCLOPT_OPT | NCLOPT_TRUEBOOL, 
0099                                 "Print all entries"},
0100         {'i', BFLD_SHORT, (void *)&print_isused, 0, 
0101                                 NCLOPT_OPT | NCLOPT_TRUEBOOL, 
0102                                 "Print entries in use"},
0103         {'w', BFLD_SHORT, (void *)&print_wasused, 0, 
0104                                 NCLOPT_OPT | NCLOPT_TRUEBOOL, 
0105                                 "Print entries which was used"},
0106         {0}
0107     };
0108     
0109     /* parse command line */
0110     if (nstd_parse_clopt(clopt, EXTRUE,  argc, argv, EXFALSE))
0111     {
0112         fprintf(stderr, XADMIN_INVALID_OPTIONS_MSG);
0113         EXFAIL_OUT(ret);
0114     }
0115     
0116     if (!print_isused && !print_wasused && !print_all)
0117     {
0118         print_isused = EXTRUE;
0119     }
0120     
0121     if (EXFAIL==tpinit(NULL))
0122     {
0123         fprintf(stderr, "* Failed to become client\n");
0124         EXFAIL_OUT(ret);
0125     }
0126     
0127     /* Print header at first step! */
0128     print_hdr();
0129     
0130     page = ndrx_G_shmcfg->ddr_page;
0131     ptr = (ndrx_services_t *) (ndrx_G_routsvc.mem + page*G_atmi_env.rtsvcmax * sizeof(ndrx_services_t));
0132     for (i=0; i<G_atmi_env.rtsvcmax; i++)
0133     {
0134         el = NDRX_DDRV_SVC_INDEX(ptr, i);
0135         
0136         if (print_all ||
0137                 (print_isused && (el->flags & NDRX_LH_FLAG_ISUSED)) ||
0138                 
0139                 (print_wasused && (el->flags & NDRX_LH_FLAG_WASUSED) && 
0140                     !(el->flags & NDRX_LH_FLAG_ISUSED))
0141                 
0142                 )
0143         {
0144             flagsstr[0]=EXEOS;
0145             
0146             if (el->flags & NDRX_LH_FLAG_ISUSED)
0147             {
0148                 if (EXEOS!=flagsstr[0])
0149                 {
0150                     NDRX_STRCAT_S(flagsstr, sizeof(flagsstr), ",");
0151                 }
0152                 NDRX_STRCAT_S(flagsstr, sizeof(flagsstr), "iuse");
0153             }
0154             else if (el->flags & NDRX_LH_FLAG_WASUSED)
0155             {
0156                 if (EXEOS!=flagsstr[0])
0157                 {
0158                     NDRX_STRCAT_S(flagsstr, sizeof(flagsstr), ",");
0159                 }
0160                 NDRX_STRCAT_S(flagsstr, sizeof(flagsstr), "wuse");
0161             }
0162             
0163             fprintf(stdout, "%6d %-30.30s %4d %-15.15s %c %8lu %s\n",
0164                     i, el->svcnm, el->prio, el->criterion, el->autotran?'Y':'N',
0165                     el->trantime, flagsstr);
0166             total++;
0167         }
0168     }
0169     
0170     fprintf(stderr, "\nTOTAL: %d\n", total);
0171     
0172 out:
0173                         
0174     return ret;
0175 }
0176 /* vim: set ts=4 sw=4 et smartindent: */