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

Last change on this file since 20115 was 18920, checked in by tbretz, 7 years ago
Updated to v20r20 - This also includes some minor fixes, I requested.
File size: 25.0 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_t)*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, (size_t)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 = (int)strlen(itsFormat)+1;
128 if(len > 1)
129 return itsFormat;
130 }
131 def = dic_get_format(itsId);
132 new_len = (int)strlen(def)+1;
133 if(new_len > len)
134 {
135 if(itsFormat)
136 delete[] itsFormat;
137 itsFormat = new char[(int)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[(int)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, (size_t)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[(int)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, (size_t)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[(int)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, (size_t)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_t)*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[(int)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, (size_t)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_t)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_t)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, (size_t)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[(int)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, (size_t)nolinksize);
704 }
705 itsNameOut = new char[(int)strlen(name)+1+10];
706 strcpy(itsNameOut,name);
707 strcat(itsNameOut,(char *)"/RpcIn");
708 itsNameIn = new char[(int)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_t)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 = (int)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 + (int)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[(int)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[(int)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 if(!itsData[1]->cmpToken((char *)"@"))
990 {
991 server = currToken;
992 ret = itsData[1]->getToken(currToken);
993 }
994 if(!itsData[1]->cmpToken((char *)"@"))
995 return 0;
996 while(1)
997 {
998 ret = itsData[1]->getToken(currToken);
999 node = currToken;
1000 itsData[1]->pushToken();
1001 ret = itsData[1]->getToken(currToken);
1002 if(itsData[1]->cmpToken((char *)"@"))
1003 {
1004 strcat(server,"@");
1005 strcat(server,node);
1006 }
1007 else
1008 break;
1009 }
1010 if(!itsData[1]->cmpToken((char *)"|"))
1011 itsData[1]->popToken();
1012 return 1;
1013}
1014
1015int DimBrowser::getNextServer(char *&server, char *&node, int &pid)
1016{
1017 int ret, lpid = 0;
1018 char *tok;
1019
1020 ret = getNextServer(server, node);
1021 if(ret && itsData[4])
1022 {
1023 ret = itsData[4]->getToken(tok);
1024 if(ret)
1025 {
1026 sscanf(tok,"%d",&lpid);
1027 pid = lpid;
1028 }
1029 }
1030 if(!ret)
1031 return 0;
1032 ret = itsData[4]->getToken(tok);
1033 return 1;
1034}
1035
1036int DimBrowser::getNextServerService(char *&service, char *&format)
1037{
1038 int ret, type;
1039
1040 service = format = &none;
1041 ret = itsData[2]->getToken(currToken);
1042 if(!ret) return 0;
1043 service = currToken;
1044 ret = itsData[2]->getToken(currToken);
1045 if(!itsData[2]->cmpToken((char *)"|"))
1046 return 0;
1047 ret = itsData[2]->getToken(currToken);
1048 if(!itsData[2]->cmpToken((char *)"|"))
1049 {
1050 format = currToken;
1051 ret = itsData[2]->getToken(currToken);
1052 if(!itsData[2]->cmpToken((char *)"|"))
1053 return 0;
1054 }
1055 ret = itsData[2]->getToken(currToken);
1056 type = DimSERVICE;
1057 if(!itsData[2]->cmpToken((char *)"\n"))
1058 {
1059 if(itsData[2]->cmpToken((char *)"CMD"))
1060 type = DimCOMMAND;
1061 if(itsData[2]->cmpToken((char *)"RPC"))
1062 type = DimRPC;
1063 ret = itsData[2]->getToken(currToken);
1064 if(!itsData[2]->cmpToken((char *)"\n"))
1065 return 0;
1066 }
1067 return type;
1068}
1069
1070int DimBrowser::getNextServerClient(char *&client, char *&node)
1071{
1072 int ret;
1073
1074 client = node = &none;
1075 ret = itsData[3]->getToken(currToken);
1076 if(!ret) return 0;
1077 client = currToken;
1078 ret = itsData[3]->getToken(currToken);
1079 if(!itsData[3]->cmpToken((char *)"@"))
1080 return 0;
1081 ret = itsData[3]->getToken(currToken);
1082 node = currToken;
1083 itsData[3]->pushToken();
1084 ret = itsData[3]->getToken(currToken);
1085 if(!itsData[3]->cmpToken((char *)"|"))
1086 itsData[3]->popToken();
1087 return 1;
1088}
1089
1090DimClient::DimClient()
1091{
1092 itsCltError = this;
1093}
1094
1095DimClient::~DimClient()
1096{
1097 if(dimDnsNode)
1098 delete[] dimDnsNode;
1099}
1100
1101int DimClient::sendCommand(const char *name, int data)
1102{
1103 DimCmnd a;
1104 return a.send((char *)name, &data, sizeof(int));
1105}
1106
1107int DimClient::sendCommand(const char *name, float data)
1108{
1109 DimCmnd a;
1110 return a.send((char *)name, &data, sizeof(float));
1111}
1112
1113int DimClient::sendCommand(const char *name, double data)
1114{
1115 DimCmnd a;
1116 return a.send((char *)name, &data, sizeof(double));
1117}
1118
1119int DimClient::sendCommand(const char *name, longlong data)
1120{
1121 DimCmnd a;
1122 return a.send((char *)name, &data, sizeof(longlong));
1123}
1124
1125int DimClient::sendCommand(const char *name, short data)
1126{
1127 DimCmnd a;
1128 return a.send((char *)name, &data, sizeof(short));
1129}
1130
1131int DimClient::sendCommand(const char *name, const char *data)
1132{
1133 DimCmnd a;
1134 return a.send((char *)name, (char *)data, (int)strlen(data)+1);
1135}
1136
1137int DimClient::sendCommand(const char *name, void *data, int datasize)
1138{
1139 DimCmnd a;
1140 return a.send((char *)name, data, datasize);
1141}
1142
1143void DimClient::sendCommandNB(const char *name, int data)
1144{
1145 DimCmnd a;
1146 a.sendNB((char *)name, &data, sizeof(int));
1147}
1148
1149void DimClient::sendCommandNB(const char *name, float data)
1150{
1151 DimCmnd a;
1152 a.sendNB((char *)name, &data, sizeof(float));
1153}
1154
1155void DimClient::sendCommandNB(const char *name, double data)
1156{
1157 DimCmnd a;
1158 a.sendNB((char *)name, &data, sizeof(double));
1159}
1160
1161void DimClient::sendCommandNB(const char *name, longlong data)
1162{
1163 DimCmnd a;
1164 a.sendNB((char *)name, &data, sizeof(longlong));
1165}
1166
1167void DimClient::sendCommandNB(const char *name, short data)
1168{
1169 DimCmnd a;
1170 a.sendNB((char *)name, &data, sizeof(short));
1171}
1172
1173void DimClient::sendCommandNB(const char *name, char *data)
1174{
1175 DimCmnd a;
1176 a.sendNB((char *)name, data, (int)strlen(data)+1);
1177}
1178
1179void DimClient::sendCommandNB(const char *name, void *data, int datasize)
1180{
1181 DimCmnd a;
1182 a.sendNB((char *)name, data, datasize);
1183}
1184
1185int DimClient::setExitHandler(const char *srvName)
1186{
1187 DimCmnd a;
1188 int ret, tag = 1;
1189 char *name = new char[(int)strlen(srvName) + 20];
1190 strcpy(name,(char *)srvName);
1191 strcat(name,"/SET_EXIT_HANDLER");
1192 ret = a.send(name, &tag, sizeof(int));
1193 delete[] name;
1194 return ret;
1195}
1196
1197int DimClient::killServer(const char *srvName)
1198{
1199 DimCmnd a;
1200 int ret, tag = 1;
1201 char *name = new char[(int)strlen(srvName) + 20];
1202 strcpy(name,(char *)srvName);
1203 strcat(name,"/EXIT");
1204 ret = a.send(name, &tag, sizeof(int));
1205 delete[] name;
1206 return ret;
1207}
1208
1209int DimClient::setDnsNode(const char *node)
1210{
1211 dic_set_dns_node((char *)node);
1212 dic_close_dns();
1213 return 1;
1214}
1215
1216int DimClient::setDnsNode(const char *node, int port)
1217{
1218 dic_set_dns_port(port);
1219 dic_set_dns_node((char *)node);
1220 dic_close_dns();
1221 return 1;
1222}
1223
1224char *DimClient::getDnsNode()
1225{
1226 if(!dimDnsNode)
1227 dimDnsNode = new char[256];
1228 if(dic_get_dns_node(dimDnsNode))
1229 return dimDnsNode;
1230 else
1231 return 0;
1232}
1233
1234int DimClient::getDnsPort()
1235{
1236 return dic_get_dns_port();
1237}
1238
1239void DimClient::setNoDataCopy()
1240{
1241 dicNoCopy = 1;
1242}
1243
1244int DimClient::getNoDataCopy()
1245{
1246 return dicNoCopy;
1247}
1248
1249extern "C" {
1250//static void clt_error_user_routine(char*, int);
1251static void clt_error_user_routine(int severity, int code, char *msg)
1252{
1253
1254 DimCore::inCallback = 2;
1255 if(DimClient::itsCltError != 0)
1256 DimClient::itsCltError->errorHandler(severity, code, msg);
1257 DimCore::inCallback = 0;
1258}
1259}
1260
1261void DimClient::addErrorHandler(DimErrorHandler *handler)
1262{
1263 if(handler == 0)
1264 {
1265 dic_add_error_handler(0);
1266 DimClient::itsCltError = 0;
1267 }
1268 else
1269 {
1270 DimClient::itsCltError = handler;
1271 dic_add_error_handler(clt_error_user_routine);
1272 }
1273}
1274
1275void DimClient::addErrorHandler()
1276{
1277 DimClient::itsCltError = this;
1278 dic_add_error_handler(clt_error_user_routine);
1279}
1280
1281int DimClient::getServerId()
1282{
1283 if(!serverName)
1284 serverName = new char[128];
1285 serverName[0] = '\0';
1286 return dic_get_server(serverName);
1287}
1288
1289int DimClient::getServerPid()
1290{
1291 int pid, ret;
1292
1293 ret = dic_get_server_pid(&pid);
1294 if(!ret)
1295 return 0;
1296 return pid;
1297}
1298
1299char *DimClient::getServerName()
1300{
1301 if(!serverName)
1302 serverName = new char[128];
1303 serverName[0] = '\0';
1304 dic_get_server(serverName);
1305 return(serverName);
1306}
1307
1308/*
1309char *DimClient::getServerServices(int serverId)
1310{
1311 return dic_get_server_services(serverId);
1312}
1313
1314char *DimClient::getServerServices()
1315{
1316 int id;
1317 if((id = dic_get_conn_id()))
1318 return dic_get_server_services(id);
1319 return (char *)0;
1320}
1321*/
1322char **DimClient::getServerServices()
1323{
1324 static TokenString *data = 0;
1325 int id, len = 0, index = 0;
1326 char *services;
1327 static char** list = 0;
1328 char *sep;
1329
1330 if(data)
1331 {
1332 delete data;
1333 data = 0;
1334 }
1335 if(list)
1336 {
1337 delete[] list;
1338 list = 0;
1339 }
1340 if((id = dic_get_conn_id()))
1341 {
1342 services = dic_get_server_services(id);
1343 if(services)
1344 {
1345 data = new TokenString(services,(char *)"\n");
1346 len = data->getNTokens();
1347 list = new char*[len];
1348 while(data->getToken(list[index]))
1349 {
1350 data->getToken(sep);
1351 index++;
1352 }
1353 }
1354 }
1355 if(!len)
1356 list = new char*[1];
1357 list[index] = 0;
1358 return list;
1359}
1360
1361int DimClient::inCallback()
1362{
1363 if(DimCore::inCallback)
1364 return 1;
1365 return 0;
1366}
Note: See TracBrowser for help on using the repository browser.