source: trunk/FACT++/dim/src/examples/test_client.c@ 11307

Last change on this file since 11307 was 11121, checked in by tbretz, 13 years ago
Updated from v19r21 to v19r22
File size: 3.0 KB
Line 
1
2#include <dic.h>
3#include <time.h>
4#include <string.h>
5#include <stdio.h>
6
7char str[80];
8char str_res[10][80];
9char client_str[80];
10int no_link = -1;
11float no_link_float = -1.0;
12char buff[80];
13
14typedef struct {
15 int i;
16 int j;
17 int k;
18 double d;
19 short s;
20 char c;
21 short t;
22 float f;
23 char str[20];
24}TT;
25
26TT t;
27/*
28void big_rout( tag, buf, size )
29int *buf;
30int *tag, *size;
31{
32
33 printf("Received %d for TestMem\n", *buf);
34}
35*/
36
37void got_servers( int *tag, char *list, int *size)
38{
39 if(tag){}
40 if(size){}
41 printf("%s",list);
42}
43
44void got_services( int *tag, char *list, int *size)
45{
46 if(tag){}
47 if(size){}
48 printf("%s",list);
49}
50/*
51void rout_list( int *tag, char *buf, int *size )
52{
53 printf("Received list %d: %s\n",*size, buf);
54}
55*/
56
57void version_rout( int *tag, int *buf, int *size)
58{
59 printf("Received VERSION %x, %d\n", buf, *size);
60}
61
62void rout( tag, buf, size )
63char *buf;
64int *tag, *size;
65{
66
67 if(*tag == 1100)
68 {
69 printf("Received ONCE_ONLY : %s\n",buff);
70 return;
71 }
72 if(*tag == 1200)
73 {
74 char node[128], str[256];
75 int secs, millis;
76 time_t tsecs;
77
78 dic_get_dns_node(node);
79 printf("DNS node = %s\n",node);
80 printf("size = %d\n",*size);
81 memcpy(&t, buf, *size);
82 printf("t.i = %d, t.d = %2.2f, t.s = %d, t.c = %c, t.f = %2.2f, t.str = %s\n",
83 t.i,t.d,t.s,t.c,t.f,t.str);
84 dic_get_timestamp(0, &secs, &millis);
85 tsecs = secs;
86 my_ctime(&tsecs, str, 128);
87 str[strlen(str)-1] = '\0';
88 printf("timestamp = %s.%d\n",str,millis);
89
90 return;
91 }
92 else
93 printf("%s Received %s for Service%03d\n",client_str,buf, *tag);
94
95/*
96 if(conn_id = dic_get_server(server))
97 printf("received from %d, %s\n",conn_id, server);
98*/
99
100}
101
102int main(int argc, char **argv)
103{
104 int i;
105 char aux[80];
106 int id = 123;
107
108/*
109 dic_set_debug_on();
110*/
111/*
112 dic_set_dns_node("pclhcb99.cern.ch");
113*/
114 if(argc){}
115 sprintf(str,"%s/SET_EXIT_HANDLER",argv[2]);
116 dic_cmnd_service(str, &id, 4);
117 dic_get_id(aux);
118 printf("%s\n",aux);
119 strcpy(client_str,argv[1]);
120 for(i = 0; i< 10; i++)
121 {
122 sprintf(str,"%s/Service_%03d",argv[2],i);
123 dic_info_service( str, TIMED, 10, 0, 0, rout, i,
124 "No Link", 8 );
125 }
126
127 sprintf(aux,"%s/TEST_SWAP",argv[2]);
128 dic_info_service_stamped( aux, TIMED, 5, 0, 0, rout, 1200,
129 &no_link, 4 );
130
131 sprintf(str,"%s/VERSION_NUMBER",argv[2]);
132 dic_info_service( str, MONITORED, 0, 0, 0, version_rout, 0,
133 NULL, 0 );
134/*
135 sprintf(aux,"%s/TestMem",argv[2]);
136 dic_info_service( aux, MONITORED, 0, 0, 0, big_rout, 0,
137 &no_link, 4 );
138*/
139/*
140 sprintf(aux,"DIS_DNS/SERVER_LIST");
141 dic_info_service( aux, MONITORED, 0, 0, 0, rout_list, 0,
142 "DEAD", 5 );
143 sprintf(aux,"%s/SERVICE_LIST",argv[2]);
144 dic_info_service( aux, MONITORED, 0, 0, 0, rout_list, 0,
145 "DEAD", 5 );
146*/
147/*
148 dic_info_service("DIS_DNS/SERVER_LIST",MONITORED, 0, 0, 0, got_servers, 0,
149 "not there", 10);
150 dic_info_service("xx/SERVICE_LIST",MONITORED, 0, 0, 0, got_services, 0,
151 "not there", 10);
152*/
153 sprintf(aux,"%s/TEST_CMD",argv[2]);
154 while(1)
155 {
156 sleep(10);
157 printf("Sending Command, size = %d, i = %d\n",(int)sizeof(t), t.i);
158 dic_cmnd_service(aux,&t,(int)sizeof(t));
159 }
160 return 1;
161}
Note: See TracBrowser for help on using the repository browser.