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 <stdio.h>
0035 #include <stdlib.h>
0036 #include <ndebug.h>
0037 #include <atmi.h>
0038 #include <ndrstandard.h>
0039 #include <ubf.h>
0040 #include <test.fd.h>
0041 #include <string.h>
0042 #include <unistd.h>
0043 #include <thlock.h>
0044 #include "test75.h"
0045 #include "ubf_int.h"
0046 #include <exassert.h>
0047
0048
0049
0050
0051
0052
0053
0054
0055 int M_stopping1 = EXFALSE;
0056 int M_stopping2 = EXFALSE;
0057
0058
0059
0060
0061
0062 void DMNSV1 (TPSVCINFO *p_svc)
0063 {
0064 int ret=EXSUCCEED;
0065 char tmp_buf[64];
0066 UBFH *p_ub = (UBFH *)p_svc->data;
0067
0068 NDRX_LOG(log_debug, "%s got call", __func__);
0069
0070
0071 Bprint(p_ub);
0072
0073
0074
0075 NDRX_ASSERT_UBF_OUT((EXSUCCEED==Bget(p_ub, T_STRING_2_FLD, 0, tmp_buf, NULL)),
0076 "Failed to get T_STRING_2_FLD");
0077
0078 NDRX_ASSERT_VAL_OUT((0==strcmp(tmp_buf, "TEST_UBF")),
0079 "Invalid value");
0080
0081
0082 while(!M_stopping1)
0083 {
0084 NDRX_LOG(log_debug, "Daemon running...");
0085 sleep(1);
0086 }
0087
0088 M_stopping1=EXFALSE;
0089
0090 out:
0091 tpreturn( ret==EXSUCCEED?TPSUCCESS:TPFAIL,
0092 0L,
0093 (char *)p_ub,
0094 0L,
0095 0L);
0096 }
0097
0098
0099
0100
0101 void DMNSV2 (TPSVCINFO *p_svc)
0102 {
0103 int ret=EXSUCCEED;
0104
0105 NDRX_LOG(log_debug, "%s got call", __func__);
0106
0107
0108 if (NULL!=p_svc->data)
0109 {
0110 NDRX_LOG(log_error, "Expected NULL data");
0111 EXFAIL_OUT(ret);
0112 }
0113
0114
0115 while(!M_stopping2)
0116 {
0117 NDRX_LOG(log_debug, "Daemon running...");
0118 sleep(1);
0119 }
0120
0121 M_stopping2=EXFALSE;
0122
0123 out:
0124 tpreturn( ret==EXSUCCEED?TPSUCCESS:TPFAIL,
0125 0L,
0126 (char *)p_svc->data,
0127 0L,
0128 0L);
0129 }
0130
0131
0132
0133
0134
0135 void DMNSV_CTL (TPSVCINFO *p_svc)
0136 {
0137 int ret=EXSUCCEED;
0138 UBFH *p_ub = (UBFH *)p_svc->data;
0139 UBFH *p_ub_tmp = NULL;
0140 short dmn_no;
0141 char cmd[16];
0142
0143
0144
0145
0146
0147
0148
0149 if (EXSUCCEED!=Bget(p_ub, T_STRING_FLD, 0, cmd, NULL))
0150 {
0151 NDRX_LOG(log_error, "TESTERROR: Failed to get command: %s",
0152 Bstrerror(Berror));
0153 EXFAIL_OUT(ret);
0154 }
0155
0156 if (EXSUCCEED!=Bget(p_ub, T_SHORT_FLD, 0, (char *)&dmn_no, 0))
0157 {
0158 NDRX_LOG(log_error, "TESTERROR: Failed to get command: %s",
0159 Bstrerror(Berror));
0160 EXFAIL_OUT(ret);
0161 }
0162
0163 if (0==strcmp(cmd, "stop"))
0164 {
0165 switch (dmn_no)
0166 {
0167 case 1:
0168 M_stopping1=EXTRUE;
0169 break;
0170 case 2:
0171 M_stopping2=EXTRUE;
0172 break;
0173 default:
0174 NDRX_LOG(log_error, "Invalid dmn_no=%hd", dmn_no);
0175 break;
0176 }
0177 }
0178 else if (0==strcmp(cmd, "start"))
0179 {
0180 switch (dmn_no)
0181 {
0182 case 1:
0183
0184 p_ub_tmp = (UBFH *)tpalloc("UBF", NULL, 1024);
0185
0186 NDRX_ASSERT_TP_OUT((NULL!=p_ub_tmp), "Failed to alloc");
0187 NDRX_ASSERT_UBF_OUT((EXSUCCEED==Bchg(p_ub_tmp, T_STRING_2_FLD, 0, "TEST_UBF", 0)),
0188 "Failed to set");
0189 NDRX_ASSERT_TP_OUT((EXSUCCEED==tpacall("DMNSV1", (char *)p_ub_tmp,
0190 0, TPNOREPLY)), "Failed to call service with UBF");
0191
0192 break;
0193 case 2:
0194
0195 NDRX_ASSERT_TP_OUT((EXSUCCEED==tpacall("DMNSV2", (char *)p_ub_tmp,
0196 0, TPNOREPLY)), "Failed to call service with UBF");
0197 break;
0198 default:
0199 NDRX_LOG(log_error, "Invalid dmn_no=%hd", dmn_no);
0200 break;
0201 }
0202 }
0203
0204 out:
0205
0206 if (NULL!=p_ub_tmp)
0207 {
0208 tpfree((char *)p_ub_tmp);
0209 }
0210
0211 tpreturn( ret==EXSUCCEED?TPSUCCESS:TPFAIL,
0212 0L,
0213 (char *)p_svc->data,
0214 0L,
0215 0L);
0216 }
0217
0218
0219
0220
0221 int tpsvrinit(int argc, char **argv)
0222 {
0223 int ret = EXSUCCEED;
0224 UBFH *p_ub = NULL;
0225 NDRX_LOG(log_debug, "tpsvrinit called");
0226
0227 if (EXSUCCEED!=tpadvertise("DMNSV1", DMNSV1))
0228 {
0229 NDRX_LOG(log_error, "TESTERROR Failed to initialise DMNSV!");
0230 EXFAIL_OUT(ret);
0231 }
0232
0233 if (EXSUCCEED!=tpadvertise("DMNSV2", DMNSV2))
0234 {
0235 NDRX_LOG(log_error, "TESTERROR Failed to initialise DMNSV!");
0236 EXFAIL_OUT(ret);
0237 }
0238
0239
0240
0241 p_ub = (UBFH *)tpalloc("UBF", NULL, 1024);
0242
0243 if (NULL==p_ub)
0244 {
0245 NDRX_LOG(log_error, "TESTERROR Failed to alloc");
0246 EXFAIL_OUT(ret);
0247 }
0248
0249 Bchg(p_ub, T_STRING_2_FLD, 0, "TEST_UBF", 0L);
0250
0251 if (EXSUCCEED!=tpacall("DMNSV1", (char *)p_ub, 0, TPNOREPLY))
0252 {
0253 NDRX_LOG(log_error, "TESTERROR Failed to call DMNSV");
0254 EXFAIL_OUT(ret);
0255 }
0256
0257
0258 if (EXSUCCEED!=tpacall("DMNSV2", NULL, 0, TPNOREPLY))
0259 {
0260 NDRX_LOG(log_error, "TESTERROR Failed to call DMNSV2");
0261 EXFAIL_OUT(ret);
0262 }
0263
0264
0265 if (EXSUCCEED==tpacall("DMNSV3", (char *)p_ub, 0, TPNOREPLY))
0266 {
0267 NDRX_LOG(log_error, "TESTERROR There shall be no DMNSV3!");
0268 EXFAIL_OUT(ret);
0269 }
0270
0271 if (tperrno!=TPENOENT)
0272 {
0273 NDRX_LOG(log_error, "TESTERROR tperror expected %d but got %d!",
0274 TPENOENT, tperrno);
0275 EXFAIL_OUT(ret);
0276 }
0277
0278
0279 out:
0280
0281 if (NULL!=p_ub)
0282 {
0283 tpfree((char *)p_ub);
0284 }
0285
0286 return ret;
0287 }
0288
0289
0290
0291
0292
0293 void tpsvrdone(void)
0294 {
0295 NDRX_LOG(log_debug, "tpsvrdone called");
0296
0297 M_stopping1=EXTRUE;
0298 M_stopping2=EXTRUE;
0299 }
0300
0301
0302
0303
0304 int tpsvrthrinit(int argc, char **argv)
0305 {
0306 int ret = EXSUCCEED;
0307
0308
0309 if (EXSUCCEED!=tpadvertise("DMNSV_CTL", DMNSV_CTL))
0310 {
0311 NDRX_LOG(log_error, "Failed to initialise DMNSV_CTL!");
0312 EXFAIL_OUT(ret);
0313 }
0314
0315 out:
0316 return ret;
0317 }
0318
0319
0320
0321
0322 void tpsvrthrdone(void)
0323 {
0324 NDRX_LOG(log_debug, "tpsvrthrdone called");
0325 }
0326
0327
0328 expublic struct tmdsptchtbl_t ndrx_G_tmdsptchtbl[] = {
0329 { NULL, NULL, NULL, 0, 0 }
0330 };
0331
0332
0333
0334
0335
0336 int main( int argc, char** argv )
0337 {
0338 _tmbuilt_with_thread_option=EXTRUE;
0339 struct tmsvrargs_t tmsvrargs =
0340 {
0341 &tmnull_switch,
0342 &ndrx_G_tmdsptchtbl[0],
0343 0,
0344 tpsvrinit,
0345 tpsvrdone,
0346 NULL,
0347 NULL,
0348 NULL,
0349 NULL,
0350 NULL,
0351 tpsvrthrinit,
0352 tpsvrthrdone
0353 };
0354
0355 return( _tmstartserver( argc, argv, &tmsvrargs ));
0356
0357 }
0358
0359
0360