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 "exassert.h"
0046
0047
0048
0049
0050
0051
0052
0053 exprivate volatile short M_counter = 0;
0054 exprivate __thread short M_thr_id = 0;
0055 MUTEX_LOCKDECL(M_counter_lock);
0056
0057
0058
0059
0060
0061 void TESTSV (TPSVCINFO *p_svc)
0062 {
0063 int ret=EXSUCCEED;
0064 char testbuf[1024];
0065 UBFH *p_ub = (UBFH *)p_svc->data;
0066
0067 NDRX_LOG(log_debug, "%s got call", __func__);
0068
0069
0070 Bprint(p_ub);
0071
0072 if (EXFAIL==Bget(p_ub, T_STRING_FLD, 0, testbuf, 0))
0073 {
0074 NDRX_LOG(log_error, "TESTERROR: Failed to get T_STRING_FLD: %s",
0075 Bstrerror(Berror));
0076 ret=EXFAIL;
0077 goto out;
0078 }
0079
0080 sleep (1);
0081
0082 if (0!=strcmp(testbuf, VALUE_EXPECTED))
0083 {
0084 NDRX_LOG(log_error, "TESTERROR: Expected: [%s] got [%s]",
0085 VALUE_EXPECTED, testbuf);
0086 ret=EXFAIL;
0087 goto out;
0088 }
0089
0090
0091 if (EXSUCCEED!=Bchg(p_ub, T_SHORT_FLD, 0, (char *)&M_thr_id, 0L))
0092 {
0093 NDRX_LOG(log_error, "TESTERROR: Failed to set T_SHORT_FLD to %d: %s",
0094 M_thr_id, Bstrerror(Berror));
0095 ret=EXFAIL;
0096 goto out;
0097 }
0098
0099 out:
0100 tpreturn( ret==EXSUCCEED?TPSUCCESS:TPFAIL,
0101 0L,
0102 (char *)p_ub,
0103 0L,
0104 0L);
0105 }
0106
0107
0108
0109
0110
0111 void MULTI_INIT (TPSVCINFO *p_svc)
0112 {
0113 tpreturn( TPSUCCESS,
0114 0L,
0115 (char *)p_svc->data,
0116 0L,
0117 0L);
0118 }
0119
0120
0121
0122 int tpsvrinit(int argc, char **argv)
0123 {
0124 int ret = EXSUCCEED;
0125 NDRX_LOG(log_debug, "tpsvrinit called");
0126
0127 if (EXSUCCEED!=tpadvertise("TESTSV", TESTSV))
0128 {
0129 NDRX_LOG(log_error, "Failed to initialise TESTSV!");
0130 EXFAIL_OUT(ret);
0131 }
0132 out:
0133 return ret;
0134 }
0135
0136
0137
0138
0139 void tpsvrdone(void)
0140 {
0141 NDRX_LOG(log_debug, "tpsvrdone called");
0142 }
0143
0144
0145
0146
0147 int tpsvrthrinit(int argc, char **argv)
0148 {
0149 int ret = EXSUCCEED;
0150
0151 MUTEX_LOCK_V(M_counter_lock);
0152
0153 M_thr_id = M_counter;
0154 M_counter++;
0155
0156 MUTEX_UNLOCK_V(M_counter_lock);
0157
0158
0159 NDRX_ASSERT_TP_OUT((EXSUCCEED==tpadvertise("MULTI_INIT", MULTI_INIT)),
0160 "Advertise fail");
0161
0162
0163
0164
0165 NDRX_ASSERT_TP_OUT((EXSUCCEED==tpacall("MULTI_INIT", NULL, 0, TPNOREPLY)),
0166 "Failed to acall MULTI_INIT");
0167
0168 NDRX_LOG(log_debug, "tpsvrthrinit called argc=[%d] argv[0]=[%s] thr_id=[%hd]",
0169 argc, argv[0], M_thr_id);
0170
0171 out:
0172 return ret;
0173 }
0174
0175
0176
0177
0178 void tpsvrthrdone(void)
0179 {
0180 NDRX_LOG(log_debug, "tpsvrthrdone called");
0181 }
0182
0183
0184 expublic struct tmdsptchtbl_t ndrx_G_tmdsptchtbl[] = {
0185 { NULL, NULL, NULL, 0, 0 }
0186 };
0187
0188
0189
0190
0191
0192 int main( int argc, char** argv )
0193 {
0194 _tmbuilt_with_thread_option=EXTRUE;
0195 struct tmsvrargs_t tmsvrargs =
0196 {
0197 &tmnull_switch,
0198 &ndrx_G_tmdsptchtbl[0],
0199 0,
0200 tpsvrinit,
0201 tpsvrdone,
0202 NULL,
0203 NULL,
0204 NULL,
0205 NULL,
0206 NULL,
0207 tpsvrthrinit,
0208 tpsvrthrdone
0209 };
0210
0211 return( _tmstartserver( argc, argv, &tmsvrargs ));
0212
0213 }
0214
0215
0216