FACT++  1.0
discpp.cxx
Go to the documentation of this file.
1 #define DIMLIB
2 #include <dis.hxx>
3 #include "tokenstring.hxx"
4 //#include <iostream>
5 //using namespace std;
6 #include <time.h>
7 //#include <sys/timeb.h>
8 
12 char *DimServer::itsName = 0;
13 char *DimServer::clientName = 0;
14 char *DimServer::dimDnsNode = 0;
15 int DimServer::autoStart = 1;
16 //int DimServer::itsNServices = 0;
17 
18 extern "C" {
19 extern void dis_init();
20 
21 static void user_routine( void *tagp, void **buf, int *size, int *first_time)
22 {
23 // int *tag = (int *)tagp;
24 // int id = *tag;
25  DimService *t;
26 
27  if(first_time){}
28 // t = (DimService *)id_get_ptr(id, SRC_DIS);
29  t = *(DimService **)tagp;
30  if( t->itsServiceHandler ) {
35  }
36  else
37  {
39  t->serviceHandler();
41  }
42  if( t->itsType == DisSTRING)
43  t->itsSize = (int)strlen((char *)t->itsData)+1;
44  *buf = t->itsData;
45  *size = t->itsSize;
46 }
47 }
48 
49 void DimService::declareIt(char *name, char *format, DimServiceHandler *handler, DimServerDns *dns)
50 {
51 // itsTagId = 0;
52  itsDns = dns;
53  itsName = new char[(int)strlen(name)+1];
54  itsDataSize = 0;
55  strcpy( itsName, name);
56  if(handler)
58  else
60 // itsTagId = id_get((void *)this, SRC_DIS);
61  dis_init();
62  if(itsDns == 0)
63  {
64  DISABLE_AST
65  itsId = dis_add_service( name, format, NULL, 0,
66 // user_routine, itsTagId);
67  user_routine, (dim_long)this);
68  ENABLE_AST
70  }
71  else
72  {
73  DISABLE_AST
74  itsId = dis_add_service_dns( itsDns->getDnsId(), name, format, NULL, 0,
75 // user_routine, itsTagId);
76  user_routine, (dim_long)this);
77  ENABLE_AST
78 // itsDns->addServiceId(itsId);
80  }
81 }
82 
83 void DimService::storeIt(void *data, int size)
84 {
85  DISABLE_AST
86  if(!itsId)
87  {
88  ENABLE_AST
89  return;
90  }
91  if(!itsDataSize)
92  {
93  itsData = new char[size];
94  itsDataSize = size;
95  }
96  else if(itsDataSize < size)
97  {
98  delete[] (char *)itsData;
99  itsData = new char[size];
100  itsDataSize = size;
101  }
102  memcpy(itsData, data, (size_t)size);
103  itsSize = size;
104  ENABLE_AST
105 }
106 
107 extern "C" {
108 static void command_routine( void *tagp, void *buf, int *size)
109 {
110 // int *tag = (int *)tagp;
111 // int id = *tag;
112  DimCommand *t;
113 
114 // t = (DimCommand *)id_get_ptr(id, SRC_DIS);
115  t = *(DimCommand **)tagp;
116  t->itsData = buf;
117  t->itsSize = *size;
118  t->secs = 0;
119  if( t->itsCommandHandler ) {
124  }
125  else
126  {
128  t->commandHandler();
130  }
131  t->itsData = 0;
132  t->itsSize = 0;
133 }
134 }
135 
136 void DimCommand::declareIt(char *name, char *format, DimCommandHandler *handler, DimServerDns *dns)
137 {
138 // itsTagId = 0;
139  itsId = 0;
140  itsDns = dns;
141  itsName = new char[(int)strlen(name)+1];
142  strcpy( itsName, name);
143  itsFormat = new char[(int)strlen(format)+1];
144  strcpy( itsFormat, format);
145  currCmnd = 0;
146  if(handler)
147  itsCommandHandler = handler;
148  else
149  itsCommandHandler = 0;
150 // itsTagId = id_get((void *)this, SRC_DIS);
151  dis_init();
152  if(!itsDns)
153  {
154  DISABLE_AST
155  itsId = dis_add_cmnd( name, format, command_routine,
156 // itsTagId);
157  (dim_long)this);
158  ENABLE_AST
160  }
161  else
162  {
163  DISABLE_AST
165 // itsTagId);
166  (dim_long)this);
167  ENABLE_AST
168 // itsDns->addServiceId(itsId);
170  }
171 }
172 
173 extern "C" {
174 /*
175 static void timeout_rout(DimRpc *t)
176 {
177  sleep(t->itsTimeout);
178  t->itsKilled = 1;
179 }
180 */
181 static void rpcin_routine( void *tagp, void *buf, int *size)
182 {
183  time_t tt1 = 0, tt2 = 0;
184 
185 // int *tag = (int *)tagp;
186 // int id = *tag;
187  DimRpc *t;
188  int tout, clientId, ids[2];
189 // long tid;
190 
191 // t = (DimRpc *)id_get_ptr(id, SRC_DIS);
192  t = *(DimRpc **)tagp;
193  t->itsDataIn = buf;
194  t->itsSizeIn = *size;
195  clientId = dis_get_conn_id();
196  tout = dis_get_timeout(t->itsIdOut, clientId);
197  t->itsTimeout = tout;
198 // tid = 0;
199  if(tout > 0)
200  {
201  tt1 = time((time_t *)0);
202  t->itsKilled = 0;
203 // dtq_start_timer(t->itsTimeout,(void(*)(void *))timeout_rout,(void *)t);
204 // tid = dim_start_thread((void(*)(void *))timeout_rout,(void *)t);
205  }
207  t->rpcHandler();
209  t->itsDataIn = 0;
210  t->itsSizeIn = 0;
211  if(tout > 0)
212  {
213  tt2 = time((time_t *)0);
214  if((tt2 - tt1) > tout)
215  t->itsKilled = 1;
216  }
217  if(!t->itsKilled)
218  {
219 // if(tid)
220 // {
221 // dtq_stop_timer((void *)t);
222 // dim_stop_thread(tid);
223 // }
224  ids[0] = clientId;
225  ids[1] = 0;
227  }
228 }
229 
230 }
231 
232 extern "C" {
233 static void rpcout_routine( void *tagp, void **buf, int *size, int *first_time)
234 {
235 // int *tag = (int *)tagp;
236 // int id = *tag;
237  DimRpc *t;
238 
239  if(first_time){}
240 // t = (DimRpc *)id_get_ptr(id, SRC_DIS);
241  t = *(DimRpc**)tagp;
242  *buf = t->itsDataOut;
243  *size = t->itsSizeOut;
244 }
245 }
246 
247 void DimRpc::declareIt(char *name, char *formatin, char *formatout, DimServerDns *dns)
248 {
249 // itsTagId = 0;
250  itsIdIn = 0;
251  itsIdOut = 0;
252  itsDns = dns;
253  itsName = new char[(int)strlen(name)+1];
254  strcpy( itsName, name);
255  itsNameIn = new char[(int)strlen(name)+1+10];
256  strcpy( itsNameIn, name);
257  strcat(itsNameIn,(char *)"/RpcIn");
258  itsNameOut = new char[(int)strlen(name)+1+10];
259  strcpy( itsNameOut, name);
260  strcat(itsNameOut,(char *)"/RpcOut");
261  itsDataOut = new char[1];
262  itsDataOutSize = itsSizeOut = 1;
263  itsKilled = 0;
264  itsTimeout = 0;
265 
266 // itsTagId = id_get((void *)this, SRC_DIS);
267  dis_init();
268  if(!itsDns)
269  {
270  DISABLE_AST
271  itsIdIn = dis_add_cmnd( itsNameIn, formatin,
272 // rpcin_routine, itsTagId);
273  rpcin_routine, (dim_long)this);
274  itsIdOut = dis_add_service( itsNameOut, formatout, 0,0,
275 // rpcout_routine, itsTagId);
276  rpcout_routine, (dim_long)this);
277  ENABLE_AST
279  }
280  else
281  {
282  DISABLE_AST
283  itsIdIn = dis_add_cmnd_dns( itsDns->getDnsId(), itsNameIn, formatin,
284 // rpcin_routine, itsTagId);
285  rpcin_routine, (dim_long)this);
286  itsIdOut = dis_add_service_dns( itsDns->getDnsId(), itsNameOut, formatout, 0,0,
287 // rpcout_routine, itsTagId);
288  rpcout_routine, (dim_long)this);
289  ENABLE_AST
290 // itsDns->addServiceId(itsIdIn);
291 // itsDns->addServiceId(itsIdOut);
293  }
294 }
295 
296 void DimRpc::storeIt(void *data, int size)
297 {
298  DISABLE_AST
299  if(!itsIdIn)
300  {
301  ENABLE_AST
302  return;
303  }
304  if(!itsDataOutSize)
305  {
306  itsDataOut = new char[size];
307  itsDataOutSize = size;
308  }
309  else if(itsDataOutSize < size)
310  {
311  delete[] (char *)itsDataOut;
312  itsDataOut = new char[size];
313  itsDataOutSize = size;
314  }
315  memcpy(itsDataOut, data, (size_t)size);
316  itsSizeOut = size;
317  ENABLE_AST
318 }
319 
320 extern "C" {
321 static void client_exit_user_routine(int*);
322 static void exit_user_routine(int*);
323 static void srv_error_user_routine(int, int, char*);
324 }
325 
327 {
328  init(node, 0);
329 }
330 
331 DimServerDns::DimServerDns(const char *node, int port)
332 {
333  init(node, port);
334 }
335 
336 DimServerDns::DimServerDns(const char *node, int port, char *name)
337 {
338  init(node, port);
339  DimServer::start(this, name);
340 }
341 
342 #define DisDnsIdBlock 100
343 
344 void DimServerDns::init(const char *node, int port)
345 {
346 // if(!itsNode)
347 // {
348  itsNode = new char[(int)strlen(node)+1];
349  strcpy(itsNode,node);
350 // }
351  itsPort = port;
352  autoStart = 1;
353  itsName = 0;
354  itsServiceIdList = new int[DisDnsIdBlock];
355  itsServiceIdListSize = DisDnsIdBlock;
356  itsNServiceIds = 0;
357 // itsNServices = 0;
358  itsDnsId = DimServer::addDns(node, port);
359 }
360 
362 {
363  int *tmp;
364 
365  DISABLE_AST
366  if((itsNServiceIds + 2) > itsServiceIdListSize)
367  {
368  tmp = new int[itsServiceIdListSize + DisDnsIdBlock];
369  memcpy(tmp, itsServiceIdList, (size_t)itsServiceIdListSize*sizeof(int));
370  delete itsServiceIdList;
371  itsServiceIdList = tmp;
372  itsServiceIdListSize += DisDnsIdBlock;
373  }
374  itsServiceIdList[itsNServiceIds] = id;
375  itsServiceIdList[itsNServiceIds+1] = 0;
376  itsNServiceIds++;
377  ENABLE_AST
378 }
379 
381 {
382  int *list;
383  if(itsNServiceIds)
384  list = itsServiceIdList;
385  else
386  list = 0;
387  itsNServiceIds = 0;
388  return list;
389 }
390 
392 {
393  if(itsName)
394  {
395  DimServer::stop(this);
396 // if(itsName)
397 // delete[] itsName;
398  }
399 // if(itsNode)
400  delete[] itsNode;
401 }
402 
404 {
405  return itsDnsId;
406 }
407 
408 void DimServerDns::setName(const char *name)
409 {
410  if(!itsName)
411  {
412  itsName = new char[(int)strlen(name)+1];
413  strcpy(itsName,name);
414  }
415 }
416 
418 {
419  if(itsName)
420  {
421  delete[] itsName;
422  itsName = 0;
423  }
424 }
425 
427 {
428  return itsName;
429 }
430 
432 {
433  autoStart = 1;
434 }
435 
437 {
438  autoStart = 0;
439 }
440 
442 {
443  return autoStart;
444 }
445 
447 {
448  itsClientExit = this;
449  itsExit = this;
450  itsSrvError = this;
451 // itsNServices = 0;
452 }
453 
455 {
456  if(itsName)
457  {
459  delete[] itsName;
460  }
461  if(clientName)
462  delete[] clientName;
463  if(dimDnsNode)
464  delete[] dimDnsNode;
465 }
466 
467 void DimServer::start(const char *name)
468 {
469  if(!itsName)
470  {
471  itsName = new char[(int)strlen(name)+1];
472  strcpy(itsName,name);
473  }
475 }
476 
477 void DimServer::start(DimServerDns *dns, const char *name)
478 {
479  dim_long dnsid;
480 
481  dis_init();
482  {
483  DISABLE_AST
484  dns->setName(name);
485  dnsid = dns->getDnsId();
486  dis_start_serving_dns(dnsid, (char *)name /*, dns->getServiceIdList()*/);
487  ENABLE_AST
488  }
489 }
490 /*
491 void DimServer::threadHandler()
492 {
493  int oldNServices;
494 
495  while(1)
496  {
497  oldNServices = itsNServices;
498  usleep(100000);
499  if(oldNServices == itsNServices)
500  break;
501  }
502 cout << "Starting " << itsNServices << endl;
503  {
504  DISABLE_AST
505  dis_start_serving(itsName);
506  itsNServices = 0;
507  ENABLE_AST
508  }
509 
510 }
511 */
513 {
514 // itsNServices++;
515  if((itsName) && (autoStart))
516  {
517 // DimThread::start();
519  }
520 }
521 
523 {
524  dim_long dnsid;
525  char *name;
526  int isAuto;
527 
528  dis_init();
529  {
530  DISABLE_AST
531 // dns->itsNServices++;
532 
533  name = dns->getName();
534  dnsid = dns->getDnsId();
535  isAuto = dns->isAutoStart();
536  if((name) && (isAuto))
537  {
538 // DimThread::start();
539  dis_start_serving_dns(dnsid, (char *)name /*, dns->getServiceIdList()*/);
540  }
541  ENABLE_AST
542  }
543 }
544 
546 {
548  if(itsName)
549  {
550  delete[] itsName;
551  itsName = 0;
552  }
553 }
554 
556 {
558  dns->clearName();
559 }
560 
562 {
563  autoStart = 1;
564 }
565 
567 {
568  autoStart = 0;
569 }
570 
572 {
573  if(!clientName)
574  clientName = new char[128];
575  clientName[0] = '\0';
576  return dis_get_client(clientName);
577 }
578 
580 {
581  if(!clientName)
582  clientName = new char[128];
583  clientName[0] = '\0';
584  dis_get_client(clientName);
585  return(clientName);
586 }
587 /*
588 char *DimServer::getClientServices()
589 {
590  int id;
591  if((id = dis_get_conn_id()))
592  return dis_get_client_services(id);
593  return (char *)0;
594 }
595 
596 char *DimServer::getClientServices(int clientId)
597 {
598  return dis_get_client_services(clientId);
599 }
600 */
602 {
603  static TokenString *data = 0;
604  int id, len = 0, index = 0;
605  char *services;
606  static char** list = 0;
607  char *sep;
608 
609  if(data)
610  {
611  delete data;
612  data = 0;
613  }
614  if(list)
615  {
616  delete[] list;
617  list = 0;
618  }
619  if((id = dis_get_conn_id()))
620  {
621  services = dis_get_client_services(id);
622  if(services)
623  {
624  data = new TokenString(services,(char *)"\n");
625  len = data->getNTokens();
626  list = new char*[len];
627  while(data->getToken(list[index]))
628  {
629  data->getToken(sep);
630  index++;
631  }
632  }
633  }
634  if(!len)
635  list = new char*[1];
636  list[index] = 0;
637  return list;
638 }
639 
641 {
642  dis_set_client_exit_handler(clientId, 1);
643 }
644 
646 {
647  dis_set_client_exit_handler(clientId, 0);
648 }
649 
651 {
652  if(handler == 0)
653  {
655  DimServer::itsClientExit = 0;
656  }
657  else
658  {
659  DimServer::itsClientExit = handler;
661  }
662 }
663 
665 {
666  DimServer::itsClientExit = this;
668 }
669 
671 {
672  if(handler == 0)
673  {
675  DimServer::itsExit = 0;
676  }
677  else
678  {
679  DimServer::itsExit = handler;
681  }
682 }
683 
685 {
686  if(handler == 0)
687  {
689  DimServer::itsSrvError = 0;
690  }
691  else
692  {
693  DimServer::itsSrvError = handler;
695  }
696 }
697 
698 int DimServer::setDnsNode(const char *node)
699 {
700  return dis_set_dns_node((char *)node);
701 }
702 
703 int DimServer::setDnsNode(const char *node, int port)
704 {
705  dis_set_dns_port(port);
706  return dis_set_dns_node((char *)node);
707 }
708 
709 dim_long DimServer::addDns(const char *node, int port)
710 {
711  return dis_add_dns((char *)node, port);
712 }
714 {
715  if(!dimDnsNode)
716  dimDnsNode = new char[256];
717  if(dis_get_dns_node(dimDnsNode))
718  return dimDnsNode;
719  else
720  return 0;
721 }
722 
724 {
725  return dis_get_dns_port();
726 }
727 
729 {
730  dim_set_write_timeout(secs);
731 }
732 
734 {
735  return dim_get_write_timeout();
736 }
737 
739 {
740  DimServer::itsExit = this;
742 }
743 
745 {
746  DimServer::itsSrvError = this;
748 }
749 
751 {
753  return 1;
754  return 0;
755 }
756 
757 extern "C" {
758 static void client_exit_user_routine(int *idp)
759 {
760  int id = *idp;
761 
762  id++;
764  DimServer::itsClientExit->clientExitHandler();
766 }
767 
768 static void exit_user_routine(int *idp)
769 {
770 // int id = *idp;
771 
772 // id++;
774  DimServer::itsExit->exitHandler(*idp);
776 }
777 
778 static void srv_error_user_routine(int severity, int code, char *msg)
779 {
780 
782  if(DimServer::itsSrvError != 0)
783  DimServer::itsSrvError->errorHandler(severity, code, msg);
785 }
786 
787 }
788 
789 
791 {
792 // itsTagId = 0;
793  itsId = 0;
794  itsName = 0;
795 }
796 
797 DimService::DimService(const char *name, int &value)
798 {
799  itsId = 0;
800  itsName = 0;
801  itsData = &value;
802  itsSize = sizeof(int);
803  itsType = DisINT;
804  declareIt((char *)name, (char *)"L", 0, 0);
805 }
806 
807 DimService::DimService(const char *name, float &value)
808 {
809  itsId = 0;
810  itsName = 0;
811  itsData = &value;
812  itsSize = sizeof(float);
813  itsType = DisFLOAT;
814  declareIt((char *)name, (char *)"F", 0, 0);
815 }
816 
817 DimService::DimService(const char *name, double &value)
818 {
819  itsId = 0;
820  itsName = 0;
821  itsData = &value;
822  itsSize = sizeof(double);
823  itsType = DisDOUBLE;
824  declareIt((char *)name, (char *)"D", 0, 0);
825 }
826 
827 DimService::DimService(const char *name, longlong &value)
828 {
829  itsId = 0;
830  itsName = 0;
831  itsData = &value;
832  itsSize = sizeof(longlong);
833  itsType = DisXLONG;
834  declareIt((char *)name, (char *)"X", 0, 0);
835 }
836 
837 DimService::DimService(const char *name, short &value)
838 {
839  itsId = 0;
840  itsName = 0;
841  itsData = &value;
842  itsSize = sizeof(short);
843  itsType = DisSHORT;
844  declareIt((char *)name, (char *)"S", 0, 0);
845 }
846 
847 DimService::DimService(const char *name, char *string)
848 {
849  itsId = 0;
850  itsName = 0;
851  itsData = string;
852  itsSize = (int)strlen(string)+1;
853  itsType = DisSTRING;
854  declareIt((char *)name, (char *)"C", 0, 0);
855 }
856 
857 DimService::DimService(const char *name, char *format, void *structure, int size)
858 {
859  itsId = 0;
860  itsName = 0;
861  itsData = structure;
862  itsSize = size;
864  declareIt((char *)name, (char *)format, 0, 0);
865 }
866 
867 DimService::DimService(const char *name, char *format, DimServiceHandler *handler)
868 {
869  itsId = 0;
870  itsName = 0;
871  itsData = 0;
872  itsSize = 0;
874  declareIt((char *)name, (char *)format, handler, 0);
875 }
876 
877 DimService::DimService(const char *name, const char *format, void *structure, int size)
878 {
879  itsId = 0;
880  itsName = 0;
881  itsData = structure;
882  itsSize = size;
884  declareIt((char *)name, (char *)format, 0, 0);
885 }
886 
887 DimService::DimService(const char *name, const char *format, DimServiceHandler *handler)
888 {
889  itsId = 0;
890  itsName = 0;
891  itsData = 0;
892  itsSize = 0;
894  declareIt((char *)name, (char *)format, handler, 0);
895 }
896 
897 // with Dns
898 
899 DimService::DimService(DimServerDns *dns, const char *name, int &value)
900 {
901  itsId = 0;
902  itsName = 0;
903  itsData = &value;
904  itsSize = sizeof(int);
905  itsType = DisINT;
906  declareIt((char *)name, (char *)"L", 0, dns);
907 }
908 
909 DimService::DimService(DimServerDns *dns, const char *name, float &value)
910 {
911  itsId = 0;
912  itsName = 0;
913  itsData = &value;
914  itsSize = sizeof(float);
915  itsType = DisFLOAT;
916  declareIt((char *)name, (char *)"F", 0, dns);
917 }
918 
919 DimService::DimService(DimServerDns *dns, const char *name, double &value)
920 {
921  itsId = 0;
922  itsName = 0;
923  itsData = &value;
924  itsSize = sizeof(double);
925  itsType = DisDOUBLE;
926  declareIt((char *)name, (char *)"D", 0, dns);
927 }
928 
929 DimService::DimService(DimServerDns *dns, const char *name, longlong &value)
930 {
931  itsId = 0;
932  itsName = 0;
933  itsData = &value;
934  itsSize = sizeof(longlong);
935  itsType = DisXLONG;
936  declareIt((char *)name, (char *)"X", 0, dns);
937 }
938 
939 DimService::DimService(DimServerDns *dns, const char *name, short &value)
940 {
941  itsId = 0;
942  itsName = 0;
943  itsData = &value;
944  itsSize = sizeof(short);
945  itsType = DisSHORT;
946  declareIt((char *)name, (char *)"S", 0, dns);
947 }
948 
949 DimService::DimService(DimServerDns *dns, const char *name, char *string)
950 {
951  itsId = 0;
952  itsName = 0;
953  itsData = string;
954  itsSize = (int)strlen(string)+1;
955  itsType = DisSTRING;
956  declareIt((char *)name, (char *)"C", 0, dns);
957 }
958 
959 DimService::DimService(DimServerDns *dns, const char *name, char *format, void *structure, int size)
960 {
961  itsId = 0;
962  itsName = 0;
963  itsData = structure;
964  itsSize = size;
966  declareIt((char *)name, (char *)format, 0, dns);
967 }
968 
969 DimService::DimService(DimServerDns *dns, const char *name, char *format, DimServiceHandler *handler)
970 {
971  itsId = 0;
972  itsName = 0;
973  itsData = 0;
974  itsSize = 0;
976  declareIt((char *)name, (char *)format, handler, dns);
977 }
978 
979 
980 DimService::DimService(DimServerDns *dns, const char *name, const char *format, void *structure, int size)
981 {
982  itsId = 0;
983  itsName = 0;
984  itsData = structure;
985  itsSize = size;
987  declareIt((char *)name, (char *)format, 0, dns);
988 }
989 
990 DimService::DimService(DimServerDns *dns, const char *name, const char *format, DimServiceHandler *handler)
991 {
992  itsId = 0;
993  itsName = 0;
994  itsData = 0;
995  itsSize = 0;
997  declareIt((char *)name, (char *)format, handler, dns);
998 }
999 
1000 
1002 {
1003  DISABLE_AST
1004  if(itsName)
1005  delete[] itsName;
1006  if(itsDataSize)
1007  delete[] (char *)itsData;
1008 // if(itsTagId)
1009 // id_free(itsTagId, SRC_DIS);
1010  if(itsId)
1012  itsId = 0;
1013  ENABLE_AST
1014 }
1015 
1017 {
1018  if(!itsId)
1019  return 0;
1020  return dis_update_service( itsId );
1021 }
1022 
1023 int DimService::updateService( int &value )
1024 {
1025  if(!itsId)
1026  return 0;
1027  if( itsType == DisINT)
1028  {
1029  itsData = &value;
1030  return dis_update_service( itsId );
1031  }
1032  return -1;
1033 }
1034 
1035 int DimService::updateService( float &value )
1036 {
1037  if(!itsId)
1038  return 0;
1039  if( itsType == DisFLOAT) {
1040  itsData = &value;
1041  return dis_update_service( itsId );
1042  }
1043  return -1;
1044 }
1045 
1046 int DimService::updateService( double &value )
1047 {
1048  if(!itsId)
1049  return 0;
1050  if( itsType == DisDOUBLE) {
1051  itsData = &value;
1052  return dis_update_service( itsId );
1053  }
1054  return -1;
1055 }
1056 
1058 {
1059  if(!itsId)
1060  return 0;
1061  if( itsType == DisXLONG)
1062  {
1063  itsData = &value;
1064  return dis_update_service( itsId );
1065  }
1066  return -1;
1067 }
1068 
1069 int DimService::updateService( short &value )
1070 {
1071  if(!itsId)
1072  return 0;
1073  if( itsType == DisSHORT)
1074  {
1075  itsData = &value;
1076  return dis_update_service( itsId );
1077  }
1078  return -1;
1079 }
1080 
1081 int DimService::updateService( char *string )
1082 {
1083  if(!itsId)
1084  return 0;
1085  if( itsType == DisSTRING)
1086  {
1087  itsData = string;
1088  itsSize = (int)strlen(string)+1;
1089  return dis_update_service( itsId );
1090  }
1091  return -1;
1092 }
1093 
1094 int DimService::updateService( void *structure, int size )
1095 {
1096  if(!itsId)
1097  return 0;
1098  if( itsType == DisPOINTER)
1099  {
1100  itsData = structure;
1101  itsSize = size;
1102  return dis_update_service( itsId );
1103  }
1104  return -1;
1105 }
1106 
1108 {
1109  if(!itsId)
1110  return 0;
1111  if( cids == 0)
1112  {
1113  int ids[2];
1114  ids[0] = DimServer::getClientId();
1115  ids[1] = 0;
1116  return dis_selective_update_service( itsId, ids );
1117  }
1118  return dis_selective_update_service( itsId, cids );
1119 }
1120 
1121 int DimService::selectiveUpdateService( int &value, int *cids)
1122 {
1123  if(!itsId)
1124  return 0;
1125  if( itsType == DisINT)
1126  {
1127  itsData = &value;
1128  if( cids == 0)
1129  {
1130  int ids[2];
1131  ids[0] = DimServer::getClientId();
1132  ids[1] = 0;
1133  return dis_selective_update_service( itsId, ids );
1134  }
1135  return dis_selective_update_service( itsId, cids );
1136  }
1137  return -1;
1138 }
1139 
1140 int DimService::selectiveUpdateService( float &value, int *cids )
1141 {
1142  if(!itsId)
1143  return 0;
1144  if( itsType == DisFLOAT)
1145  {
1146  itsData = &value;
1147  if( cids == 0)
1148  {
1149  int ids[2];
1150  ids[0] = DimServer::getClientId();
1151  ids[1] = 0;
1152  return dis_selective_update_service( itsId, ids );
1153  }
1154  return dis_selective_update_service( itsId, cids );
1155  }
1156  return -1;
1157 }
1158 
1159 int DimService::selectiveUpdateService( double &value, int *cids )
1160 {
1161  if(!itsId)
1162  return 0;
1163  if( itsType == DisDOUBLE)
1164  {
1165  itsData = &value;
1166  if( cids == 0)
1167  {
1168  int ids[2];
1169  ids[0] = DimServer::getClientId();
1170  ids[1] = 0;
1171  return dis_selective_update_service( itsId, ids );
1172  }
1173  return dis_selective_update_service( itsId, cids );
1174  }
1175  return -1;
1176 }
1177 
1179 {
1180  if(!itsId)
1181  return 0;
1182  if( itsType == DisXLONG)
1183  {
1184  itsData = &value;
1185  if( cids == 0)
1186  {
1187  int ids[2];
1188  ids[0] = DimServer::getClientId();
1189  ids[1] = 0;
1190  return dis_selective_update_service( itsId, ids );
1191  }
1192  return dis_selective_update_service( itsId, cids );
1193  }
1194  return -1;
1195 }
1196 
1197 int DimService::selectiveUpdateService( short &value, int *cids )
1198 {
1199  if(!itsId)
1200  return 0;
1201  if( itsType == DisSHORT)
1202  {
1203  itsData = &value;
1204  if( cids == 0)
1205  {
1206  int ids[2];
1207  ids[0] = DimServer::getClientId();
1208  ids[1] = 0;
1209  return dis_selective_update_service( itsId, ids );
1210  }
1211  return dis_selective_update_service( itsId, cids );
1212  }
1213  return -1;
1214 }
1215 
1216 int DimService::selectiveUpdateService( char *string, int *cids )
1217 {
1218  if(!itsId)
1219  return 0;
1220  if( itsType == DisSTRING)
1221  {
1222  itsData = string;
1223  itsSize = (int)strlen(string)+1;
1224  if( cids == 0)
1225  {
1226  int ids[2];
1227  ids[0] = DimServer::getClientId();
1228  ids[1] = 0;
1229  return dis_selective_update_service( itsId, ids );
1230  }
1231  return dis_selective_update_service( itsId, cids );
1232  }
1233  return -1;
1234 }
1235 
1236 int DimService::selectiveUpdateService( void *structure, int size, int *cids )
1237 {
1238  if(!itsId)
1239  return 0;
1240  if( itsType == DisPOINTER)
1241  {
1242  itsData = structure;
1243  itsSize = size;
1244  if( cids == 0)
1245  {
1246  int ids[2];
1247  ids[0] = DimServer::getClientId();
1248  ids[1] = 0;
1249  return dis_selective_update_service( itsId, ids );
1250  }
1251  return dis_selective_update_service( itsId, cids );
1252  }
1253  return -1;
1254 }
1255 
1256 void DimService::setQuality(int quality)
1257 {
1258  if(!itsId)
1259  return;
1260  dis_set_quality( itsId, quality );
1261 }
1262 
1263 void DimService::setTimestamp(int secs, int millisecs)
1264 {
1265  if(!itsId)
1266  return;
1267  dis_set_timestamp( itsId, secs, millisecs );
1268 }
1269 
1271 {
1272  storeIt(data, size);
1273 }
1274 
1276 {
1277  storeIt(&data, sizeof(int));
1278 }
1279 
1281 {
1282  storeIt(&data, sizeof(float));
1283 }
1284 
1286 {
1287  storeIt(&data, sizeof(double));
1288 }
1289 
1291 {
1292  storeIt(&data, sizeof(longlong));
1293 }
1294 
1296 {
1297  storeIt(&data, sizeof(short));
1298 }
1299 
1301 {
1302  storeIt(data, (int)strlen(data)+1);
1303 }
1304 
1306 {
1307  return itsName;
1308 }
1309 
1310 int DimService::getTimeout(int clientId)
1311 {
1312  return dis_get_timeout(itsId, clientId);
1313 }
1314 
1316 {
1317  return dis_get_n_clients( itsId );
1318 }
1319 
1320 
1321 CmndInfo::CmndInfo(void *data, int datasize, int tsecs, int tmillisecs)
1322 {
1323  itsData = new char[datasize];
1324  itsDataSize = datasize;
1325  secs = tsecs;
1326  millisecs = tmillisecs;
1327  memcpy(itsData, data, (size_t)datasize);
1328 }
1329 
1331 {
1332  delete[] (char *)itsData;
1333 }
1334 
1335 
1336 DimCommand::DimCommand(const char *name, char *format)
1337 {
1338  declareIt( (char *)name, (char *)format, 0, 0);
1339 }
1340 
1341 DimCommand::DimCommand(const char *name, char *format, DimCommandHandler *handler)
1342 {
1343  declareIt( (char *)name, (char *)format, handler, 0);
1344 }
1345 
1346 DimCommand::DimCommand(DimServerDns *dns, const char *name, char *format)
1347 {
1348  declareIt( (char *)name, (char *)format, 0, dns);
1349 }
1350 
1351 DimCommand::DimCommand(DimServerDns *dns, const char *name, char *format, DimCommandHandler *handler)
1352 {
1353  declareIt( (char *)name, (char *)format, handler, dns);
1354 }
1355 
1356 
1357 DimCommand::DimCommand(const char *name, const char *format)
1358 {
1359  declareIt( (char *)name, (char *)format, 0, 0);
1360 }
1361 
1362 DimCommand::DimCommand(const char *name, const char *format, DimCommandHandler *handler)
1363 {
1364  declareIt( (char *)name, (char *)format, handler, 0);
1365 }
1366 
1367 DimCommand::DimCommand(DimServerDns *dns, const char *name, const char *format)
1368 {
1369  declareIt( (char *)name, (char *)format, 0, dns);
1370 }
1371 
1372 DimCommand::DimCommand(DimServerDns *dns, const char *name, const char *format, DimCommandHandler *handler)
1373 {
1374  declareIt( (char *)name, (char *)format, handler, dns);
1375 }
1376 
1378 {
1379  CmndInfo *cmndptr;
1380  if(currCmnd)
1381  {
1382  delete currCmnd;
1383  currCmnd = 0;
1384  itsData = 0;
1385  itsSize = 0;
1386  }
1387  if ((cmndptr = (CmndInfo *)itsCmndList.removeHead()))
1388  {
1389  currCmnd = cmndptr;
1390  itsData = currCmnd->itsData;
1391  itsSize = currCmnd->itsDataSize;
1392  secs = currCmnd->secs;
1393  millisecs = currCmnd->millisecs;
1394  return(1);
1395  }
1396  return(0);
1397 }
1398 
1400 {
1401  if ((CmndInfo *)itsCmndList.getHead())
1402  {
1403  return(1);
1404  }
1405  return(0);
1406 }
1407 
1409 {
1410  return itsData;
1411 }
1412 
1414 {
1415  return *(int *)itsData;
1416 }
1417 
1419 {
1420  return *(float *)itsData;
1421 }
1422 
1424 {
1425  return *(double *)itsData;
1426 }
1427 
1429 {
1430  return *(longlong *)itsData;
1431 }
1432 
1434 {
1435  return *(short *)itsData;
1436 }
1437 
1439 {
1440  return (char *)itsData;
1441 }
1442 
1444 {
1445  return itsSize;
1446 }
1447 
1449 {
1450  return itsFormat;
1451 }
1452 
1454 {
1455 
1456  if(secs == 0)
1457  {
1458  DISABLE_AST
1459  if(itsId)
1460  dis_get_timestamp(itsId, &secs, &millisecs);
1461  ENABLE_AST
1462  }
1463  return(secs);
1464 }
1465 
1467 {
1468  return(millisecs);
1469 }
1470 
1472 {
1473  CmndInfo *cmndptr;
1474  int tsecs, tmillisecs;
1475 
1476  tsecs = getTimestamp();
1477  tmillisecs = getTimestampMillisecs();
1478  cmndptr = new CmndInfo(getData(), getSize(), tsecs, tmillisecs);
1479  itsCmndList.add(cmndptr);
1480 }
1481 
1483 {
1484  return itsName;
1485 }
1486 
1488 {
1489  DISABLE_AST
1490  delete[] itsName;
1491  delete[] itsFormat;
1492 // if(itsTagId)
1493 // id_free(itsTagId, SRC_DIS);
1494  if(itsId)
1496  itsId = 0;
1497  ENABLE_AST
1498 }
1499 
1501 {
1502 }
1503 
1504 DimRpc::DimRpc(const char *name, const char *formatin, const char *formatout)
1505 {
1506  declareIt( (char *)name, (char *)formatin, (char *)formatout, 0);
1507 }
1508 
1509 DimRpc::DimRpc(DimServerDns *dns, const char *name, const char *formatin, const char *formatout)
1510 {
1511  declareIt( (char *)name, (char *)formatin, (char *)formatout, dns);
1512 }
1513 
1515 {
1516  DISABLE_AST
1517  delete[] itsName;
1518  delete[] itsNameIn;
1519  delete[] itsNameOut;
1520 // if(itsTagId)
1521 // id_free(itsTagId, SRC_DIS);
1522  if(itsIdIn)
1523  dis_remove_service( itsIdIn );
1524  if(itsIdOut)
1525  dis_remove_service( itsIdOut );
1526  itsIdIn = 0;
1527  itsIdOut = 0;
1528  ENABLE_AST
1529 }
1530 
1532 {
1533  return itsDataIn;
1534 }
1535 
1537 {
1538  return *(int *)itsDataIn;
1539 }
1540 
1542 {
1543  return *(float *)itsDataIn;
1544 }
1545 
1547 {
1548  return *(double *)itsDataIn;
1549 }
1550 
1552 {
1553  return *(longlong *)itsDataIn;
1554 }
1555 
1557 {
1558  return *(short *)itsDataIn;
1559 }
1560 
1562 {
1563  return (char *)itsDataIn;
1564 }
1565 
1567 {
1568  return itsSizeIn;
1569 }
1570 
1571 void DimRpc::setData(void *data, int size)
1572 {
1573  storeIt(data,size);
1574 }
1575 
1577 {
1578  storeIt(&data,sizeof(int));
1579 }
1580 
1581 void DimRpc::setData(float &data)
1582 {
1583  storeIt(&data,sizeof(float));
1584 }
1585 
1586 void DimRpc::setData(double &data)
1587 {
1588  storeIt(&data,sizeof(double));
1589 }
1590 
1592 {
1593  storeIt(&data,sizeof(longlong));
1594 }
1595 
1596 void DimRpc::setData(short &data)
1597 {
1598  storeIt(&data,sizeof(short));
1599 }
1600 
1602 {
1603  storeIt(data,(int)strlen(data)+1);
1604 }
1605 
1607 {
1608  return itsName;
1609 }
int isAutoStart()
Definition: discpp.cxx:441
CmndInfo(void *data, int datasize, int tsecs, int tmillisecs)
Definition: discpp.cxx:1321
double getDouble()
Definition: discpp.cxx:1423
void autoStartOn()
Definition: discpp.cxx:431
void clearName()
Definition: discpp.cxx:417
Definition: dns.c:26
Definition: dis.hxx:301
Definition: dis.hxx:24
static char * getClientName()
Definition: discpp.cxx:579
virtual void serviceHandler()
Definition: dis.hxx:220
char * getName()
Definition: discpp.cxx:1606
int getTimestampMillisecs()
Definition: discpp.cxx:1466
#define dis_set_client_exit_handler
Definition: dis.h:16
static int inCallback()
Definition: discpp.cxx:750
virtual void commandHandler()=0
#define dis_remove_service
Definition: dis.h:19
double getDouble()
Definition: discpp.cxx:1546
static void exit_user_routine(int *)
Definition: discpp.cxx:768
void addClientExitHandler()
Definition: discpp.cxx:664
int dis_get_dns_port()
Definition: open_dns.c:139
void init(S &s)
Definition: ByteOrder.h:19
#define dis_selective_update_service
Definition: dis.h:24
int getNTokens()
static void autoStartOff()
Definition: discpp.cxx:566
void autoStartOff()
Definition: discpp.cxx:436
int dis_set_dns_port(int port)
Definition: open_dns.c:114
Definition: dis.hxx:24
static void user_routine(void *tagp, void **buf, int *size, int *first_time)
Definition: discpp.cxx:21
char * getFormat()
Definition: discpp.cxx:1448
dim_long dis_add_dns(char *node_name, int port_number)
Definition: open_dns.c:237
int getTimestamp()
Definition: discpp.cxx:1453
static DimClientExitHandler * itsClientExit
Definition: dis.hxx:95
void dis_init()
Definition: dis.c:220
DisTYPE itsType
Definition: dis.hxx:211
virtual ~DimServer()
Definition: discpp.cxx:454
int ids[10]
void init(const char *node, int port)
Definition: discpp.cxx:344
static void rpcout_routine(void *tagp, void **buf, int *size, int *first_time)
Definition: discpp.cxx:233
longlong getLonglong()
Definition: discpp.cxx:1551
char * itsName
Definition: dis.hxx:227
void setQuality(int quality)
Definition: discpp.cxx:1256
longlong getLonglong()
Definition: discpp.cxx:1428
int itsSizeIn
Definition: dis.hxx:316
char * getName()
Definition: discpp.cxx:1482
int itsTimeout
Definition: dis.hxx:354
static char * dimDnsNode
Definition: dis.hxx:93
DimServer()
Definition: discpp.cxx:446
short getShort()
Definition: discpp.cxx:1433
void * itsData
Definition: dis.hxx:268
static void autoStartOn()
Definition: discpp.cxx:561
char * getString()
Definition: discpp.cxx:1438
float getFloat()
Definition: discpp.cxx:1541
dim_long getDnsId()
Definition: discpp.cxx:403
virtual ~DimRpc()
Definition: discpp.cxx:1514
#define dis_get_timestamp
Definition: dis.h:25
dis_add_service_dns(dnsid, name1,"I",&NewData, sizeof(NewData),(void *) 0, 0)
char id[4]
Definition: FITS.h:71
int itsSizeOut
Definition: dis.hxx:328
static DimExitHandler * itsExit
Definition: dis.hxx:96
int getInt()
Definition: discpp.cxx:1536
static char * clientName
Definition: dis.hxx:91
#define dis_set_timestamp
Definition: dis.h:23
virtual ~DimCommand()
Definition: discpp.cxx:1487
int dis_get_conn_id()
Definition: dis.c:2795
char * getString()
Definition: discpp.cxx:1561
void setTimestamp(int secs, int millisecs)
Definition: discpp.cxx:1263
void dis_add_error_handler(void(*user_routine)())
Definition: dis.c:540
int getInt()
Definition: discpp.cxx:1413
int itsIdOut
Definition: dis.hxx:342
void * getData()
Definition: discpp.cxx:1408
int getSize()
Definition: discpp.cxx:1566
static void setWriteTimeout(int secs)
Definition: discpp.cxx:728
char * dis_get_client_services(int conn_id)
Definition: dis.c:2536
static int inCallback
Definition: dim.hxx:11
static void rpcin_routine(void *tagp, void *buf, int *size)
Definition: discpp.cxx:181
static void stop()
Definition: discpp.cxx:545
int getTimeout(int clientId)
Definition: discpp.cxx:1310
#define dis_add_cmnd
Definition: dis.h:13
int getToken(char *&token)
#define dis_set_quality
Definition: dis.h:22
DimServerDns(const char *node)
Definition: discpp.cxx:326
#define DisDnsIdBlock
Definition: discpp.cxx:342
void storeIt(void *data, int size)
Definition: discpp.cxx:296
static int getWriteTimeout()
Definition: discpp.cxx:733
static int autoStart
Definition: dis.hxx:94
void setData(void *data, int size)
Definition: discpp.cxx:1571
~CmndInfo()
Definition: discpp.cxx:1330
int updateService()
Definition: discpp.cxx:1016
#define dis_start_serving
Definition: dis.h:8
#define dis_update_service
Definition: dis.h:18
DimCommand * itsCommand
Definition: dis.hxx:40
float getFloat()
Definition: discpp.cxx:1418
static void setClientExitHandler(int clientId)
Definition: discpp.cxx:640
long dim_long
Definition: dim_common.h:57
virtual void errorHandler(int severity, int code, char *msg)=0
DimService()
Definition: discpp.cxx:790
static void command_routine(void *tagp, void *buf, int *size)
Definition: discpp.cxx:108
DimCommandHandler * itsCommandHandler
Definition: dis.hxx:248
void dim_set_write_timeout(int secs)
Definition: tcpip.c:141
unsigned dis_add_cmnd_dns(dim_long dnsid, char *name, char *type, void(*user_routine)(), dim_long tag)
Definition: dis.c:510
void setData(void *data, int size)
Definition: discpp.cxx:1270
Warning because the service this data corrsponds to might have been last updated longer ago than Local time
Definition: smartfact.txt:92
#define dis_stop_serving
Definition: dis.h:9
static int setDnsNode(const char *node)
Definition: discpp.cxx:698
void addServiceId(int id)
Definition: discpp.cxx:361
int selectiveUpdateService(int *cids)
Definition: discpp.cxx:1107
Definition: dis.hxx:24
DimRpc()
Definition: discpp.cxx:1500
virtual void serviceHandler()=0
void storeIt(void *data, int size)
Definition: discpp.cxx:83
int dis_get_dns_node(char *node)
Definition: open_dns.c:90
virtual ~DimService()
Definition: discpp.cxx:1001
void addErrorHandler()
Definition: discpp.cxx:744
void setName(const char *name)
Definition: discpp.cxx:408
void * getData()
Definition: discpp.cxx:1531
static DimErrorHandler * itsSrvError
Definition: dis.hxx:97
virtual void clientExitHandler()=0
static dim_long addDns(const char *node, int port)
Definition: discpp.cxx:709
#define dis_get_client
Definition: dis.h:11
static void start()
Definition: discpp.cxx:512
DimService * itsService
Definition: dis.hxx:32
int size
Definition: db_dim_server.c:17
void * itsDataOut
Definition: dis.hxx:326
char * getName()
Definition: discpp.cxx:1305
int getNClients()
Definition: discpp.cxx:1315
float data[4 *1440]
virtual void rpcHandler()=0
int dis_set_dns_node(char *node)
Definition: open_dns.c:65
void declareIt(char *name, char *format, DimCommandHandler *handler, DimServerDns *dns)
Definition: discpp.cxx:136
DimServiceHandler * itsServiceHandler
Definition: dis.hxx:144
int64_t longlong
Definition: dim_common.h:56
#define dis_add_service
Definition: dis.h:12
static char * getDnsNode()
Definition: discpp.cxx:713
static void srv_error_user_routine(int, int, char *)
Definition: discpp.cxx:778
int dis_get_timeout(unsigned service_id, int client_id)
Definition: dis.c:1901
TT t
Definition: test_client.c:26
static void handler(int conn_id, char *packet, int size, int status)
Definition: webServer.c:635
void addExitHandler()
Definition: discpp.cxx:738
int itsDataSize
Definition: dis.hxx:209
#define dis_add_exit_handler
Definition: dis.h:15
#define dis_add_client_exit_handler
Definition: dis.h:14
int secs
Definition: dis.hxx:298
Definition: dis.hxx:24
static char * itsName
Definition: dis.hxx:92
int hasNext()
Definition: discpp.cxx:1399
int dim_get_write_timeout()
Definition: tcpip.c:147
static void clearClientExitHandler(int clientId)
Definition: discpp.cxx:645
int itsSize
Definition: dis.hxx:210
void declareIt(char *name, char *format, DimServiceHandler *handler, DimServerDns *dns)
Definition: discpp.cxx:49
static int getClientId()
Definition: discpp.cxx:571
void * itsDataIn
Definition: dis.hxx:315
int itsId
Definition: dis.hxx:228
static int getDnsPort()
Definition: discpp.cxx:723
void * itsData
Definition: dis.hxx:208
dnsid
Definition: README_v19.txt:372
virtual void exitHandler(int code)=0
virtual void commandHandler()
Definition: discpp.cxx:1471
static void client_exit_user_routine(int *)
Definition: discpp.cxx:758
int * getServiceIdList()
Definition: discpp.cxx:380
int dis_get_n_clients(unsigned service_id)
Definition: dis.c:1865
int getSize()
Definition: discpp.cxx:1443
char * getName()
Definition: discpp.cxx:426
static char ** getClientServices()
Definition: discpp.cxx:601
void dis_stop_serving_dns(dim_long dnsid)
Definition: dis.c:2335
DimServerDns * itsDns
Definition: dis.hxx:232
int itsSize
Definition: dis.hxx:269
int getNext()
Definition: discpp.cxx:1377
dis_start_serving_dns(dnsid,"xx_new")
void declareIt(char *name, char *formatin, char *formatout, DimServerDns *dns)
Definition: discpp.cxx:247
int itsKilled
Definition: dis.hxx:353
short getShort()
Definition: discpp.cxx:1556
DimCommand(const char *name, char *format)
Definition: discpp.cxx:1336