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