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

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