Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief `psc' command implementation
0003  *
0004  * @file cmd_psc.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 <ndrx.h>
0045 #include <ndrxdcmn.h>
0046 #include <atmi_int.h>
0047 #include <gencall.h>
0048 #include <nclopt.h>
0049 /*---------------------------Externs------------------------------------*/
0050 /*---------------------------Macros-------------------------------------*/
0051 /*---------------------------Enums--------------------------------------*/
0052 /*---------------------------Typedefs-----------------------------------*/
0053 /*---------------------------Globals------------------------------------*/
0054 /*---------------------------Statics------------------------------------*/
0055 /*---------------------------Prototypes---------------------------------*/
0056 
0057 exprivate short M_svconly;
0058 
0059 /**
0060  * Print header
0061  * @return
0062  */
0063 exprivate void print_hdr(void)
0064 {
0065     if (M_svconly)
0066     {
0067         fprintf(stderr, "Nd Service Name                   Prog SRVID #SUCC #FAIL      MAX     LAST STAT\n");
0068         fprintf(stderr, "-- ------------------------------ ---- ----- ----- ----- -------- -------- -----\n");
0069     }
0070     else
0071     {
0072         fprintf(stderr, "Nd Service Name Routine Name Prog Name SRVID #SUCC #FAIL      MAX     LAST STAT\n");
0073         fprintf(stderr, "-- ------------ ------------ --------- ----- ----- ----- -------- -------- -----\n");
0074     }
0075 }
0076 
0077 /**
0078  * Process response back.
0079  * @param reply
0080  * @param reply_len
0081  * @return
0082  */
0083 expublic int psc_rsp_process(command_reply_t *reply, size_t reply_len)
0084 {
0085     int i;
0086     char binary[9+1];
0087     char svc[12+1];
0088     char fun[12+1];
0089 
0090     if (NDRXD_CALL_TYPE_SVCINFO==reply->msg_type)
0091     {
0092         command_reply_psc_t * psc_info = (command_reply_psc_t*)reply;
0093         FIX_SVC_NM(psc_info->binary_name, binary, (sizeof(binary)-1));
0094         for (i=0; i<psc_info->svc_count; i++)
0095         {
0096             if (M_svconly)
0097             {
0098                 /* Feature #230 */
0099                 /*svc    fun     bin*/
0100                 fprintf(stdout, "%2d %-30.30s %-4.4s %5d %5.5s %5.5s %8.8s %8.8s %-5.5s\n",
0101                        psc_info->nodeid,
0102                        psc_info->svcdet[i].svc_nm, binary, psc_info->srvid, 
0103                        ndrx_decode_num(psc_info->svcdet[i].done, 0, 0, 1), 
0104                        ndrx_decode_num(psc_info->svcdet[i].fail, 1, 0, 1),
0105                        /*decode_msec(psc_info->svcdet[i].min, 0, 0, 2), - not very interesting */
0106                        ndrx_decode_msec(psc_info->svcdet[i].max, 0, 0, 2),
0107                        ndrx_decode_msec(psc_info->svcdet[i].last, 1, 0, 2),
0108                        (psc_info->svcdet[i].status?"BUSY":"AVAIL"));
0109             }
0110             else
0111             {
0112                 FIX_SVC_NM(psc_info->svcdet[i].svc_nm, svc, (sizeof(svc)-1));
0113                 FIX_SVC_NM(psc_info->svcdet[i].fn_nm, fun, (sizeof(fun)-1));
0114                                  /*svc    fun     bin*/
0115                 fprintf(stdout, "%2d %-12.12s %-12.12s %-9.9s %5d %5.5s %5.5s %8.8s %8.8s %-5.5s\n",
0116                        psc_info->nodeid,
0117                        svc, fun, binary, psc_info->srvid, 
0118                        ndrx_decode_num(psc_info->svcdet[i].done, 0, 0, 1), 
0119                        ndrx_decode_num(psc_info->svcdet[i].fail, 1, 0, 1),
0120                        /*decode_msec(psc_info->svcdet[i].min, 0, 0, 2), - not very interesting */
0121                        ndrx_decode_msec(psc_info->svcdet[i].max, 0, 0, 2),
0122                        ndrx_decode_msec(psc_info->svcdet[i].last, 1, 0, 2),
0123                        (psc_info->svcdet[i].status?"BUSY":"AVAIL"));
0124             }
0125         }
0126     }
0127     
0128     return EXSUCCEED;
0129 }
0130 
0131 /**
0132  * Get service listings
0133  * @param p_cmd_map
0134  * @param argc
0135  * @param argv
0136  * @return SUCCEED
0137  */
0138 expublic int cmd_psc(cmd_mapping_t *p_cmd_map, int argc, char **argv, int *p_have_next)
0139 {
0140     command_call_t call;
0141     
0142     int ret = EXSUCCEED;
0143     
0144     ncloptmap_t clopt[] =
0145     {
0146         {'s', BFLD_INT, (void *)&M_svconly, sizeof(M_svconly), 
0147                                 NCLOPT_OPT, "Print services only"},
0148         {0}
0149     };
0150     
0151     M_svconly = EXFALSE;
0152             
0153     /* parse command line */
0154     if (nstd_parse_clopt(clopt, EXTRUE,  argc, argv, EXFALSE))
0155     {
0156         fprintf(stderr, XADMIN_INVALID_OPTIONS_MSG);
0157         EXFAIL_OUT(ret);
0158     }
0159     
0160     memset(&call, 0, sizeof(call));
0161 
0162     /* Print header at first step! */
0163     print_hdr();
0164     /* Then get listing... */
0165     return cmd_generic_listcall(p_cmd_map->ndrxd_cmd, NDRXD_SRC_ADMIN,
0166                         NDRXD_CALL_TYPE_GENERIC,
0167                         &call, sizeof(call),
0168                         G_config.reply_queue_str,
0169                         G_config.reply_queue,
0170                         G_config.ndrxd_q,
0171                         G_config.ndrxd_q_str,
0172                         argc, argv,
0173                         p_have_next,
0174                         G_call_args,
0175                         EXFALSE,
0176                         G_config.listcall_flags);
0177     
0178 out:
0179     return ret;
0180 }
0181 
0182 /* vim: set ts=4 sw=4 et smartindent: */