33 #include "BESServiceRegistry.h"
35 #include "BESInternalError.h"
45 BESServiceRegistry::BESServiceRegistry()
49 BESServiceRegistry::~BESServiceRegistry()
61 map<string,map<string,service_cmd> >::iterator i = _services.find( name ) ;
62 if( i == _services.end() )
64 map<string,service_cmd> cmds ;
65 _services[name] = cmds ;
69 string err = (string)
"The service " + name
70 +
" has already been registered" ;
92 const string &cmd_descript,
93 const string &format )
95 map<string,map<string,service_cmd> >::iterator si ;
96 si = _services.find( service ) ;
97 if( si != _services.end() )
99 map<string,service_cmd>::const_iterator ci ;
100 ci = (*si).second.find( cmd ) ;
101 if( ci != (*si).second.end() )
103 string err = (string)
"Attempting to add command "
104 + (*ci).first +
" to the service "
105 + service +
", command alrady exists" ;
109 sc._description = cmd_descript ;
110 sc._formats[format] = format ;
111 (*si).second[cmd] = sc ;
115 string err = (string)
"Attempting to add commands to the service "
116 + service +
" that has not yet been registered" ;
132 const string &format )
134 map<string,map<string,service_cmd> >::iterator si ;
135 si = _services.find( service ) ;
136 if( si != _services.end() )
138 map<string,service_cmd>::iterator ci = (*si).second.find( cmd ) ;
139 if( ci != (*si).second.end() )
141 map<string,string>::iterator fi ;
142 fi = (*ci).second._formats.find( format ) ;
143 if( fi == (*ci).second._formats.end() )
145 (*ci).second._formats[format] = format ;
149 string err = (string)
"Attempting to add format "
150 + format +
" to command " + cmd
151 +
" for service " + service
152 +
" where the format has already been registered" ;
158 string err = (string)
"Attempting to add a format " + format
159 +
" to command " + cmd +
" for service " + service
160 +
" where the command has not been registered" ;
166 string err = (string)
"Attempting to add a format " + format
167 +
" to command " + cmd +
" for a service " + service
168 +
" that has not been registered" ;
184 map<string,map<string,service_cmd> >::iterator i ;
185 i = _services.find( service ) ;
186 if( i != _services.end() )
189 _services.erase( i ) ;
194 map<string,map<string,string> >::iterator hi = _handles.begin() ;
195 map<string,map<string,string> >::iterator he = _handles.end() ;
196 for( ; hi != he; hi++ )
198 map<string,string>::iterator hsi = (*hi).second.find( service ) ;
199 if( hsi != (*hi).second.end() )
201 (*hi).second.erase( hsi ) ;
224 const string &format )
227 map<string,map<string,service_cmd> >::iterator si ;
228 si = _services.find( service ) ;
229 if( si != _services.end() )
233 map<string,service_cmd>::iterator ci = (*si).second.find( cmd ) ;
234 if( ci != (*si).second.end() )
236 if( !format.empty() )
238 map<string,string>::iterator fi ;
239 fi = (*ci).second._formats.find( format ) ;
240 if( fi != (*ci).second._formats.end() )
272 const string &service )
274 map<string,map<string,service_cmd> >::iterator si ;
275 si = _services.find( service ) ;
276 if( si == _services.end() )
278 string err = (string)
"Registering a handler to handle service "
279 + service +
" that has not yet been registered" ;
283 map<string,map<string,string> >::iterator hi = _handles.find( handler ) ;
284 if( hi == _handles.end() )
286 map<string,string> services ;
287 services[service] = service ;
288 _handles[handler] = services ;
292 map<string,string>::iterator ci = (*hi).second.find( service ) ;
293 if( ci == (*hi).second.end() )
295 (*hi).second[service] = service ;
310 const string &service )
312 bool handled = false ;
313 map<string,map<string,string> >::iterator hi = _handles.find( handler ) ;
314 if( hi != _handles.end() )
316 map<string,string>::iterator si = (*hi).second.find( service ) ;
317 if( si != (*hi).second.end() )
335 list<string> &services )
337 map<string,map<string,string> >::iterator hi = _handles.find( handler ) ;
338 if( hi != _handles.end() )
340 map<string,string>::const_iterator si = (*hi).second.begin() ;
341 map<string,string>::const_iterator se = (*hi).second.end() ;
342 for( ; si != se; si++ )
344 services.push_back( (*si).second ) ;
360 map<string,map<string,service_cmd> >::iterator si = _services.begin() ;
361 map<string,map<string,service_cmd> >::iterator se = _services.end() ;
362 for( ; si != se; si++ )
364 map<string,string> props ;
365 props[
"name"] = (*si).first ;
366 info.begin_tag(
"serviceDescription", &props ) ;
367 map<string,service_cmd>::iterator ci = (*si).second.begin() ;
368 map<string,service_cmd>::iterator ce = (*si).second.end() ;
369 for( ; ci != ce; ci++ )
371 map<string,string> cprops ;
372 cprops[
"name"] = (*ci).first ;
373 info.begin_tag(
"command", &cprops ) ;
374 info.add_tag(
"description", (*ci).second._description ) ;
375 map<string,string>::iterator fi = (*ci).second._formats.begin() ;
376 map<string,string>::iterator fe = (*ci).second._formats.end() ;
377 for( ; fi != fe; fi++ )
379 map<string,string> fprops ;
380 fprops[
"name"] = (*fi).first ;
381 info.add_tag(
"format",
"", &fprops ) ;
383 info.end_tag(
"command" ) ;
385 info.end_tag(
"serviceDescription" ) ;
399 strm << BESIndent::LMarg <<
"BESServiceRegistry::dump - ("
400 << (
void *)
this <<
")" << endl ;
401 BESIndent::Indent() ;
402 strm << BESIndent::LMarg <<
"registered services" << endl ;
403 BESIndent::Indent() ;
404 map<string,map<string,service_cmd> >::const_iterator si ;
405 si = _services.begin() ;
406 map<string,map<string,service_cmd> >::const_iterator se ;
407 se = _services.end() ;
408 for( ; si != se; si++ )
410 strm << BESIndent::LMarg << (*si).first << endl ;
411 BESIndent::Indent() ;
412 map<string,service_cmd>::const_iterator ci = (*si).second.begin() ;
413 map<string,service_cmd>::const_iterator ce = (*si).second.end() ;
414 for( ; ci != ce; ci++ )
416 strm << BESIndent::LMarg << (*ci).first << endl ;
417 BESIndent::Indent() ;
418 strm << BESIndent::LMarg <<
"description: "
419 << (*ci).second._description << endl ;
420 strm << BESIndent::LMarg <<
"formats:" << endl ;
421 BESIndent::Indent() ;
422 map<string,string>::const_iterator fi ;
423 fi = (*ci).second._formats.begin() ;
424 map<string,string>::const_iterator fe ;
425 fe = (*ci).second._formats.end() ;
426 for( ; fi != fe; fi++ )
428 strm << BESIndent::LMarg << (*fi).first << endl ;
430 BESIndent::UnIndent() ;
431 BESIndent::UnIndent() ;
433 BESIndent::UnIndent() ;
435 BESIndent::UnIndent() ;
436 strm << BESIndent::LMarg <<
"services provided by handler" << endl ;
437 BESIndent::Indent() ;
438 map<string,map<string,string> >::const_iterator hi = _handles.begin() ;
439 map<string,map<string,string> >::const_iterator he = _handles.end() ;
440 for( ; hi != he; hi++ )
442 strm << BESIndent::LMarg << (*hi).first ;
443 map<string,string>::const_iterator hsi = (*hi).second.begin() ;
444 map<string,string>::const_iterator hse = (*hi).second.end() ;
445 bool isfirst = true ;
446 for( ; hsi != hse; hsi++ )
448 if( !isfirst ) strm <<
", " ;
450 strm << (*hsi).first ;
455 BESIndent::UnIndent() ;
456 BESIndent::UnIndent() ;
460 BESServiceRegistry::TheRegistry()