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 | printf("Command received, size = %d, TT size = %d:\n", *size,
|
---|
31 | (int)sizeof(TT));
|
---|
32 | printf("buf->i = %d, buf->d = %2.2f, buf->s = %d, buf->c = %c, buf->f = %2.2f, buf->str = %s\n",
|
---|
33 | buf->i,buf->d,buf->s,buf->c,buf->f,buf->str);
|
---|
34 | }
|
---|
35 |
|
---|
36 | void client_exited(int *tag)
|
---|
37 | {
|
---|
38 | char name[84];
|
---|
39 |
|
---|
40 | if(dis_get_client(name))
|
---|
41 | printf("Client %s (%d) exited\n", name, *tag);
|
---|
42 | else
|
---|
43 | printf("Client %d exited\n", *tag);
|
---|
44 | }
|
---|
45 |
|
---|
46 | void exit_cmnd(int *code)
|
---|
47 | {
|
---|
48 | printf("Exit_cmnd %d\n", *code);
|
---|
49 | exit(*code);
|
---|
50 | }
|
---|
51 |
|
---|
52 | int NewData;
|
---|
53 | int NewIds[11];
|
---|
54 |
|
---|
55 | int main(int argc, char **argv)
|
---|
56 | {
|
---|
57 | int i, id, *ptr;
|
---|
58 | char aux[80];
|
---|
59 | char name[84], name1[132];
|
---|
60 | int on = 0;
|
---|
61 | long dnsid = 0;
|
---|
62 | char extra_dns[128];
|
---|
63 | int new_dns = 0;
|
---|
64 | /*
|
---|
65 | int buf_sz, buf_sz1;
|
---|
66 | */
|
---|
67 | /*
|
---|
68 | dis_set_debug_on();
|
---|
69 | */
|
---|
70 | if(argc){}
|
---|
71 | new_dns = dim_get_env_var("EXTRA_DNS_NODE", extra_dns, sizeof(extra_dns));
|
---|
72 | if(new_dns)
|
---|
73 | dnsid = dis_add_dns(extra_dns,0);
|
---|
74 | /*
|
---|
75 | buf_sz = dim_get_write_buffer_size();
|
---|
76 | dim_set_write_buffer_size(10000000);
|
---|
77 | buf_sz1 = dim_get_write_buffer_size();
|
---|
78 | printf("socket buffer size = %d, after = %d\n",buf_sz, buf_sz1);
|
---|
79 | */
|
---|
80 | dis_add_exit_handler(exit_cmnd);
|
---|
81 | dis_add_client_exit_handler(client_exited);
|
---|
82 |
|
---|
83 | for(i = 0; i< 10; i++)
|
---|
84 | {
|
---|
85 | sprintf(str[i],"%s/Service_%03d",argv[1],i);
|
---|
86 | dis_add_service( str[i], "C", str[i], strlen(str[i])+1,
|
---|
87 | (void *)0, 0 );
|
---|
88 | }
|
---|
89 | t.i = 123;
|
---|
90 | t.j = 456;
|
---|
91 | t.k = 789;
|
---|
92 | t.d = 56.78;
|
---|
93 | t.s = 12;
|
---|
94 | t.t = 12;
|
---|
95 | t.c = 'a';
|
---|
96 | t.f = (float)4.56;
|
---|
97 | ptr = (int *)&t;
|
---|
98 | strcpy(t.str,"hello world");
|
---|
99 |
|
---|
100 | sprintf(aux,"%s/TEST_SWAP",argv[1]);
|
---|
101 | id = dis_add_service( aux, "l:3;d:1;s:1;c:1;s:1;f:1;c:20", &t, sizeof(t),
|
---|
102 | (void *)0, 0 );
|
---|
103 | sprintf(aux,"%s/TEST_CMD",argv[1]);
|
---|
104 | dis_add_cmnd(aux,"l:3;d:1;s:1;c:1;s:1;f:1;c:20",cmnd_rout, 0);
|
---|
105 |
|
---|
106 | /*
|
---|
107 | big_buff[0] = 1;
|
---|
108 | for(i = 0; i < 20; i++)
|
---|
109 | {
|
---|
110 | sprintf(aux,"%s/TestMem_%d",argv[1], i);
|
---|
111 | big_ids[i] = dis_add_service( aux, "I", big_buff, 1024*sizeof(int),
|
---|
112 | (void *)0, 0 );
|
---|
113 | }
|
---|
114 | */
|
---|
115 | dis_start_serving( argv[1] );
|
---|
116 |
|
---|
117 | if(dis_get_client(name))
|
---|
118 | {
|
---|
119 | printf("client %s\n",name);
|
---|
120 | }
|
---|
121 |
|
---|
122 | while(1)
|
---|
123 | {
|
---|
124 | /*
|
---|
125 | for(i = 0; i < 20; i++)
|
---|
126 | {
|
---|
127 | index++;
|
---|
128 | big_buff[0] = index;
|
---|
129 | dis_update_service(big_ids[i]);
|
---|
130 | }
|
---|
131 | sleep(1);
|
---|
132 | */
|
---|
133 | /*
|
---|
134 | pause();
|
---|
135 | */
|
---|
136 | sleep(10);
|
---|
137 |
|
---|
138 | dis_update_service(id);
|
---|
139 |
|
---|
140 | if(new_dns)
|
---|
141 | {
|
---|
142 | if(!on)
|
---|
143 | {
|
---|
144 | printf("Connecting New DNS \n");
|
---|
145 | for(i = 0; i < 10; i++)
|
---|
146 | {
|
---|
147 | sprintf(name1,"NewService%d",i);
|
---|
148 | NewIds[i] = dis_add_service_dns(dnsid, name1, "i", &NewData, sizeof(NewData),
|
---|
149 | (void *)0, 0 );
|
---|
150 | }
|
---|
151 | NewIds[10] = 0;
|
---|
152 | dis_start_serving_dns(dnsid, "xx_new"/*, NewIds*/);
|
---|
153 | on = 1;
|
---|
154 | }
|
---|
155 | else
|
---|
156 | {
|
---|
157 | printf("DisConnecting New DNS \n");
|
---|
158 | for(i = 0; i < 10; i++)
|
---|
159 | {
|
---|
160 | dis_remove_service(NewIds[i]);
|
---|
161 | }
|
---|
162 | on = 0;
|
---|
163 | }
|
---|
164 | }
|
---|
165 |
|
---|
166 | }
|
---|
167 | return 1;
|
---|
168 | }
|
---|
169 |
|
---|