FACT++  1.0
test_client.c
Go to the documentation of this file.
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( int *tag, int *buf, int *size )
29 {
30 
31  if(size){}
32  printf("Received %d for TestMem_%d\n", *buf, *tag);
33 }
34 
35 
36 void got_servers( int *tag, char *list, int *size)
37 {
38  if(tag){}
39  if(size){}
40  printf("%s",list);
41 }
42 
43 void got_services( int *tag, char *list, int *size)
44 {
45  if(tag){}
46  if(size){}
47  printf("%s",list);
48 }
49 /*
50 void rout_list( int *tag, char *buf, int *size )
51 {
52  printf("Received list %d: %s\n",*size, buf);
53 }
54 */
55 
56 void version_rout( int *tag, int *buf, int *size)
57 {
58  if(tag){}
59  printf("Received VERSION %lx, %d\n", (dim_long)buf, *size);
60 }
61 
62 void rout( tag, buf, size )
63 char *buf;
64 int *tag, *size;
65 {
66 /*
67  char *format;
68  format = dic_get_format(0);
69  printf("Received format = %s %08x, %d\n",format, format, *size);
70 */
71  if(*tag == 1100)
72  {
73  printf("Received ONCE_ONLY : %s\n",buff);
74  return;
75  }
76  if(*tag == 1200)
77  {
78  char node[128], str[256];
79  int secs, millis;
80  time_t tsecs;
81 
82  dic_get_dns_node(node);
83  printf("DNS node = %s\n",node);
84  printf("size = %d\n",*size);
85  memcpy(&t, buf, (size_t)*size);
86  printf("t.i = %d, t.d = %2.2f, t.s = %d, t.c = %c, t.f = %2.2f, t.str = %s\n",
87  t.i,t.d,t.s,t.c,t.f,t.str);
88  dic_get_timestamp(0, &secs, &millis);
89  tsecs = secs;
90  my_ctime(&tsecs, str, 128);
91  str[(int)strlen(str)-1] = '\0';
92  printf("timestamp = %s.%d\n",str,millis);
93 
94  return;
95  }
96  else
97  printf("%s Received %s for Service%03d\n",client_str,buf,*tag);
98 
99 /*
100  if(conn_id = dic_get_server(server))
101  printf("received from %d, %s\n",conn_id, server);
102 */
103 
104 }
105 
106 int main(int argc, char **argv)
107 {
108  int i;
109  char aux[80];
110  int id = 123;
111 
112 /*
113  dic_set_debug_on();
114 */
115 /*
116  dic_set_dns_node("pclhcb99.cern.ch");
117 */
118  if(argc){}
119  sprintf(str,"%s/SET_EXIT_HANDLER",argv[2]);
120  dic_cmnd_service(str, &id, 4);
121  dic_get_id(aux);
122  printf("%s\n",aux);
123  strcpy(client_str,argv[1]);
124 
125  for(i = 0; i< 10; i++)
126  {
127  sprintf(str,"%s/Service_%03d",argv[2],i);
128  dic_info_service( str, TIMED, 10, 0, 0, rout, i,
129  "No Link", 8 );
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]);
138  NULL, 0 );
139 /*
140  for(i = 0; i < 20; i++)
141  {
142  sprintf(aux,"%s/TestMem_%d",argv[2], i);
143  dic_info_service( aux, MONITORED, 0, 0, 0, big_rout, i,
144  &no_link, 4 );
145  }
146 */
147 /*
148  sprintf(aux,"DIS_DNS/SERVER_LIST");
149  dic_info_service( aux, MONITORED, 0, 0, 0, rout_list, 0,
150  "DEAD", 5 );
151  sprintf(aux,"%s/SERVICE_LIST",argv[2]);
152  dic_info_service( aux, MONITORED, 0, 0, 0, rout_list, 0,
153  "DEAD", 5 );
154 */
155 /*
156  dic_info_service("DIS_DNS/SERVER_LIST",MONITORED, 0, 0, 0, got_servers, 0,
157  "not there", 10);
158  dic_info_service("xx/SERVICE_LIST",MONITORED, 0, 0, 0, got_services, 0,
159  "not there", 10);
160 */
161  sprintf(aux,"%s/TEST_CMD",argv[2]);
162  while(1)
163  {
164  sleep(10);
165  printf("Sending Command, size = %d, i = %d\n",(int)sizeof(t), t.i);
166  dic_cmnd_service(aux,&t,(int)sizeof(t));
167  }
168  return 1;
169 }
int no_link
Definition: test_client.c:10
#define my_ctime(t, str, size)
Definition: dim_common.h:275
Definition: dns.c:26
char str[20]
Definition: test_client.c:23
unsigned dic_info_service_stamped(char *serv_name, int req_type, int req_timeout, void *serv_address, int serv_size, void(*usr_routine)(), dim_long tag, void *fill_addr, int fill_size)
Definition: dic.c:613
float f
Definition: test_client.c:22
unsigned dic_info_service(char *serv_name, int req_type, int req_timeout, void *serv_address, int serv_size, void(*usr_routine)(), dim_long tag, void *fill_addr, int fill_size)
Definition: dic.c:601
void got_services(int *tag, char *list, int *size)
Definition: test_client.c:43
int dic_get_id(char *name)
Definition: dic.c:2062
int i
Definition: db_dim_client.c:21
char str[80]
Definition: test_client.c:7
#define MONITORED
Definition: dim_common.h:9
Definition: test_client.c:14
short s
Definition: test_client.c:19
float no_link_float
Definition: test_client.c:11
int dic_cmnd_service(char *serv_name, void *serv_address, int serv_size)
Definition: dic.c:694
int dic_get_dns_node(char *node)
Definition: open_dns.c:81
void rout(int *tag, char *buf, int *size)
Definition: test_client.c:62
long dim_long
Definition: dim_common.h:57
void got_servers(int *tag, char *list, int *size)
Definition: test_client.c:36
void version_rout(int *tag, int *buf, int *size)
Definition: test_client.c:56
char c
Definition: test_client.c:20
int i
Definition: test_client.c:15
short t
Definition: test_client.c:21
char str_res[10][80]
Definition: test_client.c:8
int j
Definition: test_client.c:16
int size
Definition: db_dim_server.c:17
int k
Definition: test_client.c:17
char client_str[80]
Definition: test_client.c:9
char buff[80]
Definition: test_client.c:12
double d
Definition: test_client.c:18
TT t
Definition: test_client.c:26
void big_rout(int *tag, int *buf, int *size)
Definition: test_client.c:28
#define TIMED
Definition: dim_common.h:8
sprintf(name1,"NewService%d", i)
int main(int argc, char **argv)
Definition: test_client.c:106
int dic_get_timestamp(unsigned serv_id, int *secs, int *milisecs)
Definition: dic.c:984