source: trunk/FACT++/dim_v19r15/src/examples/test_client.c@ 10305

Last change on this file since 10305 was 10183, checked in by tbretz, 14 years ago
New import.
File size: 2.6 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( tag, buf, size )
52char *buf;
53int *tag, *size;
54{
55
56 if(*tag == 1100)
57 {
58 printf("Received ONCE_ONLY : %s\n",buff);
59 return;
60 }
61 if(*tag == 1200)
62 {
63 char node[128], str[256];
64 int secs, millis;
65 time_t tsecs;
66
67 dic_get_dns_node(node);
68 printf("DNS node = %s\n",node);
69 printf("size = %d\n",*size);
70 memcpy(&t, buf, *size);
71 printf("t.i = %d, t.d = %2.2f, t.s = %d, t.c = %c, t.f = %2.2f, t.str = %s\n",
72 t.i,t.d,t.s,t.c,t.f,t.str);
73 dic_get_timestamp(0, &secs, &millis);
74 tsecs = secs;
75 my_ctime(&tsecs, str, 128);
76 str[strlen(str)-1] = '\0';
77 printf("timestamp = %s.%d\n",str,millis);
78
79 return;
80 }
81 else
82 printf("%s Received %s for Service%03d\n",client_str,buf, *tag);
83
84/*
85 if(conn_id = dic_get_server(server))
86 printf("received from %d, %s\n",conn_id, server);
87*/
88
89}
90
91int main(int argc, char **argv)
92{
93 int i;
94 char aux[80];
95 int id = 123;
96
97/*
98 dic_set_debug_on();
99*/
100/*
101 dic_set_dns_node("pclhcb99.cern.ch");
102*/
103 if(argc){}
104 sprintf(str,"%s/SET_EXIT_HANDLER",argv[2]);
105 dic_cmnd_service(str, &id, 4);
106 dic_get_id(aux);
107 printf("%s\n",aux);
108 strcpy(client_str,argv[1]);
109
110 for(i = 0; i< 10; i++)
111 {
112 sprintf(str,"%s/Service_%03d",argv[2],i);
113 dic_info_service( str, TIMED, 10, 0, 0, rout, i,
114 "No Link", 8 );
115 }
116
117 sprintf(aux,"%s/TEST_SWAP",argv[2]);
118 dic_info_service_stamped( aux, TIMED, 5, 0, 0, rout, 1200,
119 &no_link, 4 );
120
121/*
122 sprintf(aux,"%s/TestMem",argv[2]);
123 dic_info_service( aux, MONITORED, 0, 0, 0, big_rout, 0,
124 &no_link, 4 );
125*/
126
127 sprintf(aux,"%s/TEST_CMD",argv[2]);
128/*
129 dic_info_service("DIS_DNS/SERVER_LIST",MONITORED, 0, 0, 0, got_servers, 0,
130 "not there", 10);
131 dic_info_service("xx/SERVICE_LIST",MONITORED, 0, 0, 0, got_services, 0,
132 "not there", 10);
133*/
134 while(1)
135 {
136 sleep(10);
137
138 printf("Sending Command, size = %d, i = %d\n",(int)sizeof(t), t.i);
139 dic_cmnd_service(aux,&t,(int)sizeof(t));
140 }
141 return 1;
142}
Note: See TracBrowser for help on using the repository browser.