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 <unistd.h> /* Symbolic Constants */
0035 #include <sys/types.h> /* Primitive System Data Types */
0036 #include <errno.h> /* Errors */
0037 #include <stdio.h> /* Input/Output */
0038 #include <stdlib.h> /* General Utilities */
0039 #include <pthread.h> /* POSIX Threads */
0040
0041
0042 #include <ndebug.h>
0043 #include <atmi.h>
0044 #include <ndrstandard.h>
0045 #include <ubf.h>
0046 #include <test.fd.h>
0047 #include <string.h>
0048 #include <exthpool.h>
0049
0050 struct thread_server
0051 {
0052 char *context_data;
0053 char *buffer;
0054 };
0055
0056 typedef struct thread_server thread_server_t;
0057
0058
0059 threadpool M_thpool;
0060
0061
0062 void _TH_TESTSVFN (void *ptr, int *p_finish_off)
0063 {
0064 int ret=EXSUCCEED;
0065 double d;
0066 int i;
0067 thread_server_t *thread_data = (thread_server_t *)ptr;
0068 UBFH *p_ub = (UBFH *)thread_data->buffer;
0069
0070 if (EXSUCCEED!=tpinit(NULL))
0071 {
0072 NDRX_LOG(log_error, "Failed to init worker client");
0073 exit(1);
0074 }
0075
0076
0077 if (EXSUCCEED!=tpsrvsetctxdata(thread_data->context_data, SYS_SRV_THREAD))
0078 {
0079 NDRX_LOG(log_error, "Failed to set context");
0080 exit(1);
0081 }
0082
0083
0084 tpsrvfreectxdata(thread_data->context_data);
0085 free(thread_data);
0086
0087
0088
0089 NDRX_LOG(log_debug, "TESTSVFN got call");
0090
0091
0092
0093 if (NULL==(p_ub = (UBFH *)tprealloc((char *)p_ub, 4096)))
0094 {
0095 ret=EXFAIL;
0096 goto out;
0097 }
0098
0099 if (EXFAIL==Bget(p_ub, T_DOUBLE_FLD, Boccur(p_ub, T_DOUBLE_FLD)-1, (char *)&d, 0))
0100 {
0101 ret=EXFAIL;
0102 goto out;
0103 }
0104
0105 d+=1;
0106
0107 if (EXFAIL==Badd(p_ub, T_DOUBLE_FLD, (char *)&d, 0))
0108 {
0109 ret=EXFAIL;
0110 goto out;
0111 }
0112
0113 if (EXFAIL==ret)
0114 NDRX_LOG(log_debug, "WE GOT FAIL TESTERROR!!!!!");
0115
0116
0117 out:
0118 tpreturn( ret==EXSUCCEED?TPSUCCESS:TPFAIL,
0119 0L,
0120 (char *)p_ub,
0121 0L,
0122 0L);
0123
0124 }
0125
0126
0127
0128
0129
0130
0131
0132 void TESTSVFN (TPSVCINFO *p_svc)
0133 {
0134 int ret=EXSUCCEED;
0135 UBFH *p_ub = (UBFH *)p_svc->data;
0136 pthread_t thread;
0137 pthread_attr_t attr;
0138 long size;
0139 char btype[16];
0140 char stype[16];
0141
0142 pthread_attr_init(&attr);
0143 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
0144
0145 if (0==(size = tptypes (p_svc->data, btype, stype)))
0146 {
0147 NDRX_LOG(log_error, "Zero buffer received!");
0148 exit(1);
0149 }
0150
0151 thread_server_t *thread_data = malloc(sizeof(thread_server_t));
0152
0153
0154 thread_data->buffer = tpalloc(btype, NULL, size);
0155
0156
0157 if (NULL==thread_data->buffer)
0158 {
0159 NDRX_LOG(log_error, "tpalloc failed of type %s size %ld", btype, size);
0160 exit(1);
0161 }
0162
0163
0164 memcpy(thread_data->buffer, p_svc->data, size);
0165
0166 thread_data->context_data = tpsrvgetctxdata();
0167
0168
0169
0170
0171
0172
0173
0174
0175 ndrx_thpool_add_work(M_thpool, (void*)_TH_TESTSVFN, (void *)thread_data);
0176
0177
0178 out:
0179 if (EXSUCCEED==ret)
0180 {
0181
0182 tpcontinue();
0183 }
0184 else
0185 {
0186
0187 tpreturn( TPFAIL,
0188 0L,
0189 (char *)p_ub,
0190 0L,
0191 0L);
0192 }
0193 }
0194
0195
0196
0197 int NDRX_INTEGRA(tpsvrinit)(int argc, char **argv)
0198 {
0199 int ret = EXSUCCEED;
0200 NDRX_LOG(log_debug, "tpsvrinit called");
0201
0202
0203 if (NULL==(M_thpool = ndrx_thpool_init(10, NULL, NULL, NULL, 0, NULL)))
0204 {
0205 NDRX_LOG(log_error, "Failed to initialize thread pool (cnt: 10)!");
0206 EXFAIL_OUT(ret);
0207 }
0208
0209
0210 if (EXSUCCEED!=tpadvertise("TESTSV", TESTSVFN))
0211 {
0212 NDRX_LOG(log_error, "Failed to initialize TESTSV (first)!");
0213 ret=EXFAIL;
0214 }
0215
0216 out:
0217 return ret;
0218 }
0219
0220
0221
0222
0223 void NDRX_INTEGRA(tpsvrdone)(void)
0224 {
0225 NDRX_LOG(log_debug, "tpsvrdone called");
0226 }
0227