FACT++  1.0
test_Browser.cxx
Go to the documentation of this file.
1 #include <iostream>
2 #include <dic.hxx>
3 using namespace std;
4 
5 class ErrorHandler : public DimErrorHandler
6 {
7  void errorHandler(int severity, int code, char *msg)
8  {
9  int index = 0;
10  char **services;
11  cout << severity << " " << msg << endl;
12  services = DimClient::getServerServices();
13  cout<< "from "<< DimClient::getServerName() << " services:" << endl;
14  while(services[index])
15  {
16  cout << services[index] << endl;
17  index++;
18  }
19  }
20 public:
22 };
23 
24 class StrService : public DimInfo
25 {
26 
27  void infoHandler()
28  {
29  int index = 0;
30  char **services;
31 // cout << "Dns Node = " << DimClient::getDnsNode() << endl;
32  cout << "Received STRVAL : " << getString() << endl;
33  services = DimClient::getServerServices();
34  cout<< "from "<< DimClient::getServerName() << " services:" << endl;
35  while(services[index])
36  {
37  cout << services[index] << endl;
38  index++;
39  }
40  }
41 public :
42  StrService() : DimInfo("TEST/STRVAL","not available") {};
43 };
44 
45 
46 void **AllServices;
49 int NBytes;
50 
51 class MyTimer: public DimTimer
52 {
53  void timerHandler()
54  {
55  int i;
56  int missing = 0;
57  for(i = 0; i < NServices; i++)
58  {
59  if(AllServiceStates[i] == -2)
60  {
61  missing++;
62  }
63  }
65  printf("Missing %d, NBytes = %d\n", missing, NBytes);
66  if(missing)
67  start(1);
68  }
69  public:
70  MyTimer(): DimTimer(2){};
71 };
72 
73 class TestGetService: public DimInfo
74 {
75  void infoHandler()
76  {
77  int i, index, size, done = 1;
78  char *dataptr;
79 
80  size = getSize();
81  NBytes += size;
82  dataptr = new char[size];
83  memcpy(dataptr, getData(), size);
84  for(i = 0; i < NServices; i++)
85  {
86  if(AllServices[i] == this)
87  {
88  index = i;
89  break;
90  }
91  }
92  AllServiceStates[index] = getInt();
93  // printf("Got %s, %d, %d\n", getName(), index, AllServiceStates[index]);
94  for(i = 0; i < NServices; i++)
95  {
96  if(AllServiceStates[i] == -2)
97  {
98  done = 0;
99  break;
100  }
101  }
102  if(done)
103  {
105  printf("All Services Received\n");
106  }
107  }
108 public :
109  TestGetService(char *name): DimInfo(name, -1){};
110 };
111 
112 
113 int main(int argc, char **argv)
114 {
115 
116  ErrorHandler errHandler;
117 // StrService servstr;
118  char *server, *ptr, *ptr1;
119  DimBrowser br;
120  int type, n, index, i, ret;
121  MyTimer *myTimer;
122  char findStr[132];
123 
124  ret = 0;
125  strcpy(findStr,"*");
126  if(argc > 1)
127  {
128  if(!strcmp(argv[1],"-f"))
129  {
130  if(argc > 2)
131  strcpy(findStr,argv[2]);
132  else
133  ret = 1;
134  }
135  else
136  ret = 1;
137  if(ret)
138  {
139  printf("Parameters: [-f <search string>]\n");
140  exit(0);
141  }
142  }
143 // DimClient::addErrorHandler(errHandler);
145 printf("Asking %s\n", findStr);
146  n = br.getServices(findStr);
148  cout << "found " << n << " services" << endl;
149 
150  AllServices = (void **) new TestGetService*[n];
151  AllServiceStates = new int[n];
152  NServices = n;
153  NBytes = 0;
154  index = 0;
155  for(i = 0; i < n; i++)
156  AllServiceStates[i] = 0;
157  while((type = br.getNextService(ptr, ptr1))!= 0)
158  {
159 
160  // cout << "type = " << type << " - " << ptr << " " << ptr1 << endl;
161  AllServiceStates[index] = -2;
162  AllServices[index] = new TestGetService(ptr);
163  index++;
164  // if(index >= 1000)
165  // break;
166  }
167  myTimer = new MyTimer();
169  printf("Got Service Names\n");
170  /*
171  br.getServers();
172  while(br.getNextServer(server, ptr1))
173  {
174  cout << server << " @ " << ptr1 << endl;
175  }
176 
177  br.getServerClients("DIS_DNS");
178  while(br.getNextServerClient(ptr, ptr1))
179  {
180  cout << ptr << " @ " << ptr1 << endl;
181  }
182  DimInfo servint("TEST/INTVAL",-1);
183  */
184  while(1)
185  {
186  sleep(10);
187  /*
188  cout << "Current INTVAL : " << servint.getInt() << endl;
189  DimClient::sendCommand("TEST/CMND","UPDATE_STRVAL");
190  */
191  }
192  return 0;
193 }
int start(int initState)
Definition: feeserver.c:1740
int i
Definition: db_dim_client.c:21
int getServices(const char *serviceName)
Definition: diccpp.cxx:849
STL namespace.
Definition: dic.hxx:31
int NBytes
int type
int NServices
TestGetService(char *name)
void addErrorHandler()
Definition: diccpp.cxx:1272
static char * getServerName()
Definition: diccpp.cxx:1296
int * AllServiceStates
void infoHandler()
void ** AllServices
int size
Definition: db_dim_server.c:17
void timerHandler()
void dim_print_date_time()
Definition: utilities.c:134
static char ** getServerServices()
Definition: diccpp.cxx:1319
int main(int argc, char **argv)
int getNextService(char *&service, char *&format)
Definition: diccpp.cxx:948
Definition: dim.hxx:20
void errorHandler(int severity, int code, char *msg)
Definition: test_Browser.cxx:7