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 | // if(itsName)
|
---|
365 | // delete[] itsName;
|
---|
366 | }
|
---|
367 | if(itsNode)
|
---|
368 | delete[] itsNode;
|
---|
369 | }
|
---|
370 |
|
---|
371 | long DimServerDns::getDnsId()
|
---|
372 | {
|
---|
373 | return itsDnsId;
|
---|
374 | }
|
---|
375 |
|
---|
376 | void DimServerDns::setName(const char *name)
|
---|
377 | {
|
---|
378 | if(!itsName)
|
---|
379 | {
|
---|
380 | itsName = new char[strlen(name)+1];
|
---|
381 | strcpy(itsName,name);
|
---|
382 | }
|
---|
383 | }
|
---|
384 |
|
---|
385 | void DimServerDns::clearName()
|
---|
386 | {
|
---|
387 | if(itsName)
|
---|
388 | {
|
---|
389 | delete[] itsName;
|
---|
390 | itsName = 0;
|
---|
391 | }
|
---|
392 | }
|
---|
393 |
|
---|
394 | char *DimServerDns::getName()
|
---|
395 | {
|
---|
396 | return itsName;
|
---|
397 | }
|
---|
398 |
|
---|
399 | void DimServerDns::autoStartOn()
|
---|
400 | {
|
---|
401 | autoStart = 1;
|
---|
402 | }
|
---|
403 |
|
---|
404 | void DimServerDns::autoStartOff()
|
---|
405 | {
|
---|
406 | autoStart = 0;
|
---|
407 | }
|
---|
408 |
|
---|
409 | int DimServerDns::isAutoStart()
|
---|
410 | {
|
---|
411 | return autoStart;
|
---|
412 | }
|
---|
413 |
|
---|
414 | DimServer::DimServer()
|
---|
415 | {
|
---|
416 | itsClientExit = this;
|
---|
417 | itsExit = this;
|
---|
418 | itsSrvError = this;
|
---|
419 | // itsNServices = 0;
|
---|
420 | }
|
---|
421 |
|
---|
422 | DimServer::~DimServer()
|
---|
423 | {
|
---|
424 | if(itsName)
|
---|
425 | {
|
---|
426 | dis_stop_serving();
|
---|
427 | delete[] itsName;
|
---|
428 | }
|
---|
429 | if(clientName)
|
---|
430 | delete[] clientName;
|
---|
431 | if(dimDnsNode)
|
---|
432 | delete[] dimDnsNode;
|
---|
433 | }
|
---|
434 |
|
---|
435 | void DimServer::start(const char *name)
|
---|
436 | {
|
---|
437 | if(!itsName)
|
---|
438 | {
|
---|
439 | itsName = new char[strlen(name)+1];
|
---|
440 | strcpy(itsName,name);
|
---|
441 | }
|
---|
442 | dis_start_serving(itsName);
|
---|
443 | }
|
---|
444 |
|
---|
445 | void DimServer::start(DimServerDns *dns, const char *name)
|
---|
446 | {
|
---|
447 | long dnsid;
|
---|
448 |
|
---|
449 | DISABLE_AST
|
---|
450 | dns->setName(name);
|
---|
451 | dnsid = dns->getDnsId();
|
---|
452 | dis_start_serving_dns(dnsid, (char *)name /*, dns->getServiceIdList()*/);
|
---|
453 | ENABLE_AST
|
---|
454 | }
|
---|
455 | /*
|
---|
456 | void DimServer::threadHandler()
|
---|
457 | {
|
---|
458 | int oldNServices;
|
---|
459 |
|
---|
460 | while(1)
|
---|
461 | {
|
---|
462 | oldNServices = itsNServices;
|
---|
463 | usleep(100000);
|
---|
464 | if(oldNServices == itsNServices)
|
---|
465 | break;
|
---|
466 | }
|
---|
467 | cout << "Starting " << itsNServices << endl;
|
---|
468 | {
|
---|
469 | DISABLE_AST
|
---|
470 | dis_start_serving(itsName);
|
---|
471 | itsNServices = 0;
|
---|
472 | ENABLE_AST
|
---|
473 | }
|
---|
474 |
|
---|
475 | }
|
---|
476 | */
|
---|
477 | void DimServer::start()
|
---|
478 | {
|
---|
479 | // itsNServices++;
|
---|
480 | if((itsName) && (autoStart))
|
---|
481 | {
|
---|
482 | // DimThread::start();
|
---|
483 | dis_start_serving(itsName);
|
---|
484 | }
|
---|
485 | }
|
---|
486 |
|
---|
487 | void DimServer::start(DimServerDns *dns)
|
---|
488 | {
|
---|
489 | long dnsid;
|
---|
490 | char *name;
|
---|
491 | int isAuto;
|
---|
492 |
|
---|
493 | DISABLE_AST
|
---|
494 | // dns->itsNServices++;
|
---|
495 |
|
---|
496 | name = dns->getName();
|
---|
497 | dnsid = dns->getDnsId();
|
---|
498 | isAuto = dns->isAutoStart();
|
---|
499 | if((name) && (isAuto))
|
---|
500 | {
|
---|
501 | // DimThread::start();
|
---|
502 | dis_start_serving_dns(dnsid, (char *)name /*, dns->getServiceIdList()*/);
|
---|
503 | }
|
---|
504 | ENABLE_AST
|
---|
505 | }
|
---|
506 |
|
---|
507 | void DimServer::stop()
|
---|
508 | {
|
---|
509 | dis_stop_serving();
|
---|
510 | if(itsName)
|
---|
511 | {
|
---|
512 | delete[] itsName;
|
---|
513 | itsName = 0;
|
---|
514 | }
|
---|
515 | }
|
---|
516 |
|
---|
517 | void DimServer::stop(DimServerDns *dns)
|
---|
518 | {
|
---|
519 | dis_stop_serving_dns(dns->getDnsId());
|
---|
520 | dns->clearName();
|
---|
521 | }
|
---|
522 |
|
---|
523 | void DimServer::autoStartOn()
|
---|
524 | {
|
---|
525 | autoStart = 1;
|
---|
526 | }
|
---|
527 |
|
---|
528 | void DimServer::autoStartOff()
|
---|
529 | {
|
---|
530 | autoStart = 0;
|
---|
531 | }
|
---|
532 |
|
---|
533 | int DimServer::getClientId()
|
---|
534 | {
|
---|
535 | if(!clientName)
|
---|
536 | clientName = new char[128];
|
---|
537 | clientName[0] = '\0';
|
---|
538 | return dis_get_client(clientName);
|
---|
539 | }
|
---|
540 |
|
---|
541 | char *DimServer::getClientName()
|
---|
542 | {
|
---|
543 | if(!clientName)
|
---|
544 | clientName = new char[128];
|
---|
545 | clientName[0] = '\0';
|
---|
546 | dis_get_client(clientName);
|
---|
547 | return(clientName);
|
---|
548 | }
|
---|
549 | /*
|
---|
550 | char *DimServer::getClientServices()
|
---|
551 | {
|
---|
552 | int id;
|
---|
553 | if((id = dis_get_conn_id()))
|
---|
554 | return dis_get_client_services(id);
|
---|
555 | return (char *)0;
|
---|
556 | }
|
---|
557 |
|
---|
558 | char *DimServer::getClientServices(int clientId)
|
---|
559 | {
|
---|
560 | return dis_get_client_services(clientId);
|
---|
561 | }
|
---|
562 | */
|
---|
563 | char **DimServer::getClientServices()
|
---|
564 | {
|
---|
565 | static TokenString *data = 0;
|
---|
566 | int id, len = 0, index = 0;
|
---|
567 | char *services;
|
---|
568 | static char** list = 0;
|
---|
569 | char *sep;
|
---|
570 |
|
---|
571 | if(data)
|
---|
572 | {
|
---|
573 | delete data;
|
---|
574 | data = 0;
|
---|
575 | }
|
---|
576 | if(list)
|
---|
577 | {
|
---|
578 | delete[] list;
|
---|
579 | list = 0;
|
---|
580 | }
|
---|
581 | if((id = dis_get_conn_id()))
|
---|
582 | {
|
---|
583 | services = dis_get_client_services(id);
|
---|
584 | if(services)
|
---|
585 | {
|
---|
586 | data = new TokenString(services,(char *)"\n");
|
---|
587 | len = data->getNTokens();
|
---|
588 | list = new char*[len];
|
---|
589 | while(data->getToken(list[index]))
|
---|
590 | {
|
---|
591 | data->getToken(sep);
|
---|
592 | index++;
|
---|
593 | }
|
---|
594 | }
|
---|
595 | }
|
---|
596 | if(!len)
|
---|
597 | list = new char*[1];
|
---|
598 | list[index] = 0;
|
---|
599 | return list;
|
---|
600 | }
|
---|
601 |
|
---|
602 | void DimServer::setClientExitHandler(int clientId)
|
---|
603 | {
|
---|
604 | dis_set_client_exit_handler(clientId, 1);
|
---|
605 | }
|
---|
606 |
|
---|
607 | void DimServer::clearClientExitHandler(int clientId)
|
---|
608 | {
|
---|
609 | dis_set_client_exit_handler(clientId, 0);
|
---|
610 | }
|
---|
611 |
|
---|
612 | void DimServer::addClientExitHandler(DimClientExitHandler *handler)
|
---|
613 | {
|
---|
614 | DimServer::itsClientExit = handler;
|
---|
615 | dis_add_client_exit_handler(client_exit_user_routine);
|
---|
616 | }
|
---|
617 |
|
---|
618 | void DimServer::addClientExitHandler()
|
---|
619 | {
|
---|
620 | DimServer::itsClientExit = this;
|
---|
621 | dis_add_client_exit_handler(client_exit_user_routine);
|
---|
622 | }
|
---|
623 |
|
---|
624 | void DimServer::addExitHandler(DimExitHandler *handler)
|
---|
625 | {
|
---|
626 | DimServer::itsExit = handler;
|
---|
627 | dis_add_exit_handler(exit_user_routine);
|
---|
628 | }
|
---|
629 |
|
---|
630 | void DimServer::addErrorHandler(DimErrorHandler *handler)
|
---|
631 | {
|
---|
632 | DimServer::itsSrvError = handler;
|
---|
633 | dis_add_error_handler(srv_error_user_routine);
|
---|
634 | }
|
---|
635 |
|
---|
636 | int DimServer::setDnsNode(const char *node)
|
---|
637 | {
|
---|
638 | return dis_set_dns_node((char *)node);
|
---|
639 | }
|
---|
640 |
|
---|
641 | int DimServer::setDnsNode(const char *node, int port)
|
---|
642 | {
|
---|
643 | dis_set_dns_port(port);
|
---|
644 | return dis_set_dns_node((char *)node);
|
---|
645 | }
|
---|
646 |
|
---|
647 | long DimServer::addDns(const char *node, int port)
|
---|
648 | {
|
---|
649 | return dis_add_dns((char *)node, port);
|
---|
650 | }
|
---|
651 | char *DimServer::getDnsNode()
|
---|
652 | {
|
---|
653 | if(!dimDnsNode)
|
---|
654 | dimDnsNode = new char[256];
|
---|
655 | if(dis_get_dns_node(dimDnsNode))
|
---|
656 | return dimDnsNode;
|
---|
657 | else
|
---|
658 | return 0;
|
---|
659 | }
|
---|
660 |
|
---|
661 | int DimServer::getDnsPort()
|
---|
662 | {
|
---|
663 | return dis_get_dns_port();
|
---|
664 | }
|
---|
665 |
|
---|
666 | void DimServer::setWriteTimeout(int secs)
|
---|
667 | {
|
---|
668 | dim_set_write_timeout(secs);
|
---|
669 | }
|
---|
670 |
|
---|
671 | int DimServer::getWriteTimeout()
|
---|
672 | {
|
---|
673 | return dim_get_write_timeout();
|
---|
674 | }
|
---|
675 |
|
---|
676 | void DimServer::addExitHandler()
|
---|
677 | {
|
---|
678 | DimServer::itsExit = this;
|
---|
679 | dis_add_exit_handler(exit_user_routine);
|
---|
680 | }
|
---|
681 |
|
---|
682 | void DimServer::addErrorHandler()
|
---|
683 | {
|
---|
684 | DimServer::itsSrvError = this;
|
---|
685 | dis_add_error_handler(srv_error_user_routine);
|
---|
686 | }
|
---|
687 |
|
---|
688 | extern "C" {
|
---|
689 | static void client_exit_user_routine(int *idp)
|
---|
690 | {
|
---|
691 | int id = *idp;
|
---|
692 |
|
---|
693 | id++;
|
---|
694 | DimCore::inCallback = 2;
|
---|
695 | DimServer::itsClientExit->clientExitHandler();
|
---|
696 | DimCore::inCallback = 0;
|
---|
697 | }
|
---|
698 |
|
---|
699 | static void exit_user_routine(int *idp)
|
---|
700 | {
|
---|
701 | // int id = *idp;
|
---|
702 |
|
---|
703 | // id++;
|
---|
704 | DimCore::inCallback = 2;
|
---|
705 | DimServer::itsExit->exitHandler(*idp);
|
---|
706 | DimCore::inCallback = 0;
|
---|
707 | }
|
---|
708 |
|
---|
709 | static void srv_error_user_routine(int severity, int code, char *msg)
|
---|
710 | {
|
---|
711 |
|
---|
712 | DimCore::inCallback = 2;
|
---|
713 | DimServer::itsSrvError->errorHandler(severity, code, msg);
|
---|
714 | DimCore::inCallback = 0;
|
---|
715 | }
|
---|
716 |
|
---|
717 | }
|
---|
718 |
|
---|
719 |
|
---|
720 | DimService::DimService()
|
---|
721 | {
|
---|
722 | // itsTagId = 0;
|
---|
723 | }
|
---|
724 |
|
---|
725 | DimService::DimService(const char *name, int &value)
|
---|
726 | {
|
---|
727 | itsData = &value;
|
---|
728 | itsSize = sizeof(int);
|
---|
729 | itsType = DisINT;
|
---|
730 | declareIt((char *)name, (char *)"L", 0, 0);
|
---|
731 | }
|
---|
732 |
|
---|
733 | DimService::DimService(const char *name, float &value)
|
---|
734 | {
|
---|
735 | itsData = &value;
|
---|
736 | itsSize = sizeof(float);
|
---|
737 | itsType = DisFLOAT;
|
---|
738 | declareIt((char *)name, (char *)"F", 0, 0);
|
---|
739 | }
|
---|
740 |
|
---|
741 | DimService::DimService(const char *name, double &value)
|
---|
742 | {
|
---|
743 | itsData = &value;
|
---|
744 | itsSize = sizeof(double);
|
---|
745 | itsType = DisDOUBLE;
|
---|
746 | declareIt((char *)name, (char *)"D", 0, 0);
|
---|
747 | }
|
---|
748 |
|
---|
749 | DimService::DimService(const char *name, longlong &value)
|
---|
750 | {
|
---|
751 | itsData = &value;
|
---|
752 | itsSize = sizeof(longlong);
|
---|
753 | itsType = DisXLONG;
|
---|
754 | declareIt((char *)name, (char *)"X", 0, 0);
|
---|
755 | }
|
---|
756 |
|
---|
757 | DimService::DimService(const char *name, short &value)
|
---|
758 | {
|
---|
759 | itsData = &value;
|
---|
760 | itsSize = sizeof(short);
|
---|
761 | itsType = DisSHORT;
|
---|
762 | declareIt((char *)name, (char *)"S", 0, 0);
|
---|
763 | }
|
---|
764 |
|
---|
765 | DimService::DimService(const char *name, char *string)
|
---|
766 | {
|
---|
767 | itsData = string;
|
---|
768 | itsSize = strlen(string)+1;
|
---|
769 | itsType = DisSTRING;
|
---|
770 | declareIt((char *)name, (char *)"C", 0, 0);
|
---|
771 | }
|
---|
772 |
|
---|
773 | DimService::DimService(const char *name, 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, 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 | DimService::DimService(const char *name, const char *format, void *structure, int size)
|
---|
790 | {
|
---|
791 | itsData = structure;
|
---|
792 | itsSize = size;
|
---|
793 | itsType = DisPOINTER;
|
---|
794 | declareIt((char *)name, (char *)format, 0, 0);
|
---|
795 | }
|
---|
796 |
|
---|
797 | DimService::DimService(const char *name, const char *format, DimServiceHandler *handler)
|
---|
798 | {
|
---|
799 | itsData = 0;
|
---|
800 | itsSize = 0;
|
---|
801 | itsType = DisPOINTER;
|
---|
802 | declareIt((char *)name, (char *)format, handler, 0);
|
---|
803 | }
|
---|
804 |
|
---|
805 | // with Dns
|
---|
806 |
|
---|
807 | DimService::DimService(DimServerDns *dns, const char *name, int &value)
|
---|
808 | {
|
---|
809 | itsData = &value;
|
---|
810 | itsSize = sizeof(int);
|
---|
811 | itsType = DisINT;
|
---|
812 | declareIt((char *)name, (char *)"L", 0, dns);
|
---|
813 | }
|
---|
814 |
|
---|
815 | DimService::DimService(DimServerDns *dns, const char *name, float &value)
|
---|
816 | {
|
---|
817 | itsData = &value;
|
---|
818 | itsSize = sizeof(float);
|
---|
819 | itsType = DisFLOAT;
|
---|
820 | declareIt((char *)name, (char *)"F", 0, dns);
|
---|
821 | }
|
---|
822 |
|
---|
823 | DimService::DimService(DimServerDns *dns, const char *name, double &value)
|
---|
824 | {
|
---|
825 | itsData = &value;
|
---|
826 | itsSize = sizeof(double);
|
---|
827 | itsType = DisDOUBLE;
|
---|
828 | declareIt((char *)name, (char *)"D", 0, dns);
|
---|
829 | }
|
---|
830 |
|
---|
831 | DimService::DimService(DimServerDns *dns, const char *name, longlong &value)
|
---|
832 | {
|
---|
833 | itsData = &value;
|
---|
834 | itsSize = sizeof(longlong);
|
---|
835 | itsType = DisXLONG;
|
---|
836 | declareIt((char *)name, (char *)"X", 0, dns);
|
---|
837 | }
|
---|
838 |
|
---|
839 | DimService::DimService(DimServerDns *dns, const char *name, short &value)
|
---|
840 | {
|
---|
841 | itsData = &value;
|
---|
842 | itsSize = sizeof(short);
|
---|
843 | itsType = DisSHORT;
|
---|
844 | declareIt((char *)name, (char *)"S", 0, dns);
|
---|
845 | }
|
---|
846 |
|
---|
847 | DimService::DimService(DimServerDns *dns, const char *name, char *string)
|
---|
848 | {
|
---|
849 | itsData = string;
|
---|
850 | itsSize = strlen(string)+1;
|
---|
851 | itsType = DisSTRING;
|
---|
852 | declareIt((char *)name, (char *)"C", 0, dns);
|
---|
853 | }
|
---|
854 |
|
---|
855 | DimService::DimService(DimServerDns *dns, const char *name, char *format, void *structure, int size)
|
---|
856 | {
|
---|
857 | itsData = structure;
|
---|
858 | itsSize = size;
|
---|
859 | itsType = DisPOINTER;
|
---|
860 | declareIt((char *)name, (char *)format, 0, dns);
|
---|
861 | }
|
---|
862 |
|
---|
863 | DimService::DimService(DimServerDns *dns, const char *name, char *format, DimServiceHandler *handler)
|
---|
864 | {
|
---|
865 | itsData = 0;
|
---|
866 | itsSize = 0;
|
---|
867 | itsType = DisPOINTER;
|
---|
868 | declareIt((char *)name, (char *)format, handler, dns);
|
---|
869 | }
|
---|
870 |
|
---|
871 |
|
---|
872 | DimService::DimService(DimServerDns *dns, const char *name, const char *format, void *structure, int size)
|
---|
873 | {
|
---|
874 | itsData = structure;
|
---|
875 | itsSize = size;
|
---|
876 | itsType = DisPOINTER;
|
---|
877 | declareIt((char *)name, (char *)format, 0, dns);
|
---|
878 | }
|
---|
879 |
|
---|
880 | DimService::DimService(DimServerDns *dns, const char *name, const char *format, DimServiceHandler *handler)
|
---|
881 | {
|
---|
882 | itsData = 0;
|
---|
883 | itsSize = 0;
|
---|
884 | itsType = DisPOINTER;
|
---|
885 | declareIt((char *)name, (char *)format, handler, dns);
|
---|
886 | }
|
---|
887 |
|
---|
888 |
|
---|
889 | DimService::~DimService()
|
---|
890 | {
|
---|
891 | delete[] itsName;
|
---|
892 | if(itsDataSize)
|
---|
893 | delete[] (char *)itsData;
|
---|
894 | // if(itsTagId)
|
---|
895 | // id_free(itsTagId, SRC_DIS);
|
---|
896 | dis_remove_service( itsId );
|
---|
897 | }
|
---|
898 |
|
---|
899 | int DimService::updateService()
|
---|
900 | {
|
---|
901 | return dis_update_service( itsId );
|
---|
902 | }
|
---|
903 |
|
---|
904 | int DimService::updateService( int &value )
|
---|
905 | {
|
---|
906 | if( itsType == DisINT)
|
---|
907 | {
|
---|
908 | itsData = &value;
|
---|
909 | return dis_update_service( itsId );
|
---|
910 | }
|
---|
911 | return -1;
|
---|
912 | }
|
---|
913 |
|
---|
914 | int DimService::updateService( float &value )
|
---|
915 | {
|
---|
916 | if( itsType == DisFLOAT) {
|
---|
917 | itsData = &value;
|
---|
918 | return dis_update_service( itsId );
|
---|
919 | }
|
---|
920 | return -1;
|
---|
921 | }
|
---|
922 |
|
---|
923 | int DimService::updateService( double &value )
|
---|
924 | {
|
---|
925 | if( itsType == DisDOUBLE) {
|
---|
926 | itsData = &value;
|
---|
927 | return dis_update_service( itsId );
|
---|
928 | }
|
---|
929 | return -1;
|
---|
930 | }
|
---|
931 |
|
---|
932 | int DimService::updateService( longlong &value )
|
---|
933 | {
|
---|
934 | if( itsType == DisXLONG)
|
---|
935 | {
|
---|
936 | itsData = &value;
|
---|
937 | return dis_update_service( itsId );
|
---|
938 | }
|
---|
939 | return -1;
|
---|
940 | }
|
---|
941 |
|
---|
942 | int DimService::updateService( short &value )
|
---|
943 | {
|
---|
944 | if( itsType == DisSHORT)
|
---|
945 | {
|
---|
946 | itsData = &value;
|
---|
947 | return dis_update_service( itsId );
|
---|
948 | }
|
---|
949 | return -1;
|
---|
950 | }
|
---|
951 |
|
---|
952 | int DimService::updateService( char *string )
|
---|
953 | {
|
---|
954 | if( itsType == DisSTRING)
|
---|
955 | {
|
---|
956 | itsData = string;
|
---|
957 | itsSize = strlen(string)+1;
|
---|
958 | return dis_update_service( itsId );
|
---|
959 | }
|
---|
960 | return -1;
|
---|
961 | }
|
---|
962 |
|
---|
963 | int DimService::updateService( void *structure, int size )
|
---|
964 | {
|
---|
965 | if( itsType == DisPOINTER)
|
---|
966 | {
|
---|
967 | itsData = structure;
|
---|
968 | itsSize = size;
|
---|
969 | return dis_update_service( itsId );
|
---|
970 | }
|
---|
971 | return -1;
|
---|
972 | }
|
---|
973 |
|
---|
974 | int DimService::selectiveUpdateService(int *cids)
|
---|
975 | {
|
---|
976 | if( cids == 0)
|
---|
977 | {
|
---|
978 | int ids[2];
|
---|
979 | ids[0] = DimServer::getClientId();
|
---|
980 | ids[1] = 0;
|
---|
981 | return dis_selective_update_service( itsId, ids );
|
---|
982 | }
|
---|
983 | return dis_selective_update_service( itsId, cids );
|
---|
984 | }
|
---|
985 |
|
---|
986 | int DimService::selectiveUpdateService( int &value, int *cids)
|
---|
987 | {
|
---|
988 | if( itsType == DisINT)
|
---|
989 | {
|
---|
990 | itsData = &value;
|
---|
991 | if( cids == 0)
|
---|
992 | {
|
---|
993 | int ids[2];
|
---|
994 | ids[0] = DimServer::getClientId();
|
---|
995 | ids[1] = 0;
|
---|
996 | return dis_selective_update_service( itsId, ids );
|
---|
997 | }
|
---|
998 | return dis_selective_update_service( itsId, cids );
|
---|
999 | }
|
---|
1000 | return -1;
|
---|
1001 | }
|
---|
1002 |
|
---|
1003 | int DimService::selectiveUpdateService( float &value, int *cids )
|
---|
1004 | {
|
---|
1005 | if( itsType == DisFLOAT)
|
---|
1006 | {
|
---|
1007 | itsData = &value;
|
---|
1008 | if( cids == 0)
|
---|
1009 | {
|
---|
1010 | int ids[2];
|
---|
1011 | ids[0] = DimServer::getClientId();
|
---|
1012 | ids[1] = 0;
|
---|
1013 | return dis_selective_update_service( itsId, ids );
|
---|
1014 | }
|
---|
1015 | return dis_selective_update_service( itsId, cids );
|
---|
1016 | }
|
---|
1017 | return -1;
|
---|
1018 | }
|
---|
1019 |
|
---|
1020 | int DimService::selectiveUpdateService( double &value, int *cids )
|
---|
1021 | {
|
---|
1022 | if( itsType == DisDOUBLE)
|
---|
1023 | {
|
---|
1024 | itsData = &value;
|
---|
1025 | if( cids == 0)
|
---|
1026 | {
|
---|
1027 | int ids[2];
|
---|
1028 | ids[0] = DimServer::getClientId();
|
---|
1029 | ids[1] = 0;
|
---|
1030 | return dis_selective_update_service( itsId, ids );
|
---|
1031 | }
|
---|
1032 | return dis_selective_update_service( itsId, cids );
|
---|
1033 | }
|
---|
1034 | return -1;
|
---|
1035 | }
|
---|
1036 |
|
---|
1037 | int DimService::selectiveUpdateService( longlong &value, int *cids )
|
---|
1038 | {
|
---|
1039 | if( itsType == DisXLONG)
|
---|
1040 | {
|
---|
1041 | itsData = &value;
|
---|
1042 | if( cids == 0)
|
---|
1043 | {
|
---|
1044 | int ids[2];
|
---|
1045 | ids[0] = DimServer::getClientId();
|
---|
1046 | ids[1] = 0;
|
---|
1047 | return dis_selective_update_service( itsId, ids );
|
---|
1048 | }
|
---|
1049 | return dis_selective_update_service( itsId, cids );
|
---|
1050 | }
|
---|
1051 | return -1;
|
---|
1052 | }
|
---|
1053 |
|
---|
1054 | int DimService::selectiveUpdateService( short &value, int *cids )
|
---|
1055 | {
|
---|
1056 | if( itsType == DisSHORT)
|
---|
1057 | {
|
---|
1058 | itsData = &value;
|
---|
1059 | if( cids == 0)
|
---|
1060 | {
|
---|
1061 | int ids[2];
|
---|
1062 | ids[0] = DimServer::getClientId();
|
---|
1063 | ids[1] = 0;
|
---|
1064 | return dis_selective_update_service( itsId, ids );
|
---|
1065 | }
|
---|
1066 | return dis_selective_update_service( itsId, cids );
|
---|
1067 | }
|
---|
1068 | return -1;
|
---|
1069 | }
|
---|
1070 |
|
---|
1071 | int DimService::selectiveUpdateService( char *string, int *cids )
|
---|
1072 | {
|
---|
1073 | if( itsType == DisSTRING)
|
---|
1074 | {
|
---|
1075 | itsData = string;
|
---|
1076 | itsSize = strlen(string)+1;
|
---|
1077 | if( cids == 0)
|
---|
1078 | {
|
---|
1079 | int ids[2];
|
---|
1080 | ids[0] = DimServer::getClientId();
|
---|
1081 | ids[1] = 0;
|
---|
1082 | return dis_selective_update_service( itsId, ids );
|
---|
1083 | }
|
---|
1084 | return dis_selective_update_service( itsId, cids );
|
---|
1085 | }
|
---|
1086 | return -1;
|
---|
1087 | }
|
---|
1088 |
|
---|
1089 | int DimService::selectiveUpdateService( void *structure, int size, int *cids )
|
---|
1090 | {
|
---|
1091 | if( itsType == DisPOINTER)
|
---|
1092 | {
|
---|
1093 | itsData = structure;
|
---|
1094 | itsSize = size;
|
---|
1095 | if( cids == 0)
|
---|
1096 | {
|
---|
1097 | int ids[2];
|
---|
1098 | ids[0] = DimServer::getClientId();
|
---|
1099 | ids[1] = 0;
|
---|
1100 | return dis_selective_update_service( itsId, ids );
|
---|
1101 | }
|
---|
1102 | return dis_selective_update_service( itsId, cids );
|
---|
1103 | }
|
---|
1104 | return -1;
|
---|
1105 | }
|
---|
1106 |
|
---|
1107 | void DimService::setQuality(int quality)
|
---|
1108 | {
|
---|
1109 | dis_set_quality( itsId, quality );
|
---|
1110 | }
|
---|
1111 |
|
---|
1112 | void DimService::setTimestamp(int secs, int millisecs)
|
---|
1113 | {
|
---|
1114 | dis_set_timestamp( itsId, secs, millisecs );
|
---|
1115 | }
|
---|
1116 |
|
---|
1117 | void DimService::setData(void *data, int size)
|
---|
1118 | {
|
---|
1119 | storeIt(data, size);
|
---|
1120 | }
|
---|
1121 |
|
---|
1122 | void DimService::setData(int &data)
|
---|
1123 | {
|
---|
1124 | storeIt(&data, sizeof(int));
|
---|
1125 | }
|
---|
1126 |
|
---|
1127 | void DimService::setData(float &data)
|
---|
1128 | {
|
---|
1129 | storeIt(&data, sizeof(float));
|
---|
1130 | }
|
---|
1131 |
|
---|
1132 | void DimService::setData(double &data)
|
---|
1133 | {
|
---|
1134 | storeIt(&data, sizeof(double));
|
---|
1135 | }
|
---|
1136 |
|
---|
1137 | void DimService::setData(longlong &data)
|
---|
1138 | {
|
---|
1139 | storeIt(&data, sizeof(longlong));
|
---|
1140 | }
|
---|
1141 |
|
---|
1142 | void DimService::setData(short &data)
|
---|
1143 | {
|
---|
1144 | storeIt(&data, sizeof(short));
|
---|
1145 | }
|
---|
1146 |
|
---|
1147 | void DimService::setData(char *data)
|
---|
1148 | {
|
---|
1149 | storeIt(data, strlen(data)+1);
|
---|
1150 | }
|
---|
1151 |
|
---|
1152 | char *DimService::getName()
|
---|
1153 | {
|
---|
1154 | return itsName;
|
---|
1155 | }
|
---|
1156 |
|
---|
1157 | int DimService::getTimeout(int clientId)
|
---|
1158 | {
|
---|
1159 | return dis_get_timeout(itsId, clientId);
|
---|
1160 | }
|
---|
1161 |
|
---|
1162 | int DimService::getNClients()
|
---|
1163 | {
|
---|
1164 | return dis_get_n_clients( itsId );
|
---|
1165 | }
|
---|
1166 |
|
---|
1167 |
|
---|
1168 | CmndInfo::CmndInfo(void *data, int datasize, int tsecs, int tmillisecs)
|
---|
1169 | {
|
---|
1170 | itsData = new char[datasize];
|
---|
1171 | itsDataSize = datasize;
|
---|
1172 | secs = tsecs;
|
---|
1173 | millisecs = tmillisecs;
|
---|
1174 | memcpy(itsData, data, datasize);
|
---|
1175 | }
|
---|
1176 |
|
---|
1177 | CmndInfo::~CmndInfo()
|
---|
1178 | {
|
---|
1179 | delete[] (char *)itsData;
|
---|
1180 | }
|
---|
1181 |
|
---|
1182 |
|
---|
1183 | DimCommand::DimCommand(const char *name, char *format)
|
---|
1184 | {
|
---|
1185 | declareIt( (char *)name, (char *)format, 0, 0);
|
---|
1186 | }
|
---|
1187 |
|
---|
1188 | DimCommand::DimCommand(const char *name, char *format, DimCommandHandler *handler)
|
---|
1189 | {
|
---|
1190 | declareIt( (char *)name, (char *)format, handler, 0);
|
---|
1191 | }
|
---|
1192 |
|
---|
1193 | DimCommand::DimCommand(DimServerDns *dns, const char *name, char *format)
|
---|
1194 | {
|
---|
1195 | declareIt( (char *)name, (char *)format, 0, dns);
|
---|
1196 | }
|
---|
1197 |
|
---|
1198 | DimCommand::DimCommand(DimServerDns *dns, const char *name, char *format, DimCommandHandler *handler)
|
---|
1199 | {
|
---|
1200 | declareIt( (char *)name, (char *)format, handler, dns);
|
---|
1201 | }
|
---|
1202 |
|
---|
1203 |
|
---|
1204 | DimCommand::DimCommand(const char *name, const char *format)
|
---|
1205 | {
|
---|
1206 | declareIt( (char *)name, (char *)format, 0, 0);
|
---|
1207 | }
|
---|
1208 |
|
---|
1209 | DimCommand::DimCommand(const char *name, const char *format, DimCommandHandler *handler)
|
---|
1210 | {
|
---|
1211 | declareIt( (char *)name, (char *)format, handler, 0);
|
---|
1212 | }
|
---|
1213 |
|
---|
1214 | DimCommand::DimCommand(DimServerDns *dns, const char *name, const char *format)
|
---|
1215 | {
|
---|
1216 | declareIt( (char *)name, (char *)format, 0, dns);
|
---|
1217 | }
|
---|
1218 |
|
---|
1219 | DimCommand::DimCommand(DimServerDns *dns, const char *name, const char *format, DimCommandHandler *handler)
|
---|
1220 | {
|
---|
1221 | declareIt( (char *)name, (char *)format, handler, dns);
|
---|
1222 | }
|
---|
1223 |
|
---|
1224 | int DimCommand::getNext()
|
---|
1225 | {
|
---|
1226 | CmndInfo *cmndptr;
|
---|
1227 | if(currCmnd)
|
---|
1228 | {
|
---|
1229 | delete currCmnd;
|
---|
1230 | currCmnd = 0;
|
---|
1231 | itsData = 0;
|
---|
1232 | itsSize = 0;
|
---|
1233 | }
|
---|
1234 | if ((cmndptr = (CmndInfo *)itsCmndList.removeHead()))
|
---|
1235 | {
|
---|
1236 | currCmnd = cmndptr;
|
---|
1237 | itsData = currCmnd->itsData;
|
---|
1238 | itsSize = currCmnd->itsDataSize;
|
---|
1239 | secs = currCmnd->secs;
|
---|
1240 | millisecs = currCmnd->millisecs;
|
---|
1241 | return(1);
|
---|
1242 | }
|
---|
1243 | return(0);
|
---|
1244 | }
|
---|
1245 |
|
---|
1246 | int DimCommand::hasNext()
|
---|
1247 | {
|
---|
1248 | if ((CmndInfo *)itsCmndList.getHead())
|
---|
1249 | {
|
---|
1250 | return(1);
|
---|
1251 | }
|
---|
1252 | return(0);
|
---|
1253 | }
|
---|
1254 |
|
---|
1255 | void *DimCommand::getData()
|
---|
1256 | {
|
---|
1257 | return itsData;
|
---|
1258 | }
|
---|
1259 |
|
---|
1260 | int DimCommand::getInt()
|
---|
1261 | {
|
---|
1262 | return *(int *)itsData;
|
---|
1263 | }
|
---|
1264 |
|
---|
1265 | float DimCommand::getFloat()
|
---|
1266 | {
|
---|
1267 | return *(float *)itsData;
|
---|
1268 | }
|
---|
1269 |
|
---|
1270 | double DimCommand::getDouble()
|
---|
1271 | {
|
---|
1272 | return *(double *)itsData;
|
---|
1273 | }
|
---|
1274 |
|
---|
1275 | longlong DimCommand::getLonglong()
|
---|
1276 | {
|
---|
1277 | return *(longlong *)itsData;
|
---|
1278 | }
|
---|
1279 |
|
---|
1280 | short DimCommand::getShort()
|
---|
1281 | {
|
---|
1282 | return *(short *)itsData;
|
---|
1283 | }
|
---|
1284 |
|
---|
1285 | char *DimCommand::getString()
|
---|
1286 | {
|
---|
1287 | return (char *)itsData;
|
---|
1288 | }
|
---|
1289 |
|
---|
1290 | int DimCommand::getSize()
|
---|
1291 | {
|
---|
1292 | return itsSize;
|
---|
1293 | }
|
---|
1294 |
|
---|
1295 | char *DimCommand::getFormat()
|
---|
1296 | {
|
---|
1297 | return itsFormat;
|
---|
1298 | }
|
---|
1299 |
|
---|
1300 | int DimCommand::getTimestamp()
|
---|
1301 | {
|
---|
1302 | int ret;
|
---|
1303 |
|
---|
1304 | if(secs == 0)
|
---|
1305 | ret = dis_get_timestamp(itsId, &secs, &millisecs);
|
---|
1306 | return(secs);
|
---|
1307 | }
|
---|
1308 |
|
---|
1309 | int DimCommand::getTimestampMillisecs()
|
---|
1310 | {
|
---|
1311 | return(millisecs);
|
---|
1312 | }
|
---|
1313 |
|
---|
1314 | void DimCommand::commandHandler()
|
---|
1315 | {
|
---|
1316 | CmndInfo *cmndptr;
|
---|
1317 | int tsecs, tmillisecs;
|
---|
1318 |
|
---|
1319 | tsecs = getTimestamp();
|
---|
1320 | tmillisecs = getTimestampMillisecs();
|
---|
1321 | cmndptr = new CmndInfo(getData(), getSize(), tsecs, tmillisecs);
|
---|
1322 | itsCmndList.add(cmndptr);
|
---|
1323 | }
|
---|
1324 |
|
---|
1325 | char *DimCommand::getName()
|
---|
1326 | {
|
---|
1327 | return itsName;
|
---|
1328 | }
|
---|
1329 |
|
---|
1330 | DimCommand::~DimCommand()
|
---|
1331 | {
|
---|
1332 | delete[] itsName;
|
---|
1333 | delete[] itsFormat;
|
---|
1334 | // if(itsTagId)
|
---|
1335 | // id_free(itsTagId, SRC_DIS);
|
---|
1336 | dis_remove_service( itsId );
|
---|
1337 | }
|
---|
1338 |
|
---|
1339 | DimRpc::DimRpc()
|
---|
1340 | {
|
---|
1341 | }
|
---|
1342 |
|
---|
1343 | DimRpc::DimRpc(const char *name, const char *formatin, const char *formatout)
|
---|
1344 | {
|
---|
1345 | declareIt( (char *)name, (char *)formatin, (char *)formatout, 0);
|
---|
1346 | }
|
---|
1347 |
|
---|
1348 | DimRpc::DimRpc(DimServerDns *dns, const char *name, const char *formatin, const char *formatout)
|
---|
1349 | {
|
---|
1350 | declareIt( (char *)name, (char *)formatin, (char *)formatout, dns);
|
---|
1351 | }
|
---|
1352 |
|
---|
1353 | DimRpc::~DimRpc()
|
---|
1354 | {
|
---|
1355 | delete[] itsName;
|
---|
1356 | delete[] itsNameIn;
|
---|
1357 | delete[] itsNameOut;
|
---|
1358 | // if(itsTagId)
|
---|
1359 | // id_free(itsTagId, SRC_DIS);
|
---|
1360 | dis_remove_service( itsIdIn );
|
---|
1361 | dis_remove_service( itsIdOut );
|
---|
1362 | }
|
---|
1363 |
|
---|
1364 | void *DimRpc::getData()
|
---|
1365 | {
|
---|
1366 | return itsDataIn;
|
---|
1367 | }
|
---|
1368 |
|
---|
1369 | int DimRpc::getInt()
|
---|
1370 | {
|
---|
1371 | return *(int *)itsDataIn;
|
---|
1372 | }
|
---|
1373 |
|
---|
1374 | float DimRpc::getFloat()
|
---|
1375 | {
|
---|
1376 | return *(float *)itsDataIn;
|
---|
1377 | }
|
---|
1378 |
|
---|
1379 | double DimRpc::getDouble()
|
---|
1380 | {
|
---|
1381 | return *(double *)itsDataIn;
|
---|
1382 | }
|
---|
1383 |
|
---|
1384 | longlong DimRpc::getLonglong()
|
---|
1385 | {
|
---|
1386 | return *(longlong *)itsDataIn;
|
---|
1387 | }
|
---|
1388 |
|
---|
1389 | short DimRpc::getShort()
|
---|
1390 | {
|
---|
1391 | return *(short *)itsDataIn;
|
---|
1392 | }
|
---|
1393 |
|
---|
1394 | char *DimRpc::getString()
|
---|
1395 | {
|
---|
1396 | return (char *)itsDataIn;
|
---|
1397 | }
|
---|
1398 |
|
---|
1399 | int DimRpc::getSize()
|
---|
1400 | {
|
---|
1401 | return itsSizeIn;
|
---|
1402 | }
|
---|
1403 |
|
---|
1404 | void DimRpc::setData(void *data, int size)
|
---|
1405 | {
|
---|
1406 | storeIt(data,size);
|
---|
1407 | }
|
---|
1408 |
|
---|
1409 | void DimRpc::setData(int &data)
|
---|
1410 | {
|
---|
1411 | storeIt(&data,sizeof(int));
|
---|
1412 | }
|
---|
1413 |
|
---|
1414 | void DimRpc::setData(float &data)
|
---|
1415 | {
|
---|
1416 | storeIt(&data,sizeof(float));
|
---|
1417 | }
|
---|
1418 |
|
---|
1419 | void DimRpc::setData(double &data)
|
---|
1420 | {
|
---|
1421 | storeIt(&data,sizeof(double));
|
---|
1422 | }
|
---|
1423 |
|
---|
1424 | void DimRpc::setData(longlong &data)
|
---|
1425 | {
|
---|
1426 | storeIt(&data,sizeof(longlong));
|
---|
1427 | }
|
---|
1428 |
|
---|
1429 | void DimRpc::setData(short &data)
|
---|
1430 | {
|
---|
1431 | storeIt(&data,sizeof(short));
|
---|
1432 | }
|
---|
1433 |
|
---|
1434 | void DimRpc::setData(char *data)
|
---|
1435 | {
|
---|
1436 | storeIt(data,strlen(data)+1);
|
---|
1437 | }
|
---|
1438 |
|
---|
1439 | char *DimRpc::getName()
|
---|
1440 | {
|
---|
1441 | return itsName;
|
---|
1442 | }
|
---|