1 | #define DIMLIB
|
---|
2 | #include <dis.hxx>
|
---|
3 | #include "tokenstring.hxx"
|
---|
4 | //#include <iostream>
|
---|
5 | //using namespace std;
|
---|
6 | #include <time.h>
|
---|
7 | //#include <sys/timeb.h>
|
---|
8 |
|
---|
9 | DimClientExitHandler *DimServer::itsClientExit = 0;
|
---|
10 | DimExitHandler *DimServer::itsExit = 0;
|
---|
11 | DimErrorHandler *DimServer::itsSrvError = 0;
|
---|
12 | char *DimServer::itsName = 0;
|
---|
13 | char *DimServer::clientName = 0;
|
---|
14 | char *DimServer::dimDnsNode = 0;
|
---|
15 | int DimServer::autoStart = 1;
|
---|
16 | //int DimServer::itsNServices = 0;
|
---|
17 |
|
---|
18 | extern "C" {
|
---|
19 | static void user_routine( void *tagp, void **buf, int *size, int *first_time)
|
---|
20 | {
|
---|
21 | // int *tag = (int *)tagp;
|
---|
22 | // int id = *tag;
|
---|
23 | DimService *t;
|
---|
24 |
|
---|
25 | if(first_time){}
|
---|
26 | // t = (DimService *)id_get_ptr(id, SRC_DIS);
|
---|
27 | t = *(DimService **)tagp;
|
---|
28 | if( t->itsServiceHandler ) {
|
---|
29 | t->itsServiceHandler->itsService = t;
|
---|
30 | DimCore::inCallback = 2;
|
---|
31 | t->itsServiceHandler->serviceHandler();
|
---|
32 | DimCore::inCallback = 0;
|
---|
33 | }
|
---|
34 | else
|
---|
35 | {
|
---|
36 | DimCore::inCallback = 2;
|
---|
37 | t->serviceHandler();
|
---|
38 | DimCore::inCallback = 0;
|
---|
39 | }
|
---|
40 | if( t->itsType == DisSTRING)
|
---|
41 | t->itsSize = strlen((char *)t->itsData)+1;
|
---|
42 | *buf = t->itsData;
|
---|
43 | *size = t->itsSize;
|
---|
44 | }
|
---|
45 | }
|
---|
46 |
|
---|
47 | void DimService::declareIt(char *name, char *format, DimServiceHandler *handler, DimServerDns *dns)
|
---|
48 | {
|
---|
49 | // itsTagId = 0;
|
---|
50 | itsDns = dns;
|
---|
51 | itsName = new char[strlen(name)+1];
|
---|
52 | itsDataSize = 0;
|
---|
53 | strcpy( itsName, name);
|
---|
54 | if(handler)
|
---|
55 | itsServiceHandler = handler;
|
---|
56 | else
|
---|
57 | itsServiceHandler = 0;
|
---|
58 | // itsTagId = id_get((void *)this, SRC_DIS);
|
---|
59 | if(itsDns == 0)
|
---|
60 | {
|
---|
61 | itsId = dis_add_service( name, format, NULL, 0,
|
---|
62 | // user_routine, itsTagId);
|
---|
63 | user_routine, (long)this);
|
---|
64 | DimServer::start();
|
---|
65 | }
|
---|
66 | else
|
---|
67 | {
|
---|
68 | itsId = dis_add_service_dns( itsDns->getDnsId(), name, format, NULL, 0,
|
---|
69 | // user_routine, itsTagId);
|
---|
70 | user_routine, (long)this);
|
---|
71 | // itsDns->addServiceId(itsId);
|
---|
72 | DimServer::start(itsDns);
|
---|
73 | }
|
---|
74 | }
|
---|
75 |
|
---|
76 | void DimService::storeIt(void *data, int size)
|
---|
77 | {
|
---|
78 |
|
---|
79 | if(!itsDataSize)
|
---|
80 | {
|
---|
81 | itsData = new char[size];
|
---|
82 | itsDataSize = size;
|
---|
83 | }
|
---|
84 | else if(itsDataSize < size)
|
---|
85 | {
|
---|
86 | delete[] (char *)itsData;
|
---|
87 | itsData = new char[size];
|
---|
88 | itsDataSize = size;
|
---|
89 | }
|
---|
90 | memcpy(itsData, data, size);
|
---|
91 | itsSize = size;
|
---|
92 | }
|
---|
93 |
|
---|
94 | extern "C" {
|
---|
95 | static void command_routine( void *tagp, void *buf, int *size)
|
---|
96 | {
|
---|
97 | // int *tag = (int *)tagp;
|
---|
98 | // int id = *tag;
|
---|
99 | DimCommand *t;
|
---|
100 |
|
---|
101 | // t = (DimCommand *)id_get_ptr(id, SRC_DIS);
|
---|
102 | t = *(DimCommand **)tagp;
|
---|
103 | t->itsData = buf;
|
---|
104 | t->itsSize = *size;
|
---|
105 | t->secs = 0;
|
---|
106 | if( t->itsCommandHandler ) {
|
---|
107 | t->itsCommandHandler->itsCommand = t;
|
---|
108 | DimCore::inCallback = 2;
|
---|
109 | t->itsCommandHandler->commandHandler();
|
---|
110 | DimCore::inCallback = 0;
|
---|
111 | }
|
---|
112 | else
|
---|
113 | {
|
---|
114 | DimCore::inCallback = 2;
|
---|
115 | t->commandHandler();
|
---|
116 | DimCore::inCallback = 0;
|
---|
117 | }
|
---|
118 | t->itsData = 0;
|
---|
119 | t->itsSize = 0;
|
---|
120 | }
|
---|
121 | }
|
---|
122 |
|
---|
123 | void DimCommand::declareIt(char *name, char *format, DimCommandHandler *handler, DimServerDns *dns)
|
---|
124 | {
|
---|
125 | // itsTagId = 0;
|
---|
126 | itsDns = dns;
|
---|
127 | itsName = new char[strlen(name)+1];
|
---|
128 | strcpy( itsName, name);
|
---|
129 | itsFormat = new char[strlen(format)+1];
|
---|
130 | strcpy( itsFormat, format);
|
---|
131 | currCmnd = 0;
|
---|
132 | if(handler)
|
---|
133 | itsCommandHandler = handler;
|
---|
134 | else
|
---|
135 | itsCommandHandler = 0;
|
---|
136 | // itsTagId = id_get((void *)this, SRC_DIS);
|
---|
137 | if(!itsDns)
|
---|
138 | {
|
---|
139 | itsId = dis_add_cmnd( name, format, command_routine,
|
---|
140 | // itsTagId);
|
---|
141 | (long)this);
|
---|
142 | DimServer::start();
|
---|
143 | }
|
---|
144 | else
|
---|
145 | {
|
---|
146 | itsId = dis_add_cmnd_dns( itsDns->getDnsId(), name, format, command_routine,
|
---|
147 | // itsTagId);
|
---|
148 | (long)this);
|
---|
149 | // itsDns->addServiceId(itsId);
|
---|
150 | DimServer::start(itsDns);
|
---|
151 | }
|
---|
152 | }
|
---|
153 |
|
---|
154 | extern "C" {
|
---|
155 | /*
|
---|
156 | static void timeout_rout(DimRpc *t)
|
---|
157 | {
|
---|
158 | sleep(t->itsTimeout);
|
---|
159 | t->itsKilled = 1;
|
---|
160 | }
|
---|
161 | */
|
---|
162 | static void rpcin_routine( void *tagp, void *buf, int *size)
|
---|
163 | {
|
---|
164 | time_t tt1 = 0, tt2 = 0;
|
---|
165 |
|
---|
166 | // int *tag = (int *)tagp;
|
---|
167 | // int id = *tag;
|
---|
168 | DimRpc *t;
|
---|
169 | int tout, clientId, ids[2];
|
---|
170 | // long tid;
|
---|
171 |
|
---|
172 | // t = (DimRpc *)id_get_ptr(id, SRC_DIS);
|
---|
173 | t = *(DimRpc **)tagp;
|
---|
174 | t->itsDataIn = buf;
|
---|
175 | t->itsSizeIn = *size;
|
---|
176 | clientId = dis_get_conn_id();
|
---|
177 | tout = dis_get_timeout(t->itsIdOut, clientId);
|
---|
178 | t->itsTimeout = tout;
|
---|
179 | // tid = 0;
|
---|
180 | if(tout > 0)
|
---|
181 | {
|
---|
182 | tt1 = time((time_t *)0);
|
---|
183 | t->itsKilled = 0;
|
---|
184 | // dtq_start_timer(t->itsTimeout,(void(*)(void *))timeout_rout,(void *)t);
|
---|
185 | // tid = dim_start_thread((void(*)(void *))timeout_rout,(void *)t);
|
---|
186 | }
|
---|
187 | DimCore::inCallback = 2;
|
---|
188 | t->rpcHandler();
|
---|
189 | DimCore::inCallback = 0;
|
---|
190 | t->itsDataIn = 0;
|
---|
191 | t->itsSizeIn = 0;
|
---|
192 | if(tout > 0)
|
---|
193 | {
|
---|
194 | tt2 = time((time_t *)0);
|
---|
195 | if((tt2 - tt1) > tout)
|
---|
196 | t->itsKilled = 1;
|
---|
197 | }
|
---|
198 | if(!t->itsKilled)
|
---|
199 | {
|
---|
200 | // if(tid)
|
---|
201 | // {
|
---|
202 | // dtq_stop_timer((void *)t);
|
---|
203 | // dim_stop_thread(tid);
|
---|
204 | // }
|
---|
205 | ids[0] = clientId;
|
---|
206 | ids[1] = 0;
|
---|
207 | dis_selective_update_service(t->itsIdOut, ids);
|
---|
208 | }
|
---|
209 | }
|
---|
210 |
|
---|
211 | }
|
---|
212 |
|
---|
213 | extern "C" {
|
---|
214 | static void rpcout_routine( void *tagp, void **buf, int *size, int *first_time)
|
---|
215 | {
|
---|
216 | // int *tag = (int *)tagp;
|
---|
217 | // int id = *tag;
|
---|
218 | DimRpc *t;
|
---|
219 |
|
---|
220 | if(first_time){}
|
---|
221 | // t = (DimRpc *)id_get_ptr(id, SRC_DIS);
|
---|
222 | t = *(DimRpc**)tagp;
|
---|
223 | *buf = t->itsDataOut;
|
---|
224 | *size = t->itsSizeOut;
|
---|
225 | }
|
---|
226 | }
|
---|
227 |
|
---|
228 | void DimRpc::declareIt(char *name, char *formatin, char *formatout, DimServerDns *dns)
|
---|
229 | {
|
---|
230 | // itsTagId = 0;
|
---|
231 | itsDns = dns;
|
---|
232 | itsName = new char[strlen(name)+1];
|
---|
233 | strcpy( itsName, name);
|
---|
234 | itsNameIn = new char[strlen(name)+1+10];
|
---|
235 | strcpy( itsNameIn, name);
|
---|
236 | strcat(itsNameIn,(char *)"/RpcIn");
|
---|
237 | itsNameOut = new char[strlen(name)+1+10];
|
---|
238 | strcpy( itsNameOut, name);
|
---|
239 | strcat(itsNameOut,(char *)"/RpcOut");
|
---|
240 | itsDataOut = new char[1];
|
---|
241 | itsDataOutSize = itsSizeOut = 1;
|
---|
242 | itsKilled = 0;
|
---|
243 | itsTimeout = 0;
|
---|
244 |
|
---|
245 | // itsTagId = id_get((void *)this, SRC_DIS);
|
---|
246 | if(!itsDns)
|
---|
247 | {
|
---|
248 | itsIdIn = dis_add_cmnd( itsNameIn, formatin,
|
---|
249 | // rpcin_routine, itsTagId);
|
---|
250 | rpcin_routine, (long)this);
|
---|
251 | itsIdOut = dis_add_service( itsNameOut, formatout, 0,0,
|
---|
252 | // rpcout_routine, itsTagId);
|
---|
253 | rpcout_routine, (long)this);
|
---|
254 | DimServer::start();
|
---|
255 | }
|
---|
256 | else
|
---|
257 | {
|
---|
258 | itsIdIn = dis_add_cmnd_dns( itsDns->getDnsId(), itsNameIn, formatin,
|
---|
259 | // rpcin_routine, itsTagId);
|
---|
260 | rpcin_routine, (long)this);
|
---|
261 | itsIdOut = dis_add_service_dns( itsDns->getDnsId(), itsNameOut, formatout, 0,0,
|
---|
262 | // rpcout_routine, itsTagId);
|
---|
263 | rpcout_routine, (long)this);
|
---|
264 | // itsDns->addServiceId(itsIdIn);
|
---|
265 | // itsDns->addServiceId(itsIdOut);
|
---|
266 | DimServer::start(itsDns);
|
---|
267 | }
|
---|
268 | }
|
---|
269 |
|
---|
270 | void DimRpc::storeIt(void *data, int size)
|
---|
271 | {
|
---|
272 |
|
---|
273 | if(!itsDataOutSize)
|
---|
274 | {
|
---|
275 | itsDataOut = new char[size];
|
---|
276 | itsDataOutSize = size;
|
---|
277 | }
|
---|
278 | else if(itsDataOutSize < size)
|
---|
279 | {
|
---|
280 | delete[] (char *)itsDataOut;
|
---|
281 | itsDataOut = new char[size];
|
---|
282 | itsDataOutSize = size;
|
---|
283 | }
|
---|
284 | memcpy(itsDataOut, data, size);
|
---|
285 | itsSizeOut = size;
|
---|
286 | }
|
---|
287 |
|
---|
288 | extern "C" {
|
---|
289 | static void client_exit_user_routine(int*);
|
---|
290 | static void exit_user_routine(int*);
|
---|
291 | static void srv_error_user_routine(int, int, char*);
|
---|
292 | }
|
---|
293 |
|
---|
294 | DimServerDns::DimServerDns(const char *node)
|
---|
295 | {
|
---|
296 | init(node, 0);
|
---|
297 | }
|
---|
298 |
|
---|
299 | DimServerDns::DimServerDns(const char *node, int port)
|
---|
300 | {
|
---|
301 | init(node, port);
|
---|
302 | }
|
---|
303 |
|
---|
304 | DimServerDns::DimServerDns(const char *node, int port, char *name)
|
---|
305 | {
|
---|
306 | init(node, port);
|
---|
307 | DimServer::start(this, name);
|
---|
308 | }
|
---|
309 |
|
---|
310 | #define DisDnsIdBlock 100
|
---|
311 |
|
---|
312 | void DimServerDns::init(const char *node, int port)
|
---|
313 | {
|
---|
314 | if(!itsNode)
|
---|
315 | {
|
---|
316 | itsNode = new char[strlen(node)+1];
|
---|
317 | strcpy(itsNode,node);
|
---|
318 | }
|
---|
319 | itsPort = port;
|
---|
320 | autoStart = 1;
|
---|
321 | itsName = 0;
|
---|
322 | itsServiceIdList = new int[DisDnsIdBlock];
|
---|
323 | itsServiceIdListSize = DisDnsIdBlock;
|
---|
324 | itsNServiceIds = 0;
|
---|
325 | // itsNServices = 0;
|
---|
326 | itsDnsId = DimServer::addDns(node, port);
|
---|
327 | }
|
---|
328 |
|
---|
329 | void DimServerDns::addServiceId(int id)
|
---|
330 | {
|
---|
331 | int *tmp;
|
---|
332 |
|
---|
333 | DISABLE_AST
|
---|
334 | if((itsNServiceIds + 2) > itsServiceIdListSize)
|
---|
335 | {
|
---|
336 | tmp = new int[itsServiceIdListSize + DisDnsIdBlock];
|
---|
337 | memcpy(tmp, itsServiceIdList, itsServiceIdListSize*sizeof(int));
|
---|
338 | delete itsServiceIdList;
|
---|
339 | itsServiceIdList = tmp;
|
---|
340 | itsServiceIdListSize += DisDnsIdBlock;
|
---|
341 | }
|
---|
342 | itsServiceIdList[itsNServiceIds] = id;
|
---|
343 | itsServiceIdList[itsNServiceIds+1] = 0;
|
---|
344 | itsNServiceIds++;
|
---|
345 | ENABLE_AST
|
---|
346 | }
|
---|
347 |
|
---|
348 | int *DimServerDns::getServiceIdList()
|
---|
349 | {
|
---|
350 | int *list;
|
---|
351 | if(itsNServiceIds)
|
---|
352 | list = itsServiceIdList;
|
---|
353 | else
|
---|
354 | list = 0;
|
---|
355 | itsNServiceIds = 0;
|
---|
356 | return list;
|
---|
357 | }
|
---|
358 |
|
---|
359 | DimServerDns::~DimServerDns()
|
---|
360 | {
|
---|
361 | if(itsName)
|
---|
362 | {
|
---|
363 | DimServer::stop(this);
|
---|
364 | delete[] itsName;
|
---|
365 | }
|
---|
366 | if(itsNode)
|
---|
367 | delete[] itsNode;
|
---|
368 | }
|
---|
369 |
|
---|
370 | long DimServerDns::getDnsId()
|
---|
371 | {
|
---|
372 | return itsDnsId;
|
---|
373 | }
|
---|
374 |
|
---|
375 | void DimServerDns::setName(const char *name)
|
---|
376 | {
|
---|
377 | if(!itsName)
|
---|
378 | {
|
---|
379 | itsName = new char[strlen(name)+1];
|
---|
380 | strcpy(itsName,name);
|
---|
381 | }
|
---|
382 | }
|
---|
383 |
|
---|
384 | char *DimServerDns::getName()
|
---|
385 | {
|
---|
386 | return itsName;
|
---|
387 | }
|
---|
388 |
|
---|
389 | void DimServerDns::autoStartOn()
|
---|
390 | {
|
---|
391 | autoStart = 1;
|
---|
392 | }
|
---|
393 |
|
---|
394 | void DimServerDns::autoStartOff()
|
---|
395 | {
|
---|
396 | autoStart = 0;
|
---|
397 | }
|
---|
398 |
|
---|
399 | int DimServerDns::isAutoStart()
|
---|
400 | {
|
---|
401 | return autoStart;
|
---|
402 | }
|
---|
403 |
|
---|
404 | DimServer::DimServer()
|
---|
405 | {
|
---|
406 | itsClientExit = this;
|
---|
407 | itsExit = this;
|
---|
408 | itsSrvError = this;
|
---|
409 | // itsNServices = 0;
|
---|
410 | }
|
---|
411 |
|
---|
412 | DimServer::~DimServer()
|
---|
413 | {
|
---|
414 | if(itsName)
|
---|
415 | {
|
---|
416 | dis_stop_serving();
|
---|
417 | delete[] itsName;
|
---|
418 | }
|
---|
419 | if(clientName)
|
---|
420 | delete[] clientName;
|
---|
421 | if(dimDnsNode)
|
---|
422 | delete[] dimDnsNode;
|
---|
423 | }
|
---|
424 |
|
---|
425 | void DimServer::start(const char *name)
|
---|
426 | {
|
---|
427 | if(!itsName)
|
---|
428 | {
|
---|
429 | itsName = new char[strlen(name)+1];
|
---|
430 | strcpy(itsName,name);
|
---|
431 | }
|
---|
432 | dis_start_serving(itsName);
|
---|
433 | }
|
---|
434 |
|
---|
435 | void DimServer::start(DimServerDns *dns, const char *name)
|
---|
436 | {
|
---|
437 | long dnsid;
|
---|
438 |
|
---|
439 | DISABLE_AST
|
---|
440 | dns->setName(name);
|
---|
441 | dnsid = dns->getDnsId();
|
---|
442 | dis_start_serving_dns(dnsid, (char *)name /*, dns->getServiceIdList()*/);
|
---|
443 | ENABLE_AST
|
---|
444 | }
|
---|
445 | /*
|
---|
446 | void DimServer::threadHandler()
|
---|
447 | {
|
---|
448 | int oldNServices;
|
---|
449 |
|
---|
450 | while(1)
|
---|
451 | {
|
---|
452 | oldNServices = itsNServices;
|
---|
453 | usleep(100000);
|
---|
454 | if(oldNServices == itsNServices)
|
---|
455 | break;
|
---|
456 | }
|
---|
457 | cout << "Starting " << itsNServices << endl;
|
---|
458 | {
|
---|
459 | DISABLE_AST
|
---|
460 | dis_start_serving(itsName);
|
---|
461 | itsNServices = 0;
|
---|
462 | ENABLE_AST
|
---|
463 | }
|
---|
464 |
|
---|
465 | }
|
---|
466 | */
|
---|
467 | void DimServer::start()
|
---|
468 | {
|
---|
469 | // itsNServices++;
|
---|
470 | if((itsName) && (autoStart))
|
---|
471 | {
|
---|
472 | // DimThread::start();
|
---|
473 | dis_start_serving(itsName);
|
---|
474 | }
|
---|
475 | }
|
---|
476 |
|
---|
477 | void DimServer::start(DimServerDns *dns)
|
---|
478 | {
|
---|
479 | long dnsid;
|
---|
480 | char *name;
|
---|
481 | int isAuto;
|
---|
482 |
|
---|
483 | DISABLE_AST
|
---|
484 | // dns->itsNServices++;
|
---|
485 |
|
---|
486 | name = dns->getName();
|
---|
487 | dnsid = dns->getDnsId();
|
---|
488 | isAuto = dns->isAutoStart();
|
---|
489 | if((name) && (isAuto))
|
---|
490 | {
|
---|
491 | // DimThread::start();
|
---|
492 | dis_start_serving_dns(dnsid, (char *)name /*, dns->getServiceIdList()*/);
|
---|
493 | }
|
---|
494 | ENABLE_AST
|
---|
495 | }
|
---|
496 |
|
---|
497 | void DimServer::stop()
|
---|
498 | {
|
---|
499 | dis_stop_serving();
|
---|
500 | }
|
---|
501 |
|
---|
502 | void DimServer::stop(DimServerDns *dns)
|
---|
503 | {
|
---|
504 | dis_stop_serving_dns(dns->getDnsId());
|
---|
505 | }
|
---|
506 |
|
---|
507 | void DimServer::autoStartOn()
|
---|
508 | {
|
---|
509 | autoStart = 1;
|
---|
510 | }
|
---|
511 |
|
---|
512 | void DimServer::autoStartOff()
|
---|
513 | {
|
---|
514 | autoStart = 0;
|
---|
515 | }
|
---|
516 |
|
---|
517 | int DimServer::getClientId()
|
---|
518 | {
|
---|
519 | if(!clientName)
|
---|
520 | clientName = new char[128];
|
---|
521 | clientName[0] = '\0';
|
---|
522 | return dis_get_client(clientName);
|
---|
523 | }
|
---|
524 |
|
---|
525 | char *DimServer::getClientName()
|
---|
526 | {
|
---|
527 | if(!clientName)
|
---|
528 | clientName = new char[128];
|
---|
529 | clientName[0] = '\0';
|
---|
530 | dis_get_client(clientName);
|
---|
531 | return(clientName);
|
---|
532 | }
|
---|
533 | /*
|
---|
534 | char *DimServer::getClientServices()
|
---|
535 | {
|
---|
536 | int id;
|
---|
537 | if((id = dis_get_conn_id()))
|
---|
538 | return dis_get_client_services(id);
|
---|
539 | return (char *)0;
|
---|
540 | }
|
---|
541 |
|
---|
542 | char *DimServer::getClientServices(int clientId)
|
---|
543 | {
|
---|
544 | return dis_get_client_services(clientId);
|
---|
545 | }
|
---|
546 | */
|
---|
547 | char **DimServer::getClientServices()
|
---|
548 | {
|
---|
549 | static TokenString *data = 0;
|
---|
550 | int id, len = 0, index = 0;
|
---|
551 | char *services;
|
---|
552 | static char** list = 0;
|
---|
553 | char *sep;
|
---|
554 |
|
---|
555 | if(data)
|
---|
556 | {
|
---|
557 | delete data;
|
---|
558 | data = 0;
|
---|
559 | }
|
---|
560 | if(list)
|
---|
561 | {
|
---|
562 | delete[] list;
|
---|
563 | list = 0;
|
---|
564 | }
|
---|
565 | if((id = dis_get_conn_id()))
|
---|
566 | {
|
---|
567 | services = dis_get_client_services(id);
|
---|
568 | if(services)
|
---|
569 | {
|
---|
570 | data = new TokenString(services,(char *)"\n");
|
---|
571 | len = data->getNTokens();
|
---|
572 | list = new char*[len];
|
---|
573 | while(data->getToken(list[index]))
|
---|
574 | {
|
---|
575 | data->getToken(sep);
|
---|
576 | index++;
|
---|
577 | }
|
---|
578 | }
|
---|
579 | }
|
---|
580 | if(!len)
|
---|
581 | list = new char*[1];
|
---|
582 | list[index] = 0;
|
---|
583 | return list;
|
---|
584 | }
|
---|
585 |
|
---|
586 | void DimServer::setClientExitHandler(int clientId)
|
---|
587 | {
|
---|
588 | dis_set_client_exit_handler(clientId, 1);
|
---|
589 | }
|
---|
590 |
|
---|
591 | void DimServer::clearClientExitHandler(int clientId)
|
---|
592 | {
|
---|
593 | dis_set_client_exit_handler(clientId, 0);
|
---|
594 | }
|
---|
595 |
|
---|
596 | void DimServer::addClientExitHandler(DimClientExitHandler *handler)
|
---|
597 | {
|
---|
598 | DimServer::itsClientExit = handler;
|
---|
599 | dis_add_client_exit_handler(client_exit_user_routine);
|
---|
600 | }
|
---|
601 |
|
---|
602 | void DimServer::addClientExitHandler()
|
---|
603 | {
|
---|
604 | DimServer::itsClientExit = this;
|
---|
605 | dis_add_client_exit_handler(client_exit_user_routine);
|
---|
606 | }
|
---|
607 |
|
---|
608 | void DimServer::addExitHandler(DimExitHandler *handler)
|
---|
609 | {
|
---|
610 | DimServer::itsExit = handler;
|
---|
611 | dis_add_exit_handler(exit_user_routine);
|
---|
612 | }
|
---|
613 |
|
---|
614 | void DimServer::addErrorHandler(DimErrorHandler *handler)
|
---|
615 | {
|
---|
616 | DimServer::itsSrvError = handler;
|
---|
617 | dis_add_error_handler(srv_error_user_routine);
|
---|
618 | }
|
---|
619 |
|
---|
620 | int DimServer::setDnsNode(const char *node)
|
---|
621 | {
|
---|
622 | return dis_set_dns_node((char *)node);
|
---|
623 | }
|
---|
624 |
|
---|
625 | int DimServer::setDnsNode(const char *node, int port)
|
---|
626 | {
|
---|
627 | dis_set_dns_port(port);
|
---|
628 | return dis_set_dns_node((char *)node);
|
---|
629 | }
|
---|
630 |
|
---|
631 | long DimServer::addDns(const char *node, int port)
|
---|
632 | {
|
---|
633 | return dis_add_dns((char *)node, port);
|
---|
634 | }
|
---|
635 | char *DimServer::getDnsNode()
|
---|
636 | {
|
---|
637 | if(!dimDnsNode)
|
---|
638 | dimDnsNode = new char[256];
|
---|
639 | if(dis_get_dns_node(dimDnsNode))
|
---|
640 | return dimDnsNode;
|
---|
641 | else
|
---|
642 | return 0;
|
---|
643 | }
|
---|
644 |
|
---|
645 | int DimServer::getDnsPort()
|
---|
646 | {
|
---|
647 | return dis_get_dns_port();
|
---|
648 | }
|
---|
649 |
|
---|
650 | void DimServer::setWriteTimeout(int secs)
|
---|
651 | {
|
---|
652 | dim_set_write_timeout(secs);
|
---|
653 | }
|
---|
654 |
|
---|
655 | int DimServer::getWriteTimeout()
|
---|
656 | {
|
---|
657 | return dim_get_write_timeout();
|
---|
658 | }
|
---|
659 |
|
---|
660 | void DimServer::addExitHandler()
|
---|
661 | {
|
---|
662 | DimServer::itsExit = this;
|
---|
663 | dis_add_exit_handler(exit_user_routine);
|
---|
664 | }
|
---|
665 |
|
---|
666 | void DimServer::addErrorHandler()
|
---|
667 | {
|
---|
668 | DimServer::itsSrvError = this;
|
---|
669 | dis_add_error_handler(srv_error_user_routine);
|
---|
670 | }
|
---|
671 |
|
---|
672 | extern "C" {
|
---|
673 | static void client_exit_user_routine(int *idp)
|
---|
674 | {
|
---|
675 | int id = *idp;
|
---|
676 |
|
---|
677 | id++;
|
---|
678 | DimCore::inCallback = 2;
|
---|
679 | DimServer::itsClientExit->clientExitHandler();
|
---|
680 | DimCore::inCallback = 0;
|
---|
681 | }
|
---|
682 |
|
---|
683 | static void exit_user_routine(int *idp)
|
---|
684 | {
|
---|
685 | // int id = *idp;
|
---|
686 |
|
---|
687 | // id++;
|
---|
688 | DimCore::inCallback = 2;
|
---|
689 | DimServer::itsExit->exitHandler(*idp);
|
---|
690 | DimCore::inCallback = 0;
|
---|
691 | }
|
---|
692 |
|
---|
693 | static void srv_error_user_routine(int severity, int code, char *msg)
|
---|
694 | {
|
---|
695 |
|
---|
696 | DimCore::inCallback = 2;
|
---|
697 | DimServer::itsSrvError->errorHandler(severity, code, msg);
|
---|
698 | DimCore::inCallback = 0;
|
---|
699 | }
|
---|
700 |
|
---|
701 | }
|
---|
702 |
|
---|
703 |
|
---|
704 | DimService::DimService()
|
---|
705 | {
|
---|
706 | // itsTagId = 0;
|
---|
707 | }
|
---|
708 |
|
---|
709 | DimService::DimService(const char *name, int &value)
|
---|
710 | {
|
---|
711 | itsData = &value;
|
---|
712 | itsSize = sizeof(int);
|
---|
713 | itsType = DisINT;
|
---|
714 | declareIt((char *)name, (char *)"L", 0, 0);
|
---|
715 | }
|
---|
716 |
|
---|
717 | DimService::DimService(const char *name, float &value)
|
---|
718 | {
|
---|
719 | itsData = &value;
|
---|
720 | itsSize = sizeof(float);
|
---|
721 | itsType = DisFLOAT;
|
---|
722 | declareIt((char *)name, (char *)"F", 0, 0);
|
---|
723 | }
|
---|
724 |
|
---|
725 | DimService::DimService(const char *name, double &value)
|
---|
726 | {
|
---|
727 | itsData = &value;
|
---|
728 | itsSize = sizeof(double);
|
---|
729 | itsType = DisDOUBLE;
|
---|
730 | declareIt((char *)name, (char *)"D", 0, 0);
|
---|
731 | }
|
---|
732 |
|
---|
733 | DimService::DimService(const char *name, longlong &value)
|
---|
734 | {
|
---|
735 | itsData = &value;
|
---|
736 | itsSize = sizeof(longlong);
|
---|
737 | itsType = DisXLONG;
|
---|
738 | declareIt((char *)name, (char *)"X", 0, 0);
|
---|
739 | }
|
---|
740 |
|
---|
741 | DimService::DimService(const char *name, short &value)
|
---|
742 | {
|
---|
743 | itsData = &value;
|
---|
744 | itsSize = sizeof(short);
|
---|
745 | itsType = DisSHORT;
|
---|
746 | declareIt((char *)name, (char *)"S", 0, 0);
|
---|
747 | }
|
---|
748 |
|
---|
749 | DimService::DimService(const char *name, char *string)
|
---|
750 | {
|
---|
751 | itsData = string;
|
---|
752 | itsSize = strlen(string)+1;
|
---|
753 | itsType = DisSTRING;
|
---|
754 | declareIt((char *)name, (char *)"C", 0, 0);
|
---|
755 | }
|
---|
756 |
|
---|
757 | DimService::DimService(const char *name, char *format, void *structure, int size)
|
---|
758 | {
|
---|
759 | itsData = structure;
|
---|
760 | itsSize = size;
|
---|
761 | itsType = DisPOINTER;
|
---|
762 | declareIt((char *)name, (char *)format, 0, 0);
|
---|
763 | }
|
---|
764 |
|
---|
765 | DimService::DimService(const char *name, char *format, DimServiceHandler *handler)
|
---|
766 | {
|
---|
767 | itsData = 0;
|
---|
768 | itsSize = 0;
|
---|
769 | itsType = DisPOINTER;
|
---|
770 | declareIt((char *)name, (char *)format, handler, 0);
|
---|
771 | }
|
---|
772 |
|
---|
773 | DimService::DimService(const char *name, const char *format, void *structure, int size)
|
---|
774 | {
|
---|
775 | itsData = structure;
|
---|
776 | itsSize = size;
|
---|
777 | itsType = DisPOINTER;
|
---|
778 | declareIt((char *)name, (char *)format, 0, 0);
|
---|
779 | }
|
---|
780 |
|
---|
781 | DimService::DimService(const char *name, const char *format, DimServiceHandler *handler)
|
---|
782 | {
|
---|
783 | itsData = 0;
|
---|
784 | itsSize = 0;
|
---|
785 | itsType = DisPOINTER;
|
---|
786 | declareIt((char *)name, (char *)format, handler, 0);
|
---|
787 | }
|
---|
788 |
|
---|
789 | // with Dns
|
---|
790 |
|
---|
791 | DimService::DimService(DimServerDns *dns, const char *name, int &value)
|
---|
792 | {
|
---|
793 | itsData = &value;
|
---|
794 | itsSize = sizeof(int);
|
---|
795 | itsType = DisINT;
|
---|
796 | declareIt((char *)name, (char *)"L", 0, dns);
|
---|
797 | }
|
---|
798 |
|
---|
799 | DimService::DimService(DimServerDns *dns, const char *name, float &value)
|
---|
800 | {
|
---|
801 | itsData = &value;
|
---|
802 | itsSize = sizeof(float);
|
---|
803 | itsType = DisFLOAT;
|
---|
804 | declareIt((char *)name, (char *)"F", 0, dns);
|
---|
805 | }
|
---|
806 |
|
---|
807 | DimService::DimService(DimServerDns *dns, const char *name, double &value)
|
---|
808 | {
|
---|
809 | itsData = &value;
|
---|
810 | itsSize = sizeof(double);
|
---|
811 | itsType = DisDOUBLE;
|
---|
812 | declareIt((char *)name, (char *)"D", 0, dns);
|
---|
813 | }
|
---|
814 |
|
---|
815 | DimService::DimService(DimServerDns *dns, const char *name, longlong &value)
|
---|
816 | {
|
---|
817 | itsData = &value;
|
---|
818 | itsSize = sizeof(longlong);
|
---|
819 | itsType = DisXLONG;
|
---|
820 | declareIt((char *)name, (char *)"X", 0, dns);
|
---|
821 | }
|
---|
822 |
|
---|
823 | DimService::DimService(DimServerDns *dns, const char *name, short &value)
|
---|
824 | {
|
---|
825 | itsData = &value;
|
---|
826 | itsSize = sizeof(short);
|
---|
827 | itsType = DisSHORT;
|
---|
828 | declareIt((char *)name, (char *)"S", 0, dns);
|
---|
829 | }
|
---|
830 |
|
---|
831 | DimService::DimService(DimServerDns *dns, const char *name, char *string)
|
---|
832 | {
|
---|
833 | itsData = string;
|
---|
834 | itsSize = strlen(string)+1;
|
---|
835 | itsType = DisSTRING;
|
---|
836 | declareIt((char *)name, (char *)"C", 0, dns);
|
---|
837 | }
|
---|
838 |
|
---|
839 | DimService::DimService(DimServerDns *dns, const char *name, char *format, void *structure, int size)
|
---|
840 | {
|
---|
841 | itsData = structure;
|
---|
842 | itsSize = size;
|
---|
843 | itsType = DisPOINTER;
|
---|
844 | declareIt((char *)name, (char *)format, 0, dns);
|
---|
845 | }
|
---|
846 |
|
---|
847 | DimService::DimService(DimServerDns *dns, const char *name, char *format, DimServiceHandler *handler)
|
---|
848 | {
|
---|
849 | itsData = 0;
|
---|
850 | itsSize = 0;
|
---|
851 | itsType = DisPOINTER;
|
---|
852 | declareIt((char *)name, (char *)format, handler, dns);
|
---|
853 | }
|
---|
854 |
|
---|
855 |
|
---|
856 | DimService::DimService(DimServerDns *dns, const char *name, const char *format, void *structure, int size)
|
---|
857 | {
|
---|
858 | itsData = structure;
|
---|
859 | itsSize = size;
|
---|
860 | itsType = DisPOINTER;
|
---|
861 | declareIt((char *)name, (char *)format, 0, dns);
|
---|
862 | }
|
---|
863 |
|
---|
864 | DimService::DimService(DimServerDns *dns, const char *name, const char *format, DimServiceHandler *handler)
|
---|
865 | {
|
---|
866 | itsData = 0;
|
---|
867 | itsSize = 0;
|
---|
868 | itsType = DisPOINTER;
|
---|
869 | declareIt((char *)name, (char *)format, handler, dns);
|
---|
870 | }
|
---|
871 |
|
---|
872 |
|
---|
873 | DimService::~DimService()
|
---|
874 | {
|
---|
875 | delete[] itsName;
|
---|
876 | if(itsDataSize)
|
---|
877 | delete[] (char *)itsData;
|
---|
878 | // if(itsTagId)
|
---|
879 | // id_free(itsTagId, SRC_DIS);
|
---|
880 | dis_remove_service( itsId );
|
---|
881 | }
|
---|
882 |
|
---|
883 | int DimService::updateService()
|
---|
884 | {
|
---|
885 | return dis_update_service( itsId );
|
---|
886 | }
|
---|
887 |
|
---|
888 | int DimService::updateService( int &value )
|
---|
889 | {
|
---|
890 | if( itsType == DisINT)
|
---|
891 | {
|
---|
892 | itsData = &value;
|
---|
893 | return dis_update_service( itsId );
|
---|
894 | }
|
---|
895 | return -1;
|
---|
896 | }
|
---|
897 |
|
---|
898 | int DimService::updateService( float &value )
|
---|
899 | {
|
---|
900 | if( itsType == DisFLOAT) {
|
---|
901 | itsData = &value;
|
---|
902 | return dis_update_service( itsId );
|
---|
903 | }
|
---|
904 | return -1;
|
---|
905 | }
|
---|
906 |
|
---|
907 | int DimService::updateService( double &value )
|
---|
908 | {
|
---|
909 | if( itsType == DisDOUBLE) {
|
---|
910 | itsData = &value;
|
---|
911 | return dis_update_service( itsId );
|
---|
912 | }
|
---|
913 | return -1;
|
---|
914 | }
|
---|
915 |
|
---|
916 | int DimService::updateService( longlong &value )
|
---|
917 | {
|
---|
918 | if( itsType == DisXLONG)
|
---|
919 | {
|
---|
920 | itsData = &value;
|
---|
921 | return dis_update_service( itsId );
|
---|
922 | }
|
---|
923 | return -1;
|
---|
924 | }
|
---|
925 |
|
---|
926 | int DimService::updateService( short &value )
|
---|
927 | {
|
---|
928 | if( itsType == DisSHORT)
|
---|
929 | {
|
---|
930 | itsData = &value;
|
---|
931 | return dis_update_service( itsId );
|
---|
932 | }
|
---|
933 | return -1;
|
---|
934 | }
|
---|
935 |
|
---|
936 | int DimService::updateService( char *string )
|
---|
937 | {
|
---|
938 | if( itsType == DisSTRING)
|
---|
939 | {
|
---|
940 | itsData = string;
|
---|
941 | itsSize = strlen(string)+1;
|
---|
942 | return dis_update_service( itsId );
|
---|
943 | }
|
---|
944 | return -1;
|
---|
945 | }
|
---|
946 |
|
---|
947 | int DimService::updateService( void *structure, int size )
|
---|
948 | {
|
---|
949 | if( itsType == DisPOINTER)
|
---|
950 | {
|
---|
951 | itsData = structure;
|
---|
952 | itsSize = size;
|
---|
953 | return dis_update_service( itsId );
|
---|
954 | }
|
---|
955 | return -1;
|
---|
956 | }
|
---|
957 |
|
---|
958 | int DimService::selectiveUpdateService(int *cids)
|
---|
959 | {
|
---|
960 | if( cids == 0)
|
---|
961 | {
|
---|
962 | int ids[2];
|
---|
963 | ids[0] = DimServer::getClientId();
|
---|
964 | ids[1] = 0;
|
---|
965 | return dis_selective_update_service( itsId, ids );
|
---|
966 | }
|
---|
967 | return dis_selective_update_service( itsId, cids );
|
---|
968 | }
|
---|
969 |
|
---|
970 | int DimService::selectiveUpdateService( int &value, int *cids)
|
---|
971 | {
|
---|
972 | if( itsType == DisINT)
|
---|
973 | {
|
---|
974 | itsData = &value;
|
---|
975 | if( cids == 0)
|
---|
976 | {
|
---|
977 | int ids[2];
|
---|
978 | ids[0] = DimServer::getClientId();
|
---|
979 | ids[1] = 0;
|
---|
980 | return dis_selective_update_service( itsId, ids );
|
---|
981 | }
|
---|
982 | return dis_selective_update_service( itsId, cids );
|
---|
983 | }
|
---|
984 | return -1;
|
---|
985 | }
|
---|
986 |
|
---|
987 | int DimService::selectiveUpdateService( float &value, int *cids )
|
---|
988 | {
|
---|
989 | if( itsType == DisFLOAT)
|
---|
990 | {
|
---|
991 | itsData = &value;
|
---|
992 | if( cids == 0)
|
---|
993 | {
|
---|
994 | int ids[2];
|
---|
995 | ids[0] = DimServer::getClientId();
|
---|
996 | ids[1] = 0;
|
---|
997 | return dis_selective_update_service( itsId, ids );
|
---|
998 | }
|
---|
999 | return dis_selective_update_service( itsId, cids );
|
---|
1000 | }
|
---|
1001 | return -1;
|
---|
1002 | }
|
---|
1003 |
|
---|
1004 | int DimService::selectiveUpdateService( double &value, int *cids )
|
---|
1005 | {
|
---|
1006 | if( itsType == DisDOUBLE)
|
---|
1007 | {
|
---|
1008 | itsData = &value;
|
---|
1009 | if( cids == 0)
|
---|
1010 | {
|
---|
1011 | int ids[2];
|
---|
1012 | ids[0] = DimServer::getClientId();
|
---|
1013 | ids[1] = 0;
|
---|
1014 | return dis_selective_update_service( itsId, ids );
|
---|
1015 | }
|
---|
1016 | return dis_selective_update_service( itsId, cids );
|
---|
1017 | }
|
---|
1018 | return -1;
|
---|
1019 | }
|
---|
1020 |
|
---|
1021 | int DimService::selectiveUpdateService( longlong &value, int *cids )
|
---|
1022 | {
|
---|
1023 | if( itsType == DisXLONG)
|
---|
1024 | {
|
---|
1025 | itsData = &value;
|
---|
1026 | if( cids == 0)
|
---|
1027 | {
|
---|
1028 | int ids[2];
|
---|
1029 | ids[0] = DimServer::getClientId();
|
---|
1030 | ids[1] = 0;
|
---|
1031 | return dis_selective_update_service( itsId, ids );
|
---|
1032 | }
|
---|
1033 | return dis_selective_update_service( itsId, cids );
|
---|
1034 | }
|
---|
1035 | return -1;
|
---|
1036 | }
|
---|
1037 |
|
---|
1038 | int DimService::selectiveUpdateService( short &value, int *cids )
|
---|
1039 | {
|
---|
1040 | if( itsType == DisSHORT)
|
---|
1041 | {
|
---|
1042 | itsData = &value;
|
---|
1043 | if( cids == 0)
|
---|
1044 | {
|
---|
1045 | int ids[2];
|
---|
1046 | ids[0] = DimServer::getClientId();
|
---|
1047 | ids[1] = 0;
|
---|
1048 | return dis_selective_update_service( itsId, ids );
|
---|
1049 | }
|
---|
1050 | return dis_selective_update_service( itsId, cids );
|
---|
1051 | }
|
---|
1052 | return -1;
|
---|
1053 | }
|
---|
1054 |
|
---|
1055 | int DimService::selectiveUpdateService( char *string, int *cids )
|
---|
1056 | {
|
---|
1057 | if( itsType == DisSTRING)
|
---|
1058 | {
|
---|
1059 | itsData = string;
|
---|
1060 | itsSize = strlen(string)+1;
|
---|
1061 | if( cids == 0)
|
---|
1062 | {
|
---|
1063 | int ids[2];
|
---|
1064 | ids[0] = DimServer::getClientId();
|
---|
1065 | ids[1] = 0;
|
---|
1066 | return dis_selective_update_service( itsId, ids );
|
---|
1067 | }
|
---|
1068 | return dis_selective_update_service( itsId, cids );
|
---|
1069 | }
|
---|
1070 | return -1;
|
---|
1071 | }
|
---|
1072 |
|
---|
1073 | int DimService::selectiveUpdateService( void *structure, int size, int *cids )
|
---|
1074 | {
|
---|
1075 | if( itsType == DisPOINTER)
|
---|
1076 | {
|
---|
1077 | itsData = structure;
|
---|
1078 | itsSize = size;
|
---|
1079 | if( cids == 0)
|
---|
1080 | {
|
---|
1081 | int ids[2];
|
---|
1082 | ids[0] = DimServer::getClientId();
|
---|
1083 | ids[1] = 0;
|
---|
1084 | return dis_selective_update_service( itsId, ids );
|
---|
1085 | }
|
---|
1086 | return dis_selective_update_service( itsId, cids );
|
---|
1087 | }
|
---|
1088 | return -1;
|
---|
1089 | }
|
---|
1090 |
|
---|
1091 | void DimService::setQuality(int quality)
|
---|
1092 | {
|
---|
1093 | dis_set_quality( itsId, quality );
|
---|
1094 | }
|
---|
1095 |
|
---|
1096 | void DimService::setTimestamp(int secs, int millisecs)
|
---|
1097 | {
|
---|
1098 | dis_set_timestamp( itsId, secs, millisecs );
|
---|
1099 | }
|
---|
1100 |
|
---|
1101 | void DimService::setData(void *data, int size)
|
---|
1102 | {
|
---|
1103 | storeIt(data, size);
|
---|
1104 | }
|
---|
1105 |
|
---|
1106 | void DimService::setData(int &data)
|
---|
1107 | {
|
---|
1108 | storeIt(&data, sizeof(int));
|
---|
1109 | }
|
---|
1110 |
|
---|
1111 | void DimService::setData(float &data)
|
---|
1112 | {
|
---|
1113 | storeIt(&data, sizeof(float));
|
---|
1114 | }
|
---|
1115 |
|
---|
1116 | void DimService::setData(double &data)
|
---|
1117 | {
|
---|
1118 | storeIt(&data, sizeof(double));
|
---|
1119 | }
|
---|
1120 |
|
---|
1121 | void DimService::setData(longlong &data)
|
---|
1122 | {
|
---|
1123 | storeIt(&data, sizeof(longlong));
|
---|
1124 | }
|
---|
1125 |
|
---|
1126 | void DimService::setData(short &data)
|
---|
1127 | {
|
---|
1128 | storeIt(&data, sizeof(short));
|
---|
1129 | }
|
---|
1130 |
|
---|
1131 | void DimService::setData(char *data)
|
---|
1132 | {
|
---|
1133 | storeIt(data, strlen(data)+1);
|
---|
1134 | }
|
---|
1135 |
|
---|
1136 | char *DimService::getName()
|
---|
1137 | {
|
---|
1138 | return itsName;
|
---|
1139 | }
|
---|
1140 |
|
---|
1141 | int DimService::getTimeout(int clientId)
|
---|
1142 | {
|
---|
1143 | return dis_get_timeout(itsId, clientId);
|
---|
1144 | }
|
---|
1145 |
|
---|
1146 | int DimService::getNClients()
|
---|
1147 | {
|
---|
1148 | return dis_get_n_clients( itsId );
|
---|
1149 | }
|
---|
1150 |
|
---|
1151 |
|
---|
1152 | CmndInfo::CmndInfo(void *data, int datasize, int tsecs, int tmillisecs)
|
---|
1153 | {
|
---|
1154 | itsData = new char[datasize];
|
---|
1155 | itsDataSize = datasize;
|
---|
1156 | secs = tsecs;
|
---|
1157 | millisecs = tmillisecs;
|
---|
1158 | memcpy(itsData, data, datasize);
|
---|
1159 | }
|
---|
1160 |
|
---|
1161 | CmndInfo::~CmndInfo()
|
---|
1162 | {
|
---|
1163 | delete[] (char *)itsData;
|
---|
1164 | }
|
---|
1165 |
|
---|
1166 |
|
---|
1167 | DimCommand::DimCommand(const char *name, char *format)
|
---|
1168 | {
|
---|
1169 | declareIt( (char *)name, (char *)format, 0, 0);
|
---|
1170 | }
|
---|
1171 |
|
---|
1172 | DimCommand::DimCommand(const char *name, char *format, DimCommandHandler *handler)
|
---|
1173 | {
|
---|
1174 | declareIt( (char *)name, (char *)format, handler, 0);
|
---|
1175 | }
|
---|
1176 |
|
---|
1177 | DimCommand::DimCommand(DimServerDns *dns, const char *name, char *format)
|
---|
1178 | {
|
---|
1179 | declareIt( (char *)name, (char *)format, 0, dns);
|
---|
1180 | }
|
---|
1181 |
|
---|
1182 | DimCommand::DimCommand(DimServerDns *dns, const char *name, char *format, DimCommandHandler *handler)
|
---|
1183 | {
|
---|
1184 | declareIt( (char *)name, (char *)format, handler, dns);
|
---|
1185 | }
|
---|
1186 |
|
---|
1187 |
|
---|
1188 | DimCommand::DimCommand(const char *name, const char *format)
|
---|
1189 | {
|
---|
1190 | declareIt( (char *)name, (char *)format, 0, 0);
|
---|
1191 | }
|
---|
1192 |
|
---|
1193 | DimCommand::DimCommand(const char *name, const char *format, DimCommandHandler *handler)
|
---|
1194 | {
|
---|
1195 | declareIt( (char *)name, (char *)format, handler, 0);
|
---|
1196 | }
|
---|
1197 |
|
---|
1198 | DimCommand::DimCommand(DimServerDns *dns, const char *name, const char *format)
|
---|
1199 | {
|
---|
1200 | declareIt( (char *)name, (char *)format, 0, dns);
|
---|
1201 | }
|
---|
1202 |
|
---|
1203 | DimCommand::DimCommand(DimServerDns *dns, const char *name, const char *format, DimCommandHandler *handler)
|
---|
1204 | {
|
---|
1205 | declareIt( (char *)name, (char *)format, handler, dns);
|
---|
1206 | }
|
---|
1207 |
|
---|
1208 | int DimCommand::getNext()
|
---|
1209 | {
|
---|
1210 | CmndInfo *cmndptr;
|
---|
1211 | if(currCmnd)
|
---|
1212 | {
|
---|
1213 | delete currCmnd;
|
---|
1214 | currCmnd = 0;
|
---|
1215 | itsData = 0;
|
---|
1216 | itsSize = 0;
|
---|
1217 | }
|
---|
1218 | if ((cmndptr = (CmndInfo *)itsCmndList.removeHead()))
|
---|
1219 | {
|
---|
1220 | currCmnd = cmndptr;
|
---|
1221 | itsData = currCmnd->itsData;
|
---|
1222 | itsSize = currCmnd->itsDataSize;
|
---|
1223 | secs = currCmnd->secs;
|
---|
1224 | millisecs = currCmnd->millisecs;
|
---|
1225 | return(1);
|
---|
1226 | }
|
---|
1227 | return(0);
|
---|
1228 | }
|
---|
1229 |
|
---|
1230 | int DimCommand::hasNext()
|
---|
1231 | {
|
---|
1232 | if ((CmndInfo *)itsCmndList.getHead())
|
---|
1233 | {
|
---|
1234 | return(1);
|
---|
1235 | }
|
---|
1236 | return(0);
|
---|
1237 | }
|
---|
1238 |
|
---|
1239 | void *DimCommand::getData()
|
---|
1240 | {
|
---|
1241 | return itsData;
|
---|
1242 | }
|
---|
1243 |
|
---|
1244 | int DimCommand::getInt()
|
---|
1245 | {
|
---|
1246 | return *(int *)itsData;
|
---|
1247 | }
|
---|
1248 |
|
---|
1249 | float DimCommand::getFloat()
|
---|
1250 | {
|
---|
1251 | return *(float *)itsData;
|
---|
1252 | }
|
---|
1253 |
|
---|
1254 | double DimCommand::getDouble()
|
---|
1255 | {
|
---|
1256 | return *(double *)itsData;
|
---|
1257 | }
|
---|
1258 |
|
---|
1259 | longlong DimCommand::getLonglong()
|
---|
1260 | {
|
---|
1261 | return *(longlong *)itsData;
|
---|
1262 | }
|
---|
1263 |
|
---|
1264 | short DimCommand::getShort()
|
---|
1265 | {
|
---|
1266 | return *(short *)itsData;
|
---|
1267 | }
|
---|
1268 |
|
---|
1269 | char *DimCommand::getString()
|
---|
1270 | {
|
---|
1271 | return (char *)itsData;
|
---|
1272 | }
|
---|
1273 |
|
---|
1274 | int DimCommand::getSize()
|
---|
1275 | {
|
---|
1276 | return itsSize;
|
---|
1277 | }
|
---|
1278 |
|
---|
1279 | char *DimCommand::getFormat()
|
---|
1280 | {
|
---|
1281 | return itsFormat;
|
---|
1282 | }
|
---|
1283 |
|
---|
1284 | int DimCommand::getTimestamp()
|
---|
1285 | {
|
---|
1286 | int ret;
|
---|
1287 |
|
---|
1288 | if(secs == 0)
|
---|
1289 | ret = dis_get_timestamp(itsId, &secs, &millisecs);
|
---|
1290 | return(secs);
|
---|
1291 | }
|
---|
1292 |
|
---|
1293 | int DimCommand::getTimestampMillisecs()
|
---|
1294 | {
|
---|
1295 | return(millisecs);
|
---|
1296 | }
|
---|
1297 |
|
---|
1298 | void DimCommand::commandHandler()
|
---|
1299 | {
|
---|
1300 | CmndInfo *cmndptr;
|
---|
1301 | int tsecs, tmillisecs;
|
---|
1302 |
|
---|
1303 | tsecs = getTimestamp();
|
---|
1304 | tmillisecs = getTimestampMillisecs();
|
---|
1305 | cmndptr = new CmndInfo(getData(), getSize(), tsecs, tmillisecs);
|
---|
1306 | itsCmndList.add(cmndptr);
|
---|
1307 | }
|
---|
1308 |
|
---|
1309 | char *DimCommand::getName()
|
---|
1310 | {
|
---|
1311 | return itsName;
|
---|
1312 | }
|
---|
1313 |
|
---|
1314 | DimCommand::~DimCommand()
|
---|
1315 | {
|
---|
1316 | delete[] itsName;
|
---|
1317 | delete[] itsFormat;
|
---|
1318 | // if(itsTagId)
|
---|
1319 | // id_free(itsTagId, SRC_DIS);
|
---|
1320 | dis_remove_service( itsId );
|
---|
1321 | }
|
---|
1322 |
|
---|
1323 | DimRpc::DimRpc()
|
---|
1324 | {
|
---|
1325 | }
|
---|
1326 |
|
---|
1327 | DimRpc::DimRpc(const char *name, const char *formatin, const char *formatout)
|
---|
1328 | {
|
---|
1329 | declareIt( (char *)name, (char *)formatin, (char *)formatout, 0);
|
---|
1330 | }
|
---|
1331 |
|
---|
1332 | DimRpc::DimRpc(DimServerDns *dns, const char *name, const char *formatin, const char *formatout)
|
---|
1333 | {
|
---|
1334 | declareIt( (char *)name, (char *)formatin, (char *)formatout, dns);
|
---|
1335 | }
|
---|
1336 |
|
---|
1337 | DimRpc::~DimRpc()
|
---|
1338 | {
|
---|
1339 | delete[] itsName;
|
---|
1340 | delete[] itsNameIn;
|
---|
1341 | delete[] itsNameOut;
|
---|
1342 | // if(itsTagId)
|
---|
1343 | // id_free(itsTagId, SRC_DIS);
|
---|
1344 | dis_remove_service( itsIdIn );
|
---|
1345 | dis_remove_service( itsIdOut );
|
---|
1346 | }
|
---|
1347 |
|
---|
1348 | void *DimRpc::getData()
|
---|
1349 | {
|
---|
1350 | return itsDataIn;
|
---|
1351 | }
|
---|
1352 |
|
---|
1353 | int DimRpc::getInt()
|
---|
1354 | {
|
---|
1355 | return *(int *)itsDataIn;
|
---|
1356 | }
|
---|
1357 |
|
---|
1358 | float DimRpc::getFloat()
|
---|
1359 | {
|
---|
1360 | return *(float *)itsDataIn;
|
---|
1361 | }
|
---|
1362 |
|
---|
1363 | double DimRpc::getDouble()
|
---|
1364 | {
|
---|
1365 | return *(double *)itsDataIn;
|
---|
1366 | }
|
---|
1367 |
|
---|
1368 | longlong DimRpc::getLonglong()
|
---|
1369 | {
|
---|
1370 | return *(longlong *)itsDataIn;
|
---|
1371 | }
|
---|
1372 |
|
---|
1373 | short DimRpc::getShort()
|
---|
1374 | {
|
---|
1375 | return *(short *)itsDataIn;
|
---|
1376 | }
|
---|
1377 |
|
---|
1378 | char *DimRpc::getString()
|
---|
1379 | {
|
---|
1380 | return (char *)itsDataIn;
|
---|
1381 | }
|
---|
1382 |
|
---|
1383 | int DimRpc::getSize()
|
---|
1384 | {
|
---|
1385 | return itsSizeIn;
|
---|
1386 | }
|
---|
1387 |
|
---|
1388 | void DimRpc::setData(void *data, int size)
|
---|
1389 | {
|
---|
1390 | storeIt(data,size);
|
---|
1391 | }
|
---|
1392 |
|
---|
1393 | void DimRpc::setData(int &data)
|
---|
1394 | {
|
---|
1395 | storeIt(&data,sizeof(int));
|
---|
1396 | }
|
---|
1397 |
|
---|
1398 | void DimRpc::setData(float &data)
|
---|
1399 | {
|
---|
1400 | storeIt(&data,sizeof(float));
|
---|
1401 | }
|
---|
1402 |
|
---|
1403 | void DimRpc::setData(double &data)
|
---|
1404 | {
|
---|
1405 | storeIt(&data,sizeof(double));
|
---|
1406 | }
|
---|
1407 |
|
---|
1408 | void DimRpc::setData(longlong &data)
|
---|
1409 | {
|
---|
1410 | storeIt(&data,sizeof(longlong));
|
---|
1411 | }
|
---|
1412 |
|
---|
1413 | void DimRpc::setData(short &data)
|
---|
1414 | {
|
---|
1415 | storeIt(&data,sizeof(short));
|
---|
1416 | }
|
---|
1417 |
|
---|
1418 | void DimRpc::setData(char *data)
|
---|
1419 | {
|
---|
1420 | storeIt(data,strlen(data)+1);
|
---|
1421 | }
|
---|
1422 |
|
---|
1423 | char *DimRpc::getName()
|
---|
1424 | {
|
---|
1425 | return itsName;
|
---|
1426 | }
|
---|