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

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