1 | #include <string.h>
|
---|
2 | #include <stdlib.h>
|
---|
3 | #include <stdio.h>
|
---|
4 | #include <dis.h>
|
---|
5 |
|
---|
6 | char str[10][80];
|
---|
7 |
|
---|
8 | typedef struct {
|
---|
9 | int i;
|
---|
10 | int j;
|
---|
11 | int k;
|
---|
12 | double d;
|
---|
13 | short s;
|
---|
14 | char c;
|
---|
15 | short t;
|
---|
16 | float f;
|
---|
17 | char str[20];
|
---|
18 | }TT;
|
---|
19 |
|
---|
20 | TT t;
|
---|
21 |
|
---|
22 |
|
---|
23 | int big_buff[1024];
|
---|
24 |
|
---|
25 |
|
---|
26 | void cmnd_rout(int *tag, TT *buf, int *size)
|
---|
27 | {
|
---|
28 |
|
---|
29 | if(tag){}
|
---|
30 | dim_print_date_time();
|
---|
31 | printf("Command received, size = %d, TT size = %d:\n", *size,
|
---|
32 | (int)sizeof(TT));
|
---|
33 | printf("buf->i = %d, buf->d = %2.2f, buf->s = %d, buf->c = %c, buf->f = %2.2f, buf->str = %s\n",
|
---|
34 | buf->i,buf->d,buf->s,buf->c,buf->f,buf->str);
|
---|
35 | }
|
---|
36 |
|
---|
37 | void client_exited(int *tag)
|
---|
38 | {
|
---|
39 | char name[84];
|
---|
40 |
|
---|
41 | if(dis_get_client(name))
|
---|
42 | printf("Client %s (%d) exited\n", name, *tag);
|
---|
43 | else
|
---|
44 | printf("Client %d exited\n", *tag);
|
---|
45 | }
|
---|
46 |
|
---|
47 | void exit_cmnd(int *code)
|
---|
48 | {
|
---|
49 | printf("Exit_cmnd %d\n", *code);
|
---|
50 | exit(*code);
|
---|
51 | }
|
---|
52 |
|
---|
53 | int NewData;
|
---|
54 | int NewIds[11];
|
---|
55 |
|
---|
56 | int more_ids[1024];
|
---|
57 | int curr_more_index = 0;
|
---|
58 | char more_str[1024][80];
|
---|
59 |
|
---|
60 | /*
|
---|
61 | int atlas_ids[210];
|
---|
62 | float atlas_arr[10];
|
---|
63 | */
|
---|
64 | int main(int argc, char **argv)
|
---|
65 | {
|
---|
66 | int i, id, *ptr/*, big_ids[20]*/;
|
---|
67 | char aux[80];
|
---|
68 | char name[84]/*, name1[132]*/;
|
---|
69 | /*
|
---|
70 | int on = 0;
|
---|
71 | */
|
---|
72 | long dnsid = 0;
|
---|
73 | char extra_dns[128];
|
---|
74 | int new_dns = 0;
|
---|
75 | int index = 0;
|
---|
76 | /*
|
---|
77 | dim_set_write_timeout(1);
|
---|
78 | */
|
---|
79 | /*
|
---|
80 | int buf_sz, buf_sz1;
|
---|
81 | */
|
---|
82 | /*
|
---|
83 | dis_set_debug_on();
|
---|
84 | */
|
---|
85 | /*
|
---|
86 | int status;
|
---|
87 | regex_t re;
|
---|
88 |
|
---|
89 | if(regcomp(&re, "abc*",REG_EXTENDED|REG_NOSUB) != 0)
|
---|
90 | printf("regcomp error\n");
|
---|
91 | status = regexec(&re,"abcdef", (size_t)0, NULL, 0);
|
---|
92 | regfree(&re);
|
---|
93 | printf("result = %d\n", status);
|
---|
94 | */
|
---|
95 | if(argc){}
|
---|
96 | new_dns = dim_get_env_var("EXTRA_DNS_NODE", extra_dns, sizeof(extra_dns));
|
---|
97 | if(new_dns)
|
---|
98 | dnsid = dis_add_dns(extra_dns,0);
|
---|
99 | /*
|
---|
100 | buf_sz = dim_get_write_buffer_size();
|
---|
101 | dim_set_write_buffer_size(10000000);
|
---|
102 | buf_sz1 = dim_get_write_buffer_size();
|
---|
103 | printf("socket buffer size = %d, after = %d\n",buf_sz, buf_sz1);
|
---|
104 | */
|
---|
105 | dis_add_exit_handler(exit_cmnd);
|
---|
106 | dis_add_client_exit_handler(client_exited);
|
---|
107 |
|
---|
108 | for(i = 0; i< 10; i++)
|
---|
109 | {
|
---|
110 | sprintf(str[i],"%s/Service_%03d",argv[1],i);
|
---|
111 | dis_add_service( str[i], "C", str[i], strlen(str[i])+1,
|
---|
112 | (void *)0, 0 );
|
---|
113 | }
|
---|
114 | t.i = 123;
|
---|
115 | t.j = 456;
|
---|
116 | t.k = 789;
|
---|
117 | t.d = 56.78;
|
---|
118 | t.s = 12;
|
---|
119 | t.t = 12;
|
---|
120 | t.c = 'a';
|
---|
121 | t.f = (float)4.56;
|
---|
122 | ptr = (int *)&t;
|
---|
123 | strcpy(t.str,"hello world");
|
---|
124 |
|
---|
125 | sprintf(aux,"%s/TEST_SWAP",argv[1]);
|
---|
126 | id = dis_add_service( aux, "l:3;d:1;s:1;c:1;s:1;f:1;c:20", &t, sizeof(t),
|
---|
127 | (void *)0, 0 );
|
---|
128 | sprintf(aux,"%s/TEST_CMD",argv[1]);
|
---|
129 | dis_add_cmnd(aux,"l:3;d:1;s:1;c:1;s:1;f:1;c:20",cmnd_rout, 0);
|
---|
130 |
|
---|
131 | /*
|
---|
132 | big_buff[0] = 1;
|
---|
133 | for(i = 0; i < 20; i++)
|
---|
134 | {
|
---|
135 | sprintf(aux,"%s/TestMem_%d",argv[1], i);
|
---|
136 | big_ids[i] = dis_add_service( aux, "I", big_buff, 1024*sizeof(int),
|
---|
137 | (void *)0, 0 );
|
---|
138 | }
|
---|
139 | */
|
---|
140 |
|
---|
141 | /*
|
---|
142 | for(i = 1; i <= 200; i++)
|
---|
143 | {
|
---|
144 | sprintf(aux,"%s/ATLAS_Service%d",argv[1],i);
|
---|
145 | atlas_ids[i] = dis_add_service( aux, "F", atlas_arr, 10*sizeof(float),
|
---|
146 | (void *)0, 0 );
|
---|
147 | }
|
---|
148 | */
|
---|
149 | dis_start_serving( argv[1] );
|
---|
150 |
|
---|
151 | if(dis_get_client(name))
|
---|
152 | {
|
---|
153 | printf("client %s\n",name);
|
---|
154 | }
|
---|
155 | /*
|
---|
156 | for(i = 0; i < 5; i++)
|
---|
157 | {
|
---|
158 | sleep(10);
|
---|
159 |
|
---|
160 | }
|
---|
161 | dis_stop_serving();
|
---|
162 | sleep(59);
|
---|
163 | */
|
---|
164 | while(1)
|
---|
165 | {
|
---|
166 | index++;
|
---|
167 | /*
|
---|
168 | for(i = 0; i < 20; i++)
|
---|
169 | {
|
---|
170 | index++;
|
---|
171 | big_buff[0] = index;
|
---|
172 | dis_update_service(big_ids[i]);
|
---|
173 | }
|
---|
174 | sleep(1);
|
---|
175 | */
|
---|
176 | /*
|
---|
177 | pause();
|
---|
178 | */
|
---|
179 | sleep(10);
|
---|
180 | dis_update_service(id);
|
---|
181 | /*
|
---|
182 | for(i = 1; i <= 200; i++)
|
---|
183 | {
|
---|
184 | dis_update_service(atlas_ids[i]);
|
---|
185 | }
|
---|
186 | */
|
---|
187 | /*
|
---|
188 | if(curr_more_index < 1000)
|
---|
189 | {
|
---|
190 | for(i = 1; i <= 10; i++)
|
---|
191 | {
|
---|
192 | sprintf(more_str[curr_more_index],"%s/More_Service_%03d",argv[1],curr_more_index);
|
---|
193 | more_ids[curr_more_index] = dis_add_service( more_str[curr_more_index], "C",
|
---|
194 | more_str[curr_more_index], strlen(more_str[curr_more_index])+1,
|
---|
195 | (void *)0, 0 );
|
---|
196 | printf("Adding service %s\n",more_str[curr_more_index]);
|
---|
197 | curr_more_index++;
|
---|
198 | dis_start_serving(argv[1]);
|
---|
199 | dis_start_serving(argv[1]);
|
---|
200 | }
|
---|
201 | }
|
---|
202 | */
|
---|
203 | /*
|
---|
204 | if(new_dns)
|
---|
205 | {
|
---|
206 | if(!on)
|
---|
207 | {
|
---|
208 | printf("Connecting New DNS \n");
|
---|
209 | for(i = 0; i < 10; i++)
|
---|
210 | {
|
---|
211 | sprintf(name1,"NewService%d",i);
|
---|
212 | NewIds[i] = dis_add_service_dns(dnsid, name1, "i", &NewData, sizeof(NewData),
|
---|
213 | (void *)0, 0 );
|
---|
214 | }
|
---|
215 | NewIds[10] = 0;
|
---|
216 | dis_start_serving_dns(dnsid, "xx_new");
|
---|
217 | on = 1;
|
---|
218 | }
|
---|
219 | else
|
---|
220 | {
|
---|
221 | printf("DisConnecting New DNS \n");
|
---|
222 | for(i = 0; i < 10; i++)
|
---|
223 | {
|
---|
224 | dis_remove_service(NewIds[i]);
|
---|
225 | }
|
---|
226 | on = 0;
|
---|
227 | }
|
---|
228 | }
|
---|
229 | */
|
---|
230 | }
|
---|
231 | return 1;
|
---|
232 | }
|
---|
233 |
|
---|