0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
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
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
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
0073
0074
0075
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
0123
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
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
0212
0213
0214
0215
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
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
0240 LL_DELETE(list,el);
0241 NDRX_FREE(el);
0242 }
0243
0244 out:
0245 return ret;
0246 }
0247
0248