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

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