source: trunk/FACT++/dim/src/diccpp.cxx@ 14618

Last change on this file since 14618 was 14580, checked in by tbretz, 12 years ago
Update to v20r02.
File size: 24.8 KB
Line 
1#define DIMLIB
2#include <dic.hxx>
3#include <stdio.h>
4
5char *DimClient::dimDnsNode = 0;
6DimErrorHandler *DimClient::itsCltError = 0;
7char *DimClient::serverName = 0;
8int DimClient::dicNoCopy = 0;
9
10extern "C" {
11static void user_routine(void *tagp, void *bufp, int *size)
12{
13// int *tag = (int *)tagp;
14 char *buf = (char *)bufp;
15// int id = *tag;
16 DimInfo *t;
17
18// t = (DimInfo *)id_get_ptr(id, SRC_DIC);
19 t = * (DimInfo **)tagp;
20 if(DimClient::getNoDataCopy() == 0)
21 {
22 if(*size > 0)
23 {
24 if(!t->itsDataSize)
25 {
26 t->itsData = new char[*size];
27 t->itsDataSize = *size;
28 }
29 else if(t->itsDataSize < *size)
30 {
31 delete[] (char *)(t->itsData);
32 t->itsData = new char[*size];
33 t->itsDataSize = *size;
34 }
35 memcpy(t->itsData, buf, *size);
36 }
37 else if (*size == 0)
38 {
39 if(t->itsDataSize)
40 {
41 delete[] (char *)(t->itsData);
42 t->itsDataSize = 0;
43 }
44 t->itsData = buf;
45 }
46 }
47 else
48 {
49 t->itsData = buf;
50 }
51 t->itsSize = *size;
52 if(t->itsHandler)
53 {
54 t->itsHandler->itsService = t;
55 DimCore::inCallback = 1;
56 t->itsHandler->infoHandler();
57 DimCore::inCallback = 0;
58 }
59 else
60 {
61 DimCore::inCallback = 1;
62 t->infoHandler();
63 DimCore::inCallback = 0;
64 }
65}
66}
67
68void DimInfo::infoHandler()
69{
70 char *data;
71 if(DimClient::getNoDataCopy() == 1)
72 {
73 data = (char *)itsData;
74 if(!itsDataSize)
75 {
76 itsData = new char[itsSize];
77 itsDataSize = itsSize;
78 }
79 else if(itsDataSize < itsSize)
80 {
81 delete[] (char *)(itsData);
82 itsData = new char[itsSize];
83 itsDataSize = itsSize;
84 }
85 memcpy(itsData, data, itsSize);
86 }
87}
88
89void DimInfo::doIt()
90{
91 dim_init();
92 DISABLE_AST
93
94// itsTagId = id_get((void *)this, SRC_DIC);
95 itsId = dic_info_service(itsName,itsType,itsTime, 0, 0,
96// user_routine, itsTagId,
97 user_routine, (dim_long)this,
98 itsNolinkBuf, itsNolinkSize);
99 ENABLE_AST
100}
101
102int DimInfo::getQuality()
103{
104 return dic_get_quality(itsId);
105}
106
107int DimInfo::getTimestamp()
108{
109
110 dic_get_timestamp(itsId, &secs, &millisecs);
111 return(secs);
112}
113
114int DimInfo::getTimestampMillisecs()
115{
116 return(millisecs);
117}
118
119
120char *DimInfo::getFormat()
121{
122 char *def;
123 int len = 0, new_len;
124
125 if(itsFormat)
126 {
127 len = strlen(itsFormat)+1;
128 if(len > 1)
129 return itsFormat;
130 }
131 def = dic_get_format(itsId);
132 new_len = strlen(def)+1;
133 if(new_len > len)
134 {
135 if(itsFormat)
136 delete[] itsFormat;
137 itsFormat = new char[strlen(def)+1];
138 }
139 strcpy(itsFormat, def);
140 return itsFormat;
141}
142
143void DimInfo::timerHandler()
144{
145// itsTagId = id_get((void *)this, SRC_DIC);
146 itsId = dic_info_service(itsName,itsType,itsTime, 0, 0,
147// user_routine, itsTagId,
148 user_routine, (dim_long)this,
149 itsNolinkBuf, itsNolinkSize);
150}
151
152void DimInfo::subscribe(char *name, int time, void *nolink, int nolinksize,
153 DimInfoHandler *handler)
154{
155 itsId = 0;
156 itsData = 0;
157 itsFormat = 0;
158 itsHandler = handler;
159 itsDataSize = 0;
160 itsSize = 0;
161 itsNolinkBuf = 0;
162 itsNolinkSize = 0;
163 itsName = 0;
164 if(!name)
165 {
166 return;
167 }
168 itsName = new char[strlen(name)+1];
169 strcpy(itsName,name);
170 itsNolinkBuf = nolink;
171 itsNolinkSize = nolinksize;
172 if(nolinksize > 0)
173 {
174 itsNolinkBuf = new char[nolinksize];
175 itsNolinkSize = nolinksize;
176 memcpy(itsNolinkBuf, nolink, nolinksize);
177 }
178 if(!time)
179 {
180 itsType = MONITORED;
181 itsTime = 0;
182 }
183 else if(time > 0)
184 {
185 itsType = MONITORED;
186 itsTime = time;
187 }
188 else
189 {
190 itsType = ONCE_ONLY;
191 itsTime = 30;
192 }
193 doIt();
194}
195
196
197DimInfo::~DimInfo()
198{
199// if(itsTagId)
200// id_free(itsTagId, SRC_DIC);
201 if(itsId)
202 dic_release_service(itsId);
203 if(itsNolinkSize)
204 delete[] (char *)itsNolinkBuf;
205 if(itsDataSize)
206 delete[] (char *)itsData;
207 if(itsName)
208 delete[] itsName;
209 if(itsFormat)
210 delete[] itsFormat;
211}
212
213void *DimInfo::getData()
214{
215// if(!this->itsSize)
216// return itsNolinkBuf;
217/*
218 if(DimClient::getNoDataCopy() == 1)
219 {
220 if(!DimCore::inCallback)
221 return (void *)0;
222 }
223*/
224 return this->itsData;
225}
226
227void DimStampedInfo::doIt()
228{
229 dim_init();
230 DISABLE_AST
231// itsTagId = id_get((void *)this, SRC_DIC);
232 itsId = dic_info_service_stamped(itsName,itsType,itsTime, 0, 0,
233// user_routine, itsTagId,
234 user_routine, (dim_long)this,
235 itsNolinkBuf, itsNolinkSize);
236 ENABLE_AST
237}
238
239void DimStampedInfo::subscribe(char *name, int time, void *nolink, int nolinksize,
240 DimInfoHandler *handler)
241{
242 itsId = 0;
243 itsData = 0;
244 itsFormat = 0;
245 itsHandler = handler;
246 itsDataSize = 0;
247 itsSize = 0;
248 itsNolinkBuf = 0;
249 itsNolinkSize = 0;
250 itsName = 0;
251 if(!name)
252 {
253 return;
254 }
255 itsName = new char[strlen(name)+1];
256 strcpy(itsName,name);
257 itsNolinkBuf = nolink;
258 itsNolinkSize = nolinksize;
259 if(nolinksize > 0)
260 {
261 itsNolinkBuf = new char[nolinksize];
262 itsNolinkSize = nolinksize;
263 memcpy(itsNolinkBuf, nolink, nolinksize);
264 }
265 if(!time)
266 {
267 itsType = MONITORED;
268 itsTime = 0;
269 }
270 else if(time > 0)
271 {
272 itsType = MONITORED;
273 itsTime = time;
274 }
275 else
276 {
277 itsType = ONCE_ONLY;
278 itsTime = 30;
279 }
280 doIt();
281}
282
283DimStampedInfo::~DimStampedInfo()
284{
285}
286
287void DimUpdatedInfo::doIt()
288{
289 dim_init();
290 DISABLE_AST
291// itsTagId = id_get((void *)this, SRC_DIC);
292 itsId = dic_info_service_stamped(itsName,itsType,itsTime, 0, 0,
293// user_routine, itsTagId,
294 user_routine, (dim_long)this,
295 itsNolinkBuf, itsNolinkSize);
296 ENABLE_AST
297}
298
299void DimUpdatedInfo::subscribe(char *name, int time, void *nolink, int nolinksize,
300 DimInfoHandler *handler)
301{
302 itsId = 0;
303 itsData = 0;
304 itsFormat = 0;
305 itsHandler = handler;
306 itsDataSize = 0;
307 itsSize = 0;
308 itsNolinkBuf = 0;
309 itsNolinkSize = 0;
310 itsName = 0;
311 if(!name)
312 {
313 return;
314 }
315 itsName = new char[strlen(name)+1];
316 strcpy(itsName,name);
317 itsNolinkBuf = nolink;
318 itsNolinkSize = nolinksize;
319 if(nolinksize > 0)
320 {
321 itsNolinkBuf = new char[nolinksize];
322 itsNolinkSize = nolinksize;
323 memcpy(itsNolinkBuf, nolink, nolinksize);
324 }
325 if(!time)
326 {
327 itsType = MONIT_ONLY;
328 itsTime = 0;
329 }
330 else if(time > 0)
331 {
332 itsType = UPDATE;
333 itsTime = time;
334 }
335 doIt();
336}
337
338DimUpdatedInfo::~DimUpdatedInfo()
339{
340}
341
342extern "C" {
343static void data_user_routine(void *tagp, void *bufp, int *size)
344{
345// int *tag = (int *)tagp;
346 char *buf = (char *)bufp;
347// int id = *tag;
348 DimCurrentInfo *t;
349
350// t = (DimCurrentInfo *)id_get_ptr(id, SRC_DIC);
351 t = * (DimCurrentInfo **)tagp;
352 if(*size > 0)
353 {
354 if(!t->itsDataSize)
355 {
356 t->itsData = new char[*size];
357 t->itsDataSize = *size;
358 }
359 else if(t->itsDataSize < *size)
360 {
361 delete[] (char *)(t->itsData);
362 t->itsData = new char[*size];
363 t->itsDataSize = *size;
364 }
365 memcpy(t->itsData, buf, *size);
366 }
367 else if (*size == 0)
368 {
369 if(t->itsDataSize)
370 {
371 delete[] (char *)(t->itsData);
372 t->itsDataSize = 0;
373 }
374 t->itsData = buf;
375 }
376 t->itsSize = *size;
377 t->wakeUp = 1;
378#ifdef __VMS
379 sys$wake(0,0);
380#endif
381#ifdef WIN32
382 wake_up();
383#endif
384}
385}
386
387void DimCurrentInfo::subscribe(char *name, int time, void *nolink, int nolinksize)
388{
389
390 int timeout;
391
392// itsTagId = 0;
393// itsId = 0;
394 itsData = 0;
395// itsFormat = 0;
396// itsHandler = handler;
397 itsDataSize = 0;
398 itsSize = 0;
399 itsNolinkBuf = 0;
400 itsNolinkSize = 0;
401 itsName = 0;
402 if(!name)
403 {
404 return;
405 }
406 itsName = new char[strlen(name)+1];
407 strcpy(itsName,name);
408 itsNolinkBuf = nolink;
409 itsNolinkSize = nolinksize;
410 if(nolinksize > 0)
411 {
412 itsNolinkBuf = new char[nolinksize];
413 itsNolinkSize = nolinksize;
414 memcpy(itsNolinkBuf, nolink, nolinksize);
415 }
416 if(!time)
417 timeout = 10;
418 else
419 timeout = time;
420 wakeUp = 0;
421// itsTagId = id_get((void *)this, SRC_DIC);
422 dic_info_service(itsName,ONCE_ONLY,timeout, 0, 0,
423// data_user_routine, itsTagId,
424 data_user_routine, (dim_long)this,
425 itsNolinkBuf, itsNolinkSize);
426}
427
428DimCurrentInfo::~DimCurrentInfo()
429{
430// if(itsId)
431// dic_release_service(itsId);
432 if(itsNolinkSize)
433 delete[] (char *)itsNolinkBuf;
434 if(itsDataSize)
435 delete[] (char *)itsData;
436 if(itsName)
437 delete[] itsName;
438// if(itsFormat)
439// delete[] itsFormat;
440/*
441 delete[] (char *)itsNolinkBuf;
442
443// if(itsTagId)
444// id_free(itsTagId, SRC_DIC);
445 if(itsDataSize)
446 delete[] (char *)itsData;
447 delete[] itsName;
448*/
449}
450
451void *DimCurrentInfo::getData()
452{
453 while(!wakeUp)
454 {
455#ifdef __VMS
456 sys$hiber();
457#else
458 dim_wait();
459#endif
460 }
461 return this->itsData;
462}
463
464extern "C" {
465static void cmnd_done(void *tagp, int *result)
466{
467// int *tag = (int *)tagp;
468// int id = *tag;
469 DimCmnd *t;
470
471// t = (DimCmnd *)id_get_ptr(id, SRC_DIC);
472 t = *(DimCmnd **)tagp;
473 t->result = *result;
474 t->wakeUp = 1;
475#ifdef __VMS
476 sys$wake(0,0);
477#endif
478#ifdef WIN32
479 wake_up();
480#endif
481}
482}
483
484int DimCmnd::send(char *name, void *data, int datasize)
485{
486// int id;
487 if(DimCore::inCallback)
488 {
489 dic_cmnd_service(name, data, datasize);
490 return(1);
491 }
492 else
493 {
494 wakeUp = 0;
495// id = id_get((void *)this, SRC_DIC);
496 dic_cmnd_callback(name, data, datasize,
497// cmnd_done, id);
498 cmnd_done, (dim_long)this);
499 while(!wakeUp)
500 {
501#ifdef __VMS
502 sys$hiber();
503#else
504 dim_wait();
505#endif
506 }
507// id_free(id, SRC_DIC);
508 return(result);
509 }
510}
511
512void DimCmnd::sendNB(char *name, void *data, int datasize)
513{
514 dic_cmnd_service(name, data, datasize);
515}
516
517extern "C" {
518static void rpc_user_routine(void *tagp, void *bufp, int *sizep)
519{
520// int *tag = (int *)tagp;
521 char *buf = (char *)bufp;
522 int size = *sizep;
523// int id = *tag;
524 DimRpcInfo *t;
525 int quality;
526
527// t = (DimRpcInfo *)id_get_ptr(id, SRC_DIC);
528 t = *(DimRpcInfo **)tagp;
529 quality = dic_get_quality(0);
530 if(quality == -1)
531 {
532 buf = (char *)t->itsNolinkBuf;
533 size = t->itsNolinkSize;
534 }
535 if(DimClient::getNoDataCopy() == 0)
536 {
537 if(size > 0)
538 {
539 if(!t->itsDataSize)
540 {
541 t->itsData = new char[size];
542 t->itsDataSize = size;
543 }
544 else if(t->itsDataSize < size)
545 {
546 delete[] (char *)(t->itsData);
547 t->itsData = new char[size];
548 t->itsDataSize = size;
549 }
550 }
551 else if (size == 0)
552 {
553 if(t->itsDataSize)
554 {
555 delete[] (char *)(t->itsData);
556 t->itsDataSize = 0;
557 }
558 }
559 }
560 if(!t->itsConnected)
561 {
562 t->itsConnected = 1;
563 }
564 if(t->itsWaiting)
565 {
566 t->stop();
567//dim_print_date_time();
568//printf("DIM RPC: Stopped Timer, Data Received for %s\n", t->getName());
569 if(DimClient::getNoDataCopy() == 0)
570 {
571 if(size > 0)
572 memcpy(t->itsData, buf, size);
573 else
574 t->itsData = buf;
575 }
576 else
577 t->itsData = buf;
578 t->itsSize = size;
579 t->wakeUp = 1;
580 if(t->itsInit)
581 {
582 t->itsWaiting = 1;
583 t->itsHandler->rpcInfoHandler();
584 }
585 if(t->itsWaiting != 2)
586 t->itsWaiting = 0;
587 }
588#ifdef __VMS
589 sys$wake(0,0);
590#endif
591#ifdef WIN32
592 wake_up();
593#endif
594}
595}
596
597void DimRpcInfo::timerHandler()
598{
599 char *buf;
600 int size;
601
602 buf = (char *)itsNolinkBuf;
603 size = itsNolinkSize;
604
605 if(DimClient::getNoDataCopy() == 0)
606 {
607 if(size > 0)
608 {
609 if(!itsDataSize)
610 {
611 itsData = new char[size];
612 itsDataSize = size;
613 }
614 else if(itsDataSize < size)
615 {
616 delete[] (char *)(itsData);
617 itsData = new char[size];
618 itsDataSize = size;
619 }
620 }
621 else if (size == 0)
622 {
623 if(itsDataSize)
624 {
625 delete[] (char *)(itsData);
626 itsDataSize = 0;
627 }
628 }
629 }
630 if(itsWaiting)
631 {
632 if(DimClient::getNoDataCopy() == 0)
633 {
634 if(size > 0)
635 memcpy(itsData, buf, size);
636 else
637 itsData = buf;
638 }
639 else
640 itsData = buf;
641 itsSize = size;
642//dim_print_date_time();
643//printf("DIM RPC: Timer fired, No Data Received for %s\n", itsName);
644 wakeUp = 1;
645 if(itsInit)
646 {
647 itsWaiting = 1;
648 itsHandler->rpcInfoHandler();
649 }
650 if(itsWaiting != 2)
651 itsWaiting = 0;
652 }
653#ifdef __VMS
654 sys$wake(0,0);
655#endif
656#ifdef WIN32
657 wake_up();
658#endif
659}
660
661void DimRpcInfo::rpcInfoHandler()
662{
663 char *data;
664 if(DimClient::getNoDataCopy() == 1)
665 {
666 data = (char *)itsData;
667 if(!itsDataSize)
668 {
669 itsData = new char[itsSize];
670 itsDataSize = itsSize;
671 }
672 else if(itsDataSize < itsSize)
673 {
674 delete[] (char *)(itsData);
675 itsData = new char[itsSize];
676 itsDataSize = itsSize;
677 }
678 memcpy(itsData, data, itsSize);
679 }
680}
681
682void DimRpcInfo::subscribe(char *name, void *data, int size,
683 void *nolink, int nolinksize, int timeout)
684{
685
686 itsId = 0;
687// itsTagId = 0;
688 itsInit = 0;
689 itsWaiting = 0;
690 itsName = new char[strlen(name)+1];
691 strcpy(itsName,name);
692 itsHandler = this;
693 itsDataSize = 0;
694 itsData = 0;
695 itsDataOutSize = 0;
696 itsDataOut = 0;
697 itsNolinkBuf = nolink;
698 itsNolinkSize = nolinksize;
699 if(nolinksize > 0)
700 {
701 itsNolinkBuf = new char[nolinksize];
702 itsNolinkSize = nolinksize;
703 memcpy(itsNolinkBuf, nolink, nolinksize);
704 }
705 itsNameOut = new char[strlen(name)+1+10];
706 strcpy(itsNameOut,name);
707 strcat(itsNameOut,(char *)"/RpcIn");
708 itsNameIn = new char[strlen(name)+1+10];
709 strcpy(itsNameIn,name);
710 strcat(itsNameIn,(char *)"/RpcOut");
711 itsTimeout = timeout;
712 dim_init();
713 {
714 if(!itsId)
715 {
716// itsTagId = id_get((void *)itsHandler, SRC_DIC);
717
718// itsId = dic_info_service_stamped(itsNameIn,MONIT_ONLY,itsTimeout,
719 itsConnected = 0;
720// itsId = dic_info_service_stamped(itsNameIn,MONITORED,itsTimeout,
721 itsId = dic_info_service_stamped(itsNameIn,MONIT_FIRST,itsTimeout,
722 0, 0,
723// rpc_user_routine, itsTagId,
724 rpc_user_routine, (dim_long)itsHandler,
725 itsNolinkBuf, itsNolinkSize);
726// dim_usleep(200000);
727 itsInit = 1;
728 }
729 }
730 if(size)
731 {
732 doIt(data, size);
733 }
734}
735
736void DimRpcInfo::doIt(void *data, int size)
737{
738 int ret;
739
740 wakeUp = 0;
741 if(DimClient::getNoDataCopy() == 0)
742 {
743 if(!itsDataOut)
744 {
745 itsDataOut = new char[size];
746 itsDataOutSize = size;
747 }
748 else if(itsDataOutSize < size)
749 {
750 delete[] (char *)itsDataOut;
751 itsDataOut = new char[size];
752 itsDataOutSize = size;
753 }
754 memcpy(itsDataOut, data, size);
755 }
756 else
757 {
758 itsDataOut = data;
759 }
760 while(!itsConnected)
761 dim_wait();
762 itsWaiting = 1;
763 if(itsTimeout)
764 start(itsTimeout);
765//dim_print_date_time();
766//printf("DIM RPC: Started Timer for %s - %d secs\n", itsName, itsTimeout);
767 ret = DimClient::sendCommand(itsNameOut, itsDataOut, size);
768 if(!ret)
769 {
770 if(itsTimeout)
771 stop();
772//dim_print_date_time();
773//printf("DIM RPC: Stopped Timer, Command failed for %s\n", itsName);
774// rpc_user_routine((int *)&itsTagId, itsNolinkBuf, &itsNolinkSize);
775 rpc_user_routine((dim_long *)&itsHandler, itsNolinkBuf, &itsNolinkSize);
776 }
777/*
778 else
779 {
780 if(itsTimeout)
781 start(itsTimeout);
782 }
783*/
784}
785
786void *DimRpcInfo::getData()
787{
788 while(!wakeUp)
789 {
790#ifdef __VMS
791 sys$hiber();
792#else
793 dim_wait();
794#endif
795 }
796/*
797 if(DimClient::getNoDataCopy() == 1)
798 {
799 if(!DimCore::inCallback)
800 return (void *)0;
801 }
802*/
803 return this->itsData;
804}
805
806DimRpcInfo::~DimRpcInfo()
807{
808// if(itsTagId)
809// id_free(itsTagId, SRC_DIC);
810//dim_print_date_time();
811//printf("DIM RPC: Deleting RPC and Timer for %s\n", itsName);
812 if(itsId)
813 dic_release_service(itsId);
814 delete[] (char *)itsNolinkBuf;
815 if(itsDataSize)
816 delete[] (char *)itsData;
817 if(itsDataOutSize)
818 delete[] (char *)itsDataOut;
819 delete[] itsName;
820 delete[] itsNameIn;
821 delete[] itsNameOut;
822}
823
824DimBrowser::DimBrowser()
825{
826 int i;
827 for(i = 0; i<5; i++)
828 {
829 itsData[i] = 0;
830 itsData[i] = 0;
831 }
832 currIndex = -1;
833 none = 0;
834 browserRpc = 0;
835}
836
837DimBrowser::~DimBrowser()
838{
839 int i;
840 for(i = 0; i<5; i++)
841 {
842 if(itsData[i])
843 delete itsData[i];
844 }
845 if(browserRpc)
846 delete browserRpc;
847}
848
849int DimBrowser::getServices(const char * serviceName)
850{
851 return getServices(serviceName, 0);
852}
853
854int DimBrowser::getServices(const char * serviceName, int timeout)
855{
856 char *str;
857
858// DimRpcInfo rpc((char *)"DIS_DNS/SERVICE_INFO",(char *)"\0");
859// rpc.setData((char *)serviceName);
860// str = rpc.getString();
861 if(!browserRpc)
862 browserRpc = new DimRpcInfo((char *)"DIS_DNS/SERVICE_INFO",timeout,(char *)"\0");
863 browserRpc->setData((char *)serviceName);
864 str = browserRpc->getString();
865 if(itsData[0])
866 delete itsData[0];
867 itsData[0] = new TokenString(str,(char *)"|\n");
868 currIndex = 0;
869 if(!itsData[0]->getNTokens())
870 return(0);
871 return( itsData[0]->getNTokens((char *)"\n") + 1);
872}
873
874int DimBrowser::getServers()
875{
876 return getServers(0);
877}
878
879int DimBrowser::getServers(int timeout)
880{
881 char *str, *pid_str;
882 int size, totsize;
883 DimCurrentInfo srv((char *)"DIS_DNS/SERVER_LIST", timeout, (char *)"\0");
884 str = srv.getString();
885 size = strlen(str)+1;
886 totsize = srv.getSize();
887
888 if(itsData[1])
889 delete itsData[1];
890 itsData[1] = new TokenString(str,(char *)"|@\n");
891 currIndex = 1;
892 if(!str[0])
893 return(0);
894 if(totsize > size)
895 {
896 pid_str = str + strlen(str) + 1;
897 if(itsData[4])
898 delete itsData[4];
899 itsData[4] = new TokenString(pid_str,(char *)"|");
900 }
901 return(itsData[1]->getNTokens((char *)"|") +1);
902}
903
904int DimBrowser::getServerServices(const char *serverName)
905{
906 return getServerServices(serverName, 0);
907}
908
909int DimBrowser::getServerServices(const char *serverName, int timeout)
910{
911 char *str;
912 char *name = new char[strlen(serverName) + 20];
913 strcpy(name,(char *)serverName);
914 strcat(name,(char *)"/SERVICE_LIST");
915 DimCurrentInfo srv(name, timeout, (char *)"\0");
916 delete[] name;
917 str = srv.getString();
918 if(itsData[2])
919 delete itsData[2];
920 itsData[2] = new TokenString(str,(char *)"|\n");
921 currIndex = 2;
922 if(!itsData[2]->getNTokens())
923 return(0);
924 return(itsData[2]->getNTokens((char *)"\n") + 1);
925}
926
927int DimBrowser::getServerClients(const char *serverName)
928{
929 return getServerClients(serverName, 0);
930}
931
932int DimBrowser::getServerClients(const char *serverName, int timeout)
933{
934 char *str;
935 char *name = new char[strlen(serverName) + 20];
936 strcpy(name,(char *)serverName);
937 strcat(name,(char *)"/CLIENT_LIST");
938 DimCurrentInfo srv(name, timeout, (char *)"\0");
939 delete[] name;
940 str = srv.getString();
941 if(itsData[3])
942 delete itsData[3];
943 itsData[3] = new TokenString(str,(char *)"|@\n");
944 currIndex = 3;
945 return(itsData[3]->getNTokens((char *)"@") );
946}
947
948int DimBrowser::getNextService(char *&service, char *&format)
949{
950 int ret, type;
951
952 service = format = &none;
953 ret = itsData[0]->getToken(currToken);
954 if(!ret) return 0;
955 service = currToken;
956 ret = itsData[0]->getToken(currToken);
957 if(!itsData[0]->cmpToken((char *)"|"))
958 return 0;
959 ret = itsData[0]->getToken(currToken);
960 if(!itsData[0]->cmpToken((char *)"|"))
961 {
962 format = currToken;
963 ret = itsData[0]->getToken(currToken);
964 if(!itsData[0]->cmpToken((char *)"|"))
965 return 0;
966 }
967 ret = itsData[0]->getToken(currToken);
968 type = DimSERVICE;
969 if(!itsData[0]->cmpToken((char *)"\n"))
970 {
971 if(itsData[0]->cmpToken((char *)"CMD"))
972 type = DimCOMMAND;
973 if(itsData[0]->cmpToken((char *)"RPC"))
974 type = DimRPC;
975 ret = itsData[0]->getToken(currToken);
976 if(!itsData[0]->cmpToken((char *)"\n"))
977 return 0;
978 }
979 return type;
980}
981
982int DimBrowser::getNextServer(char *&server, char *&node)
983{
984 int ret;
985
986 server = node = &none;
987 ret = itsData[1]->getToken(currToken);
988 if(!ret) return 0;
989 server = currToken;
990 ret = itsData[1]->getToken(currToken);
991 if(!itsData[1]->cmpToken((char *)"@"))
992 return 0;
993 while(1)
994 {
995 ret = itsData[1]->getToken(currToken);
996 node = currToken;
997 itsData[1]->pushToken();
998 ret = itsData[1]->getToken(currToken);
999 if(itsData[1]->cmpToken((char *)"@"))
1000 {
1001 strcat(server,"@");
1002 strcat(server,node);
1003 }
1004 else
1005 break;
1006 }
1007 if(!itsData[1]->cmpToken((char *)"|"))
1008 itsData[1]->popToken();
1009 return 1;
1010}
1011
1012int DimBrowser::getNextServer(char *&server, char *&node, int &pid)
1013{
1014 int ret, lpid = 0;
1015 char *tok;
1016
1017 ret = getNextServer(server, node);
1018 if(ret && itsData[4])
1019 {
1020 ret = itsData[4]->getToken(tok);
1021 if(ret)
1022 {
1023 sscanf(tok,"%d",&lpid);
1024 pid = lpid;
1025 }
1026 }
1027 if(!ret)
1028 return 0;
1029 ret = itsData[4]->getToken(tok);
1030 return 1;
1031}
1032
1033int DimBrowser::getNextServerService(char *&service, char *&format)
1034{
1035 int ret, type;
1036
1037 service = format = &none;
1038 ret = itsData[2]->getToken(currToken);
1039 if(!ret) return 0;
1040 service = currToken;
1041 ret = itsData[2]->getToken(currToken);
1042 if(!itsData[2]->cmpToken((char *)"|"))
1043 return 0;
1044 ret = itsData[2]->getToken(currToken);
1045 if(!itsData[2]->cmpToken((char *)"|"))
1046 {
1047 format = currToken;
1048 ret = itsData[2]->getToken(currToken);
1049 if(!itsData[2]->cmpToken((char *)"|"))
1050 return 0;
1051 }
1052 ret = itsData[2]->getToken(currToken);
1053 type = DimSERVICE;
1054 if(!itsData[2]->cmpToken((char *)"\n"))
1055 {
1056 if(itsData[2]->cmpToken((char *)"CMD"))
1057 type = DimCOMMAND;
1058 if(itsData[2]->cmpToken((char *)"RPC"))
1059 type = DimRPC;
1060 ret = itsData[2]->getToken(currToken);
1061 if(!itsData[2]->cmpToken((char *)"\n"))
1062 return 0;
1063 }
1064 return type;
1065}
1066
1067int DimBrowser::getNextServerClient(char *&client, char *&node)
1068{
1069 int ret;
1070
1071 client = node = &none;
1072 ret = itsData[3]->getToken(currToken);
1073 if(!ret) return 0;
1074 client = currToken;
1075 ret = itsData[3]->getToken(currToken);
1076 if(!itsData[3]->cmpToken((char *)"@"))
1077 return 0;
1078 ret = itsData[3]->getToken(currToken);
1079 node = currToken;
1080 itsData[3]->pushToken();
1081 ret = itsData[3]->getToken(currToken);
1082 if(!itsData[3]->cmpToken((char *)"|"))
1083 itsData[3]->popToken();
1084 return 1;
1085}
1086
1087DimClient::DimClient()
1088{
1089 itsCltError = this;
1090}
1091
1092DimClient::~DimClient()
1093{
1094 if(dimDnsNode)
1095 delete[] dimDnsNode;
1096}
1097
1098int DimClient::sendCommand(const char *name, int data)
1099{
1100 DimCmnd a;
1101 return a.send((char *)name, &data, sizeof(int));
1102}
1103
1104int DimClient::sendCommand(const char *name, float data)
1105{
1106 DimCmnd a;
1107 return a.send((char *)name, &data, sizeof(float));
1108}
1109
1110int DimClient::sendCommand(const char *name, double data)
1111{
1112 DimCmnd a;
1113 return a.send((char *)name, &data, sizeof(double));
1114}
1115
1116int DimClient::sendCommand(const char *name, longlong data)
1117{
1118 DimCmnd a;
1119 return a.send((char *)name, &data, sizeof(longlong));
1120}
1121
1122int DimClient::sendCommand(const char *name, short data)
1123{
1124 DimCmnd a;
1125 return a.send((char *)name, &data, sizeof(short));
1126}
1127
1128int DimClient::sendCommand(const char *name, const char *data)
1129{
1130 DimCmnd a;
1131 return a.send((char *)name, (char *)data, strlen(data)+1);
1132}
1133
1134int DimClient::sendCommand(const char *name, void *data, int datasize)
1135{
1136 DimCmnd a;
1137 return a.send((char *)name, data, datasize);
1138}
1139
1140void DimClient::sendCommandNB(const char *name, int data)
1141{
1142 DimCmnd a;
1143 a.sendNB((char *)name, &data, sizeof(int));
1144}
1145
1146void DimClient::sendCommandNB(const char *name, float data)
1147{
1148 DimCmnd a;
1149 a.sendNB((char *)name, &data, sizeof(float));
1150}
1151
1152void DimClient::sendCommandNB(const char *name, double data)
1153{
1154 DimCmnd a;
1155 a.sendNB((char *)name, &data, sizeof(double));
1156}
1157
1158void DimClient::sendCommandNB(const char *name, longlong data)
1159{
1160 DimCmnd a;
1161 a.sendNB((char *)name, &data, sizeof(longlong));
1162}
1163
1164void DimClient::sendCommandNB(const char *name, short data)
1165{
1166 DimCmnd a;
1167 a.sendNB((char *)name, &data, sizeof(short));
1168}
1169
1170void DimClient::sendCommandNB(const char *name, char *data)
1171{
1172 DimCmnd a;
1173 a.sendNB((char *)name, data, strlen(data)+1);
1174}
1175
1176void DimClient::sendCommandNB(const char *name, void *data, int datasize)
1177{
1178 DimCmnd a;
1179 a.sendNB((char *)name, data, datasize);
1180}
1181
1182int DimClient::setExitHandler(const char *srvName)
1183{
1184 DimCmnd a;
1185 int ret, tag = 1;
1186 char *name = new char[strlen(srvName) + 20];
1187 strcpy(name,(char *)srvName);
1188 strcat(name,"/SET_EXIT_HANDLER");
1189 ret = a.send(name, &tag, sizeof(int));
1190 delete[] name;
1191 return ret;
1192}
1193
1194int DimClient::killServer(const char *srvName)
1195{
1196 DimCmnd a;
1197 int ret, tag = 1;
1198 char *name = new char[strlen(srvName) + 20];
1199 strcpy(name,(char *)srvName);
1200 strcat(name,"/EXIT");
1201 ret = a.send(name, &tag, sizeof(int));
1202 delete[] name;
1203 return ret;
1204}
1205
1206int DimClient::setDnsNode(const char *node)
1207{
1208 dic_set_dns_node((char *)node);
1209 dic_close_dns();
1210 return 1;
1211}
1212
1213int DimClient::setDnsNode(const char *node, int port)
1214{
1215 dic_set_dns_port(port);
1216 dic_set_dns_node((char *)node);
1217 dic_close_dns();
1218 return 1;
1219}
1220
1221char *DimClient::getDnsNode()
1222{
1223 if(!dimDnsNode)
1224 dimDnsNode = new char[256];
1225 if(dic_get_dns_node(dimDnsNode))
1226 return dimDnsNode;
1227 else
1228 return 0;
1229}
1230
1231int DimClient::getDnsPort()
1232{
1233 return dic_get_dns_port();
1234}
1235
1236void DimClient::setNoDataCopy()
1237{
1238 dicNoCopy = 1;
1239}
1240
1241int DimClient::getNoDataCopy()
1242{
1243 return dicNoCopy;
1244}
1245
1246extern "C" {
1247//static void clt_error_user_routine(char*, int);
1248static void clt_error_user_routine(int severity, int code, char *msg)
1249{
1250
1251 DimCore::inCallback = 2;
1252 if(DimClient::itsCltError != 0)
1253 DimClient::itsCltError->errorHandler(severity, code, msg);
1254 DimCore::inCallback = 0;
1255}
1256}
1257
1258void DimClient::addErrorHandler(DimErrorHandler *handler)
1259{
1260 if(handler == 0)
1261 {
1262 dic_add_error_handler(0);
1263 DimClient::itsCltError = 0;
1264 }
1265 else
1266 {
1267 DimClient::itsCltError = handler;
1268 dic_add_error_handler(clt_error_user_routine);
1269 }
1270}
1271
1272void DimClient::addErrorHandler()
1273{
1274 DimClient::itsCltError = this;
1275 dic_add_error_handler(clt_error_user_routine);
1276}
1277
1278int DimClient::getServerId()
1279{
1280 if(!serverName)
1281 serverName = new char[128];
1282 serverName[0] = '\0';
1283 return dic_get_server(serverName);
1284}
1285
1286int DimClient::getServerPid()
1287{
1288 int pid, ret;
1289
1290 ret = dic_get_server_pid(&pid);
1291 if(!ret)
1292 return 0;
1293 return pid;
1294}
1295
1296char *DimClient::getServerName()
1297{
1298 if(!serverName)
1299 serverName = new char[128];
1300 serverName[0] = '\0';
1301 dic_get_server(serverName);
1302 return(serverName);
1303}
1304
1305/*
1306char *DimClient::getServerServices(int serverId)
1307{
1308 return dic_get_server_services(serverId);
1309}
1310
1311char *DimClient::getServerServices()
1312{
1313 int id;
1314 if((id = dic_get_conn_id()))
1315 return dic_get_server_services(id);
1316 return (char *)0;
1317}
1318*/
1319char **DimClient::getServerServices()
1320{
1321 static TokenString *data = 0;
1322 int id, len = 0, index = 0;
1323 char *services;
1324 static char** list = 0;
1325 char *sep;
1326
1327 if(data)
1328 {
1329 delete data;
1330 data = 0;
1331 }
1332 if(list)
1333 {
1334 delete[] list;
1335 list = 0;
1336 }
1337 if((id = dic_get_conn_id()))
1338 {
1339 services = dic_get_server_services(id);
1340 if(services)
1341 {
1342 data = new TokenString(services,(char *)"\n");
1343 len = data->getNTokens();
1344 list = new char*[len];
1345 while(data->getToken(list[index]))
1346 {
1347 data->getToken(sep);
1348 index++;
1349 }
1350 }
1351 }
1352 if(!len)
1353 list = new char*[1];
1354 list[index] = 0;
1355 return list;
1356}
1357
1358int DimClient::inCallback()
1359{
1360 if(DimCore::inCallback)
1361 return 1;
1362 return 0;
1363}
Note: See TracBrowser for help on using the repository browser.