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 <unistd.h>
0038 #include <memory.h>
0039
0040 #include <ndebug.h>
0041 #include <atmi.h>
0042
0043 #include "Exfields.h"
0044
0045
0046
0047
0048
0049
0050
0051
0052 exprivate int M_tran = EXFALSE;
0053 exprivate int M_usleep = 0;
0054
0055
0056
0057
0058
0059
0060 void EXBENCHSV (TPSVCINFO *p_svc)
0061 {
0062 char btype[16]={EXEOS};
0063 char stype[16]={EXEOS};
0064 CLIENTID cltid;
0065 long size;
0066 BFLDLEN len;
0067 int ret = TPSUCCESS;
0068
0069 if (M_usleep > 0)
0070 {
0071 usleep(M_usleep);
0072 }
0073
0074 size = tptypes (p_svc->data, btype, stype);
0075
0076 len = sizeof(cltid.clientdata);
0077
0078 if (0==strcmp("UBF", btype) && EXSUCCEED==Bget((UBFH*)p_svc->data,
0079 EX_CLTID, 0, cltid.clientdata, &len))
0080 {
0081
0082 if (EXFAIL==tpnotify(&cltid, p_svc->data, p_svc->len, 0))
0083 {
0084 ret = TPFAIL;
0085 }
0086 }
0087
0088
0089 tpreturn( ret,
0090 0L,
0091 (char *)p_svc->data,
0092 0L,
0093 0L);
0094 }
0095
0096
0097
0098
0099
0100
0101
0102 int init(int argc, char** argv)
0103 {
0104 int ret = EXSUCCEED;
0105 char svcnm[XATMI_SERVICE_NAME_LENGTH+1];
0106 char svcnm_base[XATMI_SERVICE_NAME_LENGTH+1]="EXBENCH";
0107 int c;
0108 int svcnum=0;
0109 char event[XATMI_EVENT_MAX+1]="";
0110
0111
0112 while ((c = getopt(argc, argv, "s:N:TU:e:--")) != EXFAIL)
0113 {
0114 switch(c)
0115 {
0116 case 'N':
0117 svcnum = atoi(optarg);
0118 break;
0119 case 's':
0120 NDRX_STRCPY_SAFE(svcnm_base, optarg);
0121 break;
0122 case 'U':
0123 M_usleep = atoi(optarg);
0124 break;
0125 case 'T':
0126 M_tran = EXTRUE;
0127 break;
0128 case 'e':
0129 NDRX_STRCPY_SAFE(event, optarg);
0130 break;
0131 }
0132 }
0133
0134 if (svcnum > 0)
0135 {
0136 snprintf(svcnm, sizeof(svcnm), "%s%03d", svcnm_base, (tpgetsrvid() % 1000) % svcnum );
0137 }
0138 else
0139 {
0140 NDRX_STRCPY_SAFE(svcnm, svcnm_base);
0141 }
0142
0143
0144 if (EXSUCCEED!=tpadvertise(svcnm, EXBENCHSV))
0145 {
0146 NDRX_LOG(log_error, "Failed to initialise EXBENCH: %s!", tpstrerror(tperrno));
0147 ret=EXFAIL;
0148 goto out;
0149 }
0150
0151 if (EXEOS!=event[0])
0152 {
0153 TPEVCTL evctl;
0154 memset(&evctl, 0, sizeof(evctl));
0155 evctl.flags|=TPEVSERVICE;
0156 NDRX_STRCPY_SAFE(evctl.name1, svcnm);
0157 if (EXFAIL==tpsubscribe(event, NULL, &evctl, 0L))
0158 {
0159 NDRX_LOG(log_error, "Failed to subscribe to [%s] event: %s",
0160 event, tpstrerror(tperrno));
0161 EXFAIL_OUT(ret);
0162 }
0163 }
0164
0165 if (M_tran && EXSUCCEED!=tpopen())
0166 {
0167 NDRX_LOG(log_error, "Failed to initialise tpopen: %s!", tpstrerror(tperrno));
0168 ret=EXFAIL;
0169 goto out;
0170 }
0171
0172 out:
0173
0174 return ret;
0175 }
0176
0177
0178
0179
0180 void uninit(void)
0181 {
0182 TP_LOG(log_info, "uninit");
0183 if (M_tran)
0184 {
0185 tpclose();
0186 }
0187 }
0188
0189
0190
0191
0192
0193
0194
0195 int thinit(int argc, char ** argv)
0196 {
0197 int ret = EXSUCCEED;
0198
0199 if (M_tran && EXSUCCEED!=tpopen())
0200 {
0201 TP_LOG(log_error, "thinit: tailed to initialise tpopen: %s!", tpstrerror(tperrno));
0202 ret=EXFAIL;
0203 goto out;
0204 }
0205
0206 out:
0207 return ret;
0208 }
0209
0210
0211
0212
0213 void thuninit(void)
0214 {
0215 TP_LOG(log_info, "thuninit");
0216 if (M_tran)
0217 {
0218 tpclose();
0219 }
0220 }
0221
0222
0223
0224 expublic struct tmdsptchtbl_t ndrx_G_tmdsptchtbl[] = {
0225 { "", "EXBENCHSV", EXBENCHSV, 0, 0 }
0226 , { NULL, NULL, NULL, 0, 0 }
0227 };
0228
0229
0230
0231
0232
0233
0234
0235 int main( int argc, char** argv )
0236 {
0237 _tmbuilt_with_thread_option=EXTRUE;
0238 struct tmsvrargs_t tmsvrargs =
0239 {
0240 &tmnull_switch,
0241 &ndrx_G_tmdsptchtbl[0],
0242 0,
0243 init,
0244 uninit,
0245 NULL,
0246 NULL,
0247 NULL,
0248 NULL,
0249 NULL,
0250 thinit,
0251 thuninit
0252 };
0253
0254 return( _tmstartserver( argc, argv, &tmsvrargs ));
0255
0256 }
0257
0258
0259
0260