FACT++  1.0
int main ( int  argc,
char **  argv 
)

Definition at line 157 of file dimbridge.cxx.

References SLList::add(), bridge_name, BridgeService::clear(), BridgeCommand::clear(), DimCOMMAND, DimSERVICE, BridgeService::find(), BridgeCommand::find(), from_node, DimClient::getDnsNode(), SLList::getHead(), BridgeService::getName(), BridgeCommand::getName(), SLList::getNext(), DimBrowser::getNextService(), DimBrowser::getServices(), print_usage(), SLList::remove(), BridgeService::set(), BridgeCommand::set(), DimServer::setDnsNode(), DimClient::setDnsNode(), sprintf(), to_node, and type.

158 {
159 char services[132];
160 DimBrowser dbr;
161 char *service, *format, *p;
162 int type, known;
163 BridgeService *ptrs, *aux_ptrs;
164 BridgeCommand *ptrc, *aux_ptrc;
165 SLList lists, listc;
166 int rate = 0;
167 int copyFlag = 0;
168 
169 //dic_set_debug_on();
170  if(argc < 3)
171  {
172  print_usage();
173  return 0;
174  }
175  else if( argc == 3)
176  {
177  strcpy(from_node, DimClient::getDnsNode());
178  strcpy(to_node, argv[1]);
179  strcpy(services, argv[2]);
180  }
181  else if (argc == 4)
182  {
183  if(sscanf(argv[3],"%d", &rate))
184  {
185  strcpy(from_node, DimClient::getDnsNode());
186  strcpy(to_node, argv[1]);
187  strcpy(services, argv[2]);
188  }
189  else if(argv[3][0] == '-')
190  {
191  rate = 0;
192  strcpy(from_node, DimClient::getDnsNode());
193  strcpy(to_node, argv[1]);
194  strcpy(services, argv[2]);
195  copyFlag = 1;
196  }
197  else
198  {
199  rate = 0;
200  strcpy(from_node, argv[1]);
201  strcpy(to_node, argv[2]);
202  strcpy(services, argv[3]);
203  }
204  }
205  else if(argc == 5)
206  {
207  if(sscanf(argv[4],"%d", &rate))
208  {
209  strcpy(from_node, argv[1]);
210  strcpy(to_node, argv[2]);
211  strcpy(services, argv[3]);
212  }
213  else if(argv[4][0] == '-')
214  {
215  copyFlag = 1;
216  if(sscanf(argv[3],"%d", &rate))
217  {
218  strcpy(from_node, DimClient::getDnsNode());
219  strcpy(to_node, argv[1]);
220  strcpy(services, argv[2]);
221  }
222  else
223  {
224  rate = 0;
225  strcpy(from_node, argv[1]);
226  strcpy(to_node, argv[2]);
227  strcpy(services, argv[3]);
228  }
229  }
230  }
231  else if(argc == 6)
232  {
233  strcpy(from_node, argv[1]);
234  strcpy(to_node, argv[2]);
235  strcpy(services, argv[3]);
236  sscanf(argv[4],"%d", &rate);
237  copyFlag = 1;
238  }
239  else
240  {
241  cout << "Bad parameters" << endl;
242  return 0;
243  }
244 
245  cout << "Starting DimBridge from "<<from_node<<" to "<<to_node<<" for "<< services;
246  if(rate)
247  cout << " interval=" << rate;
248  if(copyFlag)
249  cout << " (internal data copy)";
250  cout << endl;
251 
252  strcpy(bridge_name,"Bridge_");
253  strcat(bridge_name, from_node);
254  if( (p = strchr(bridge_name,'.')) )
255  *p = '\0';
256 #ifndef WIN32
257  sprintf(p,"_%d",getpid());
258 #else
259  sprintf(p,"_%d",_getpid());
260 #endif
263  while(1)
264  {
265  ptrs = (BridgeService *)lists.getHead();
266  while(ptrs)
267  {
268  ptrs->clear();
269  ptrs = (BridgeService *)lists.getNext();
270  }
271  ptrc = (BridgeCommand *)listc.getHead();
272  while(ptrc)
273  {
274  ptrc->clear();
275  ptrc = (BridgeCommand *)listc.getNext();
276  }
277  dbr.getServices(services);
278  while( (type = dbr.getNextService(service, format)) )
279  {
280  known = 0;
281  ptrs = (BridgeService *)lists.getHead();
282  while(ptrs)
283  {
284  if(!strcmp(ptrs->getName(), service))
285  {
286  known = 1;
287  ptrs->set();
288  break;
289  }
290  ptrs = (BridgeService *)lists.getNext();
291  }
292  ptrc = (BridgeCommand *)listc.getHead();
293  while(ptrc)
294  {
295  if(!strcmp(ptrc->getName(), service))
296  {
297  known = 1;
298  ptrc->set();
299  break;
300  }
301  ptrc = (BridgeCommand *)listc.getNext();
302  }
303  if(strstr(service,"DIS_DNS"))
304  known = 1;
305  if(!known)
306  {
307  if(type == DimSERVICE)
308  {
309  if(!rate)
310  ptrs = new BridgeService(service, format, copyFlag);
311  else
312  ptrs = new BridgeService(service, format, rate, copyFlag);
313  lists.add(ptrs);
314  }
315  else if (type == DimCOMMAND)
316  {
317 // DimClient::setDnsNode(to_node);
318  ptrc = new BridgeCommand(service, format);
319  listc.add(ptrc);
320 // DimClient::setDnsNode(from_node);
321  }
322  }
323  }
324  ptrs = (BridgeService *)lists.getHead();
325  while(ptrs)
326  {
327  aux_ptrs = 0;
328  if(!ptrs->find())
329  {
330  lists.remove(ptrs);
331  aux_ptrs = ptrs;
332  }
333  ptrs = (BridgeService *)lists.getNext();
334  if(aux_ptrs)
335  {
336  delete aux_ptrs;
337  }
338  }
339  ptrc = (BridgeCommand *)listc.getHead();
340  while(ptrc)
341  {
342  aux_ptrc = 0;
343  if(!ptrc->find())
344  {
345  listc.remove(ptrc);
346  aux_ptrc = ptrc;
347  }
348  ptrc = (BridgeCommand *)listc.getNext();
349  if(aux_ptrc)
350  {
351  delete aux_ptrc;
352  }
353  }
354  sleep(5);
355  }
356  return 1;
357 }
static char from_node[64]
Definition: dimbridge.cxx:8
static char to_node[64]
Definition: dimbridge.cxx:8
static char * getDnsNode()
Definition: diccpp.cxx:1221
int getServices(const char *serviceName)
Definition: diccpp.cxx:849
void print_usage()
Definition: dimbridge.cxx:147
void add(SLLItem *itemptr)
Definition: sllist.hxx:29
int type
static int setDnsNode(const char *node)
Definition: diccpp.cxx:1206
static char bridge_name[64]
Definition: dimbridge.cxx:8
char * getName()
Definition: dimbridge.cxx:140
static int setDnsNode(const char *node)
Definition: discpp.cxx:698
SLLItem * getHead()
Definition: sllist.hxx:40
SLLItem * getNext()
Definition: sllist.hxx:45
sprintf(name1,"NewService%d", i)
void remove(SLLItem *itemptr)
Definition: sllist.hxx:68
int getNextService(char *&service, char *&format)
Definition: diccpp.cxx:948
char * getName()
Definition: dimbridge.cxx:106

+ Here is the call graph for this function: