source: trunk/FACT++/dim/src/discpp.cxx@ 14621

Last change on this file since 14621 was 14575, checked in by tbretz, 12 years ago
Updated to v20r01.
File size: 26.7 KB
Line 
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
9DimClientExitHandler *DimServer::itsClientExit = 0;
10DimExitHandler *DimServer::itsExit = 0;
11DimErrorHandler *DimServer::itsSrvError = 0;
12char *DimServer::itsName = 0;
13char *DimServer::clientName = 0;
14char *DimServer::dimDnsNode = 0;
15int DimServer::autoStart = 1;
16//int DimServer::itsNServices = 0;
17
18extern "C" {
19static 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
47void 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, (dim_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, (dim_long)this);
71// itsDns->addServiceId(itsId);
72 DimServer::start(itsDns);
73 }
74}
75
76void 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
94extern "C" {
95static 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
123void 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 (dim_long)this);
142 DimServer::start();
143 }
144 else
145 {
146 itsId = dis_add_cmnd_dns( itsDns->getDnsId(), name, format, command_routine,
147// itsTagId);
148 (dim_long)this);
149// itsDns->addServiceId(itsId);
150 DimServer::start(itsDns);
151 }
152}
153
154extern "C" {
155/*
156static void timeout_rout(DimRpc *t)
157{
158 sleep(t->itsTimeout);
159 t->itsKilled = 1;
160}
161*/
162static 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
213extern "C" {
214static 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
228void 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, (dim_long)this);
251 itsIdOut = dis_add_service( itsNameOut, formatout, 0,0,
252// rpcout_routine, itsTagId);
253 rpcout_routine, (dim_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, (dim_long)this);
261 itsIdOut = dis_add_service_dns( itsDns->getDnsId(), itsNameOut, formatout, 0,0,
262// rpcout_routine, itsTagId);
263 rpcout_routine, (dim_long)this);
264// itsDns->addServiceId(itsIdIn);
265// itsDns->addServiceId(itsIdOut);
266 DimServer::start(itsDns);
267 }
268}
269
270void 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
288extern "C" {
289static void client_exit_user_routine(int*);
290static void exit_user_routine(int*);
291static void srv_error_user_routine(int, int, char*);
292}
293
294DimServerDns::DimServerDns(const char *node)
295{
296 init(node, 0);
297}
298
299DimServerDns::DimServerDns(const char *node, int port)
300{
301 init(node, port);
302}
303
304DimServerDns::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
312void 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
329void 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
348int *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
359DimServerDns::~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
371dim_long DimServerDns::getDnsId()
372{
373 return itsDnsId;
374}
375
376void DimServerDns::setName(const char *name)
377{
378 if(!itsName)
379 {
380 itsName = new char[strlen(name)+1];
381 strcpy(itsName,name);
382 }
383}
384
385void DimServerDns::clearName()
386{
387 if(itsName)
388 {
389 delete[] itsName;
390 itsName = 0;
391 }
392}
393
394char *DimServerDns::getName()
395{
396 return itsName;
397}
398
399void DimServerDns::autoStartOn()
400{
401 autoStart = 1;
402}
403
404void DimServerDns::autoStartOff()
405{
406 autoStart = 0;
407}
408
409int DimServerDns::isAutoStart()
410{
411 return autoStart;
412}
413
414DimServer::DimServer()
415{
416 itsClientExit = this;
417 itsExit = this;
418 itsSrvError = this;
419// itsNServices = 0;
420}
421
422DimServer::~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
435void 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
445void DimServer::start(DimServerDns *dns, const char *name)
446{
447 dim_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/*
456void DimServer::threadHandler()
457{
458 int oldNServices;
459
460 while(1)
461 {
462 oldNServices = itsNServices;
463 usleep(100000);
464 if(oldNServices == itsNServices)
465 break;
466 }
467cout << "Starting " << itsNServices << endl;
468 {
469 DISABLE_AST
470 dis_start_serving(itsName);
471 itsNServices = 0;
472 ENABLE_AST
473 }
474
475}
476*/
477void DimServer::start()
478{
479// itsNServices++;
480 if((itsName) && (autoStart))
481 {
482// DimThread::start();
483 dis_start_serving(itsName);
484 }
485}
486
487void DimServer::start(DimServerDns *dns)
488{
489 dim_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
507void DimServer::stop()
508{
509 dis_stop_serving();
510 if(itsName)
511 {
512 delete[] itsName;
513 itsName = 0;
514 }
515}
516
517void DimServer::stop(DimServerDns *dns)
518{
519 dis_stop_serving_dns(dns->getDnsId());
520 dns->clearName();
521}
522
523void DimServer::autoStartOn()
524{
525 autoStart = 1;
526}
527
528void DimServer::autoStartOff()
529{
530 autoStart = 0;
531}
532
533int DimServer::getClientId()
534{
535 if(!clientName)
536 clientName = new char[128];
537 clientName[0] = '\0';
538 return dis_get_client(clientName);
539}
540
541char *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/*
550char *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
558char *DimServer::getClientServices(int clientId)
559{
560 return dis_get_client_services(clientId);
561}
562*/
563char **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
602void DimServer::setClientExitHandler(int clientId)
603{
604 dis_set_client_exit_handler(clientId, 1);
605}
606
607void DimServer::clearClientExitHandler(int clientId)
608{
609 dis_set_client_exit_handler(clientId, 0);
610}
611
612void DimServer::addClientExitHandler(DimClientExitHandler *handler)
613{
614 if(handler == 0)
615 {
616 dis_add_client_exit_handler(0);
617 DimServer::itsClientExit = 0;
618 }
619 else
620 {
621 DimServer::itsClientExit = handler;
622 dis_add_client_exit_handler(client_exit_user_routine);
623 }
624}
625
626void DimServer::addClientExitHandler()
627{
628 DimServer::itsClientExit = this;
629 dis_add_client_exit_handler(client_exit_user_routine);
630}
631
632void DimServer::addExitHandler(DimExitHandler *handler)
633{
634 if(handler == 0)
635 {
636 dis_add_exit_handler(0);
637 DimServer::itsExit = 0;
638 }
639 else
640 {
641 DimServer::itsExit = handler;
642 dis_add_exit_handler(exit_user_routine);
643 }
644}
645
646void DimServer::addErrorHandler(DimErrorHandler *handler)
647{
648 if(handler == 0)
649 {
650 dis_add_error_handler(0);
651 DimServer::itsSrvError = 0;
652 }
653 else
654 {
655 DimServer::itsSrvError = handler;
656 dis_add_error_handler(srv_error_user_routine);
657 }
658}
659
660int DimServer::setDnsNode(const char *node)
661{
662 return dis_set_dns_node((char *)node);
663}
664
665int DimServer::setDnsNode(const char *node, int port)
666{
667 dis_set_dns_port(port);
668 return dis_set_dns_node((char *)node);
669}
670
671dim_long DimServer::addDns(const char *node, int port)
672{
673 return dis_add_dns((char *)node, port);
674}
675char *DimServer::getDnsNode()
676{
677 if(!dimDnsNode)
678 dimDnsNode = new char[256];
679 if(dis_get_dns_node(dimDnsNode))
680 return dimDnsNode;
681 else
682 return 0;
683}
684
685int DimServer::getDnsPort()
686{
687 return dis_get_dns_port();
688}
689
690void DimServer::setWriteTimeout(int secs)
691{
692 dim_set_write_timeout(secs);
693}
694
695int DimServer::getWriteTimeout()
696{
697 return dim_get_write_timeout();
698}
699
700void DimServer::addExitHandler()
701{
702 DimServer::itsExit = this;
703 dis_add_exit_handler(exit_user_routine);
704}
705
706void DimServer::addErrorHandler()
707{
708 DimServer::itsSrvError = this;
709 dis_add_error_handler(srv_error_user_routine);
710}
711
712int DimServer::inCallback()
713{
714 if(DimCore::inCallback)
715 return 1;
716 return 0;
717}
718
719extern "C" {
720static void client_exit_user_routine(int *idp)
721{
722 int id = *idp;
723
724 id++;
725 DimCore::inCallback = 2;
726 DimServer::itsClientExit->clientExitHandler();
727 DimCore::inCallback = 0;
728}
729
730static void exit_user_routine(int *idp)
731{
732// int id = *idp;
733
734// id++;
735 DimCore::inCallback = 2;
736 DimServer::itsExit->exitHandler(*idp);
737 DimCore::inCallback = 0;
738}
739
740static void srv_error_user_routine(int severity, int code, char *msg)
741{
742
743 DimCore::inCallback = 2;
744 if(DimServer::itsSrvError != 0)
745 DimServer::itsSrvError->errorHandler(severity, code, msg);
746 DimCore::inCallback = 0;
747}
748
749}
750
751
752DimService::DimService()
753{
754// itsTagId = 0;
755}
756
757DimService::DimService(const char *name, int &value)
758{
759 itsData = &value;
760 itsSize = sizeof(int);
761 itsType = DisINT;
762 declareIt((char *)name, (char *)"L", 0, 0);
763}
764
765DimService::DimService(const char *name, float &value)
766{
767 itsData = &value;
768 itsSize = sizeof(float);
769 itsType = DisFLOAT;
770 declareIt((char *)name, (char *)"F", 0, 0);
771}
772
773DimService::DimService(const char *name, double &value)
774{
775 itsData = &value;
776 itsSize = sizeof(double);
777 itsType = DisDOUBLE;
778 declareIt((char *)name, (char *)"D", 0, 0);
779}
780
781DimService::DimService(const char *name, longlong &value)
782{
783 itsData = &value;
784 itsSize = sizeof(longlong);
785 itsType = DisXLONG;
786 declareIt((char *)name, (char *)"X", 0, 0);
787}
788
789DimService::DimService(const char *name, short &value)
790{
791 itsData = &value;
792 itsSize = sizeof(short);
793 itsType = DisSHORT;
794 declareIt((char *)name, (char *)"S", 0, 0);
795}
796
797DimService::DimService(const char *name, char *string)
798{
799 itsData = string;
800 itsSize = strlen(string)+1;
801 itsType = DisSTRING;
802 declareIt((char *)name, (char *)"C", 0, 0);
803}
804
805DimService::DimService(const char *name, char *format, void *structure, int size)
806{
807 itsData = structure;
808 itsSize = size;
809 itsType = DisPOINTER;
810 declareIt((char *)name, (char *)format, 0, 0);
811}
812
813DimService::DimService(const char *name, char *format, DimServiceHandler *handler)
814{
815 itsData = 0;
816 itsSize = 0;
817 itsType = DisPOINTER;
818 declareIt((char *)name, (char *)format, handler, 0);
819}
820
821DimService::DimService(const char *name, const char *format, void *structure, int size)
822{
823 itsData = structure;
824 itsSize = size;
825 itsType = DisPOINTER;
826 declareIt((char *)name, (char *)format, 0, 0);
827}
828
829DimService::DimService(const char *name, const char *format, DimServiceHandler *handler)
830{
831 itsData = 0;
832 itsSize = 0;
833 itsType = DisPOINTER;
834 declareIt((char *)name, (char *)format, handler, 0);
835}
836
837// with Dns
838
839DimService::DimService(DimServerDns *dns, const char *name, int &value)
840{
841 itsData = &value;
842 itsSize = sizeof(int);
843 itsType = DisINT;
844 declareIt((char *)name, (char *)"L", 0, dns);
845}
846
847DimService::DimService(DimServerDns *dns, const char *name, float &value)
848{
849 itsData = &value;
850 itsSize = sizeof(float);
851 itsType = DisFLOAT;
852 declareIt((char *)name, (char *)"F", 0, dns);
853}
854
855DimService::DimService(DimServerDns *dns, const char *name, double &value)
856{
857 itsData = &value;
858 itsSize = sizeof(double);
859 itsType = DisDOUBLE;
860 declareIt((char *)name, (char *)"D", 0, dns);
861}
862
863DimService::DimService(DimServerDns *dns, const char *name, longlong &value)
864{
865 itsData = &value;
866 itsSize = sizeof(longlong);
867 itsType = DisXLONG;
868 declareIt((char *)name, (char *)"X", 0, dns);
869}
870
871DimService::DimService(DimServerDns *dns, const char *name, short &value)
872{
873 itsData = &value;
874 itsSize = sizeof(short);
875 itsType = DisSHORT;
876 declareIt((char *)name, (char *)"S", 0, dns);
877}
878
879DimService::DimService(DimServerDns *dns, const char *name, char *string)
880{
881 itsData = string;
882 itsSize = strlen(string)+1;
883 itsType = DisSTRING;
884 declareIt((char *)name, (char *)"C", 0, dns);
885}
886
887DimService::DimService(DimServerDns *dns, const char *name, char *format, void *structure, int size)
888{
889 itsData = structure;
890 itsSize = size;
891 itsType = DisPOINTER;
892 declareIt((char *)name, (char *)format, 0, dns);
893}
894
895DimService::DimService(DimServerDns *dns, const char *name, char *format, DimServiceHandler *handler)
896{
897 itsData = 0;
898 itsSize = 0;
899 itsType = DisPOINTER;
900 declareIt((char *)name, (char *)format, handler, dns);
901}
902
903
904DimService::DimService(DimServerDns *dns, const char *name, const char *format, void *structure, int size)
905{
906 itsData = structure;
907 itsSize = size;
908 itsType = DisPOINTER;
909 declareIt((char *)name, (char *)format, 0, dns);
910}
911
912DimService::DimService(DimServerDns *dns, const char *name, const char *format, DimServiceHandler *handler)
913{
914 itsData = 0;
915 itsSize = 0;
916 itsType = DisPOINTER;
917 declareIt((char *)name, (char *)format, handler, dns);
918}
919
920
921DimService::~DimService()
922{
923 delete[] itsName;
924 if(itsDataSize)
925 delete[] (char *)itsData;
926// if(itsTagId)
927// id_free(itsTagId, SRC_DIS);
928 dis_remove_service( itsId );
929}
930
931int DimService::updateService()
932{
933 return dis_update_service( itsId );
934}
935
936int DimService::updateService( int &value )
937{
938 if( itsType == DisINT)
939 {
940 itsData = &value;
941 return dis_update_service( itsId );
942 }
943 return -1;
944}
945
946int DimService::updateService( float &value )
947{
948 if( itsType == DisFLOAT) {
949 itsData = &value;
950 return dis_update_service( itsId );
951 }
952 return -1;
953}
954
955int DimService::updateService( double &value )
956{
957 if( itsType == DisDOUBLE) {
958 itsData = &value;
959 return dis_update_service( itsId );
960 }
961 return -1;
962}
963
964int DimService::updateService( longlong &value )
965{
966 if( itsType == DisXLONG)
967 {
968 itsData = &value;
969 return dis_update_service( itsId );
970 }
971 return -1;
972}
973
974int DimService::updateService( short &value )
975{
976 if( itsType == DisSHORT)
977 {
978 itsData = &value;
979 return dis_update_service( itsId );
980 }
981 return -1;
982}
983
984int DimService::updateService( char *string )
985{
986 if( itsType == DisSTRING)
987 {
988 itsData = string;
989 itsSize = strlen(string)+1;
990 return dis_update_service( itsId );
991 }
992 return -1;
993}
994
995int DimService::updateService( void *structure, int size )
996{
997 if( itsType == DisPOINTER)
998 {
999 itsData = structure;
1000 itsSize = size;
1001 return dis_update_service( itsId );
1002 }
1003 return -1;
1004}
1005
1006int DimService::selectiveUpdateService(int *cids)
1007{
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
1018int DimService::selectiveUpdateService( int &value, int *cids)
1019{
1020 if( itsType == DisINT)
1021 {
1022 itsData = &value;
1023 if( cids == 0)
1024 {
1025 int ids[2];
1026 ids[0] = DimServer::getClientId();
1027 ids[1] = 0;
1028 return dis_selective_update_service( itsId, ids );
1029 }
1030 return dis_selective_update_service( itsId, cids );
1031 }
1032 return -1;
1033}
1034
1035int DimService::selectiveUpdateService( float &value, int *cids )
1036{
1037 if( itsType == DisFLOAT)
1038 {
1039 itsData = &value;
1040 if( cids == 0)
1041 {
1042 int ids[2];
1043 ids[0] = DimServer::getClientId();
1044 ids[1] = 0;
1045 return dis_selective_update_service( itsId, ids );
1046 }
1047 return dis_selective_update_service( itsId, cids );
1048 }
1049 return -1;
1050}
1051
1052int DimService::selectiveUpdateService( double &value, int *cids )
1053{
1054 if( itsType == DisDOUBLE)
1055 {
1056 itsData = &value;
1057 if( cids == 0)
1058 {
1059 int ids[2];
1060 ids[0] = DimServer::getClientId();
1061 ids[1] = 0;
1062 return dis_selective_update_service( itsId, ids );
1063 }
1064 return dis_selective_update_service( itsId, cids );
1065 }
1066 return -1;
1067}
1068
1069int DimService::selectiveUpdateService( longlong &value, int *cids )
1070{
1071 if( itsType == DisXLONG)
1072 {
1073 itsData = &value;
1074 if( cids == 0)
1075 {
1076 int ids[2];
1077 ids[0] = DimServer::getClientId();
1078 ids[1] = 0;
1079 return dis_selective_update_service( itsId, ids );
1080 }
1081 return dis_selective_update_service( itsId, cids );
1082 }
1083 return -1;
1084}
1085
1086int DimService::selectiveUpdateService( short &value, int *cids )
1087{
1088 if( itsType == DisSHORT)
1089 {
1090 itsData = &value;
1091 if( cids == 0)
1092 {
1093 int ids[2];
1094 ids[0] = DimServer::getClientId();
1095 ids[1] = 0;
1096 return dis_selective_update_service( itsId, ids );
1097 }
1098 return dis_selective_update_service( itsId, cids );
1099 }
1100 return -1;
1101}
1102
1103int DimService::selectiveUpdateService( char *string, int *cids )
1104{
1105 if( itsType == DisSTRING)
1106 {
1107 itsData = string;
1108 itsSize = strlen(string)+1;
1109 if( cids == 0)
1110 {
1111 int ids[2];
1112 ids[0] = DimServer::getClientId();
1113 ids[1] = 0;
1114 return dis_selective_update_service( itsId, ids );
1115 }
1116 return dis_selective_update_service( itsId, cids );
1117 }
1118 return -1;
1119}
1120
1121int DimService::selectiveUpdateService( void *structure, int size, int *cids )
1122{
1123 if( itsType == DisPOINTER)
1124 {
1125 itsData = structure;
1126 itsSize = size;
1127 if( cids == 0)
1128 {
1129 int ids[2];
1130 ids[0] = DimServer::getClientId();
1131 ids[1] = 0;
1132 return dis_selective_update_service( itsId, ids );
1133 }
1134 return dis_selective_update_service( itsId, cids );
1135 }
1136 return -1;
1137}
1138
1139void DimService::setQuality(int quality)
1140{
1141 dis_set_quality( itsId, quality );
1142}
1143
1144void DimService::setTimestamp(int secs, int millisecs)
1145{
1146 dis_set_timestamp( itsId, secs, millisecs );
1147}
1148
1149void DimService::setData(void *data, int size)
1150{
1151 storeIt(data, size);
1152}
1153
1154void DimService::setData(int &data)
1155{
1156 storeIt(&data, sizeof(int));
1157}
1158
1159void DimService::setData(float &data)
1160{
1161 storeIt(&data, sizeof(float));
1162}
1163
1164void DimService::setData(double &data)
1165{
1166 storeIt(&data, sizeof(double));
1167}
1168
1169void DimService::setData(longlong &data)
1170{
1171 storeIt(&data, sizeof(longlong));
1172}
1173
1174void DimService::setData(short &data)
1175{
1176 storeIt(&data, sizeof(short));
1177}
1178
1179void DimService::setData(char *data)
1180{
1181 storeIt(data, strlen(data)+1);
1182}
1183
1184char *DimService::getName()
1185{
1186 return itsName;
1187}
1188
1189int DimService::getTimeout(int clientId)
1190{
1191 return dis_get_timeout(itsId, clientId);
1192}
1193
1194int DimService::getNClients()
1195{
1196 return dis_get_n_clients( itsId );
1197}
1198
1199
1200CmndInfo::CmndInfo(void *data, int datasize, int tsecs, int tmillisecs)
1201{
1202 itsData = new char[datasize];
1203 itsDataSize = datasize;
1204 secs = tsecs;
1205 millisecs = tmillisecs;
1206 memcpy(itsData, data, datasize);
1207}
1208
1209CmndInfo::~CmndInfo()
1210{
1211 delete[] (char *)itsData;
1212}
1213
1214
1215DimCommand::DimCommand(const char *name, char *format)
1216{
1217 declareIt( (char *)name, (char *)format, 0, 0);
1218}
1219
1220DimCommand::DimCommand(const char *name, char *format, DimCommandHandler *handler)
1221{
1222 declareIt( (char *)name, (char *)format, handler, 0);
1223}
1224
1225DimCommand::DimCommand(DimServerDns *dns, const char *name, char *format)
1226{
1227 declareIt( (char *)name, (char *)format, 0, dns);
1228}
1229
1230DimCommand::DimCommand(DimServerDns *dns, const char *name, char *format, DimCommandHandler *handler)
1231{
1232 declareIt( (char *)name, (char *)format, handler, dns);
1233}
1234
1235
1236DimCommand::DimCommand(const char *name, const char *format)
1237{
1238 declareIt( (char *)name, (char *)format, 0, 0);
1239}
1240
1241DimCommand::DimCommand(const char *name, const char *format, DimCommandHandler *handler)
1242{
1243 declareIt( (char *)name, (char *)format, handler, 0);
1244}
1245
1246DimCommand::DimCommand(DimServerDns *dns, const char *name, const char *format)
1247{
1248 declareIt( (char *)name, (char *)format, 0, dns);
1249}
1250
1251DimCommand::DimCommand(DimServerDns *dns, const char *name, const char *format, DimCommandHandler *handler)
1252{
1253 declareIt( (char *)name, (char *)format, handler, dns);
1254}
1255
1256int DimCommand::getNext()
1257{
1258 CmndInfo *cmndptr;
1259 if(currCmnd)
1260 {
1261 delete currCmnd;
1262 currCmnd = 0;
1263 itsData = 0;
1264 itsSize = 0;
1265 }
1266 if ((cmndptr = (CmndInfo *)itsCmndList.removeHead()))
1267 {
1268 currCmnd = cmndptr;
1269 itsData = currCmnd->itsData;
1270 itsSize = currCmnd->itsDataSize;
1271 secs = currCmnd->secs;
1272 millisecs = currCmnd->millisecs;
1273 return(1);
1274 }
1275 return(0);
1276}
1277
1278int DimCommand::hasNext()
1279{
1280 if ((CmndInfo *)itsCmndList.getHead())
1281 {
1282 return(1);
1283 }
1284 return(0);
1285}
1286
1287void *DimCommand::getData()
1288{
1289 return itsData;
1290}
1291
1292int DimCommand::getInt()
1293{
1294 return *(int *)itsData;
1295}
1296
1297float DimCommand::getFloat()
1298{
1299 return *(float *)itsData;
1300}
1301
1302double DimCommand::getDouble()
1303{
1304 return *(double *)itsData;
1305}
1306
1307longlong DimCommand::getLonglong()
1308{
1309 return *(longlong *)itsData;
1310}
1311
1312short DimCommand::getShort()
1313{
1314 return *(short *)itsData;
1315}
1316
1317char *DimCommand::getString()
1318{
1319 return (char *)itsData;
1320}
1321
1322int DimCommand::getSize()
1323{
1324 return itsSize;
1325}
1326
1327char *DimCommand::getFormat()
1328{
1329 return itsFormat;
1330}
1331
1332int DimCommand::getTimestamp()
1333{
1334
1335 if(secs == 0)
1336 dis_get_timestamp(itsId, &secs, &millisecs);
1337 return(secs);
1338}
1339
1340int DimCommand::getTimestampMillisecs()
1341{
1342 return(millisecs);
1343}
1344
1345void DimCommand::commandHandler()
1346{
1347 CmndInfo *cmndptr;
1348 int tsecs, tmillisecs;
1349
1350 tsecs = getTimestamp();
1351 tmillisecs = getTimestampMillisecs();
1352 cmndptr = new CmndInfo(getData(), getSize(), tsecs, tmillisecs);
1353 itsCmndList.add(cmndptr);
1354}
1355
1356char *DimCommand::getName()
1357{
1358 return itsName;
1359}
1360
1361DimCommand::~DimCommand()
1362{
1363 delete[] itsName;
1364 delete[] itsFormat;
1365// if(itsTagId)
1366// id_free(itsTagId, SRC_DIS);
1367 dis_remove_service( itsId );
1368}
1369
1370DimRpc::DimRpc()
1371{
1372}
1373
1374DimRpc::DimRpc(const char *name, const char *formatin, const char *formatout)
1375{
1376 declareIt( (char *)name, (char *)formatin, (char *)formatout, 0);
1377}
1378
1379DimRpc::DimRpc(DimServerDns *dns, const char *name, const char *formatin, const char *formatout)
1380{
1381 declareIt( (char *)name, (char *)formatin, (char *)formatout, dns);
1382}
1383
1384DimRpc::~DimRpc()
1385{
1386 delete[] itsName;
1387 delete[] itsNameIn;
1388 delete[] itsNameOut;
1389// if(itsTagId)
1390// id_free(itsTagId, SRC_DIS);
1391 dis_remove_service( itsIdIn );
1392 dis_remove_service( itsIdOut );
1393}
1394
1395void *DimRpc::getData()
1396{
1397 return itsDataIn;
1398}
1399
1400int DimRpc::getInt()
1401{
1402 return *(int *)itsDataIn;
1403}
1404
1405float DimRpc::getFloat()
1406{
1407 return *(float *)itsDataIn;
1408}
1409
1410double DimRpc::getDouble()
1411{
1412 return *(double *)itsDataIn;
1413}
1414
1415longlong DimRpc::getLonglong()
1416{
1417 return *(longlong *)itsDataIn;
1418}
1419
1420short DimRpc::getShort()
1421{
1422 return *(short *)itsDataIn;
1423}
1424
1425char *DimRpc::getString()
1426{
1427 return (char *)itsDataIn;
1428}
1429
1430int DimRpc::getSize()
1431{
1432 return itsSizeIn;
1433}
1434
1435void DimRpc::setData(void *data, int size)
1436{
1437 storeIt(data,size);
1438}
1439
1440void DimRpc::setData(int &data)
1441{
1442 storeIt(&data,sizeof(int));
1443}
1444
1445void DimRpc::setData(float &data)
1446{
1447 storeIt(&data,sizeof(float));
1448}
1449
1450void DimRpc::setData(double &data)
1451{
1452 storeIt(&data,sizeof(double));
1453}
1454
1455void DimRpc::setData(longlong &data)
1456{
1457 storeIt(&data,sizeof(longlong));
1458}
1459
1460void DimRpc::setData(short &data)
1461{
1462 storeIt(&data,sizeof(short));
1463}
1464
1465void DimRpc::setData(char *data)
1466{
1467 storeIt(data,strlen(data)+1);
1468}
1469
1470char *DimRpc::getName()
1471{
1472 return itsName;
1473}
Note: See TracBrowser for help on using the repository browser.