33 #include "BESServiceRegistry.h" 35 #include "BESInternalError.h" 39 BESServiceRegistry::BESServiceRegistry()
43 BESServiceRegistry::~BESServiceRegistry()
55 map<string,map<string,service_cmd> >::iterator i = _services.find( name ) ;
56 if( i == _services.end() )
58 map<string,service_cmd> cmds ;
59 _services[name] = cmds ;
63 string err = (string)
"The service " + name
64 +
" has already been registered" ;
86 const string &cmd_descript,
87 const string &format )
89 map<string,map<string,service_cmd> >::iterator si ;
90 si = _services.find( service ) ;
91 if( si != _services.end() )
93 map<string,service_cmd>::const_iterator ci ;
94 ci = (*si).second.find( cmd ) ;
95 if( ci != (*si).second.end() )
97 string err = (string)
"Attempting to add command " 98 + (*ci).first +
" to the service " 99 + service +
", command alrady exists" ;
103 sc._description = cmd_descript ;
104 sc._formats[format] = format ;
105 (*si).second[cmd] = sc ;
109 string err = (string)
"Attempting to add commands to the service " 110 + service +
" that has not yet been registered" ;
126 const string &format )
128 map<string,map<string,service_cmd> >::iterator si ;
129 si = _services.find( service ) ;
130 if( si != _services.end() )
132 map<string,service_cmd>::iterator ci = (*si).second.find( cmd ) ;
133 if( ci != (*si).second.end() )
135 map<string,string>::iterator fi ;
136 fi = (*ci).second._formats.find( format ) ;
137 if( fi == (*ci).second._formats.end() )
139 (*ci).second._formats[format] = format ;
143 string err = (string)
"Attempting to add format " 144 + format +
" to command " + cmd
145 +
" for service " + service
146 +
" where the format has already been registered" ;
152 string err = (string)
"Attempting to add a format " + format
153 +
" to command " + cmd +
" for service " + service
154 +
" where the command has not been registered" ;
160 string err = (string)
"Attempting to add a format " + format
161 +
" to command " + cmd +
" for a service " + service
162 +
" that has not been registered" ;
178 map<string,map<string,service_cmd> >::iterator i ;
179 i = _services.find( service ) ;
180 if( i != _services.end() )
183 _services.erase( i ) ;
188 map<string,map<string,string> >::iterator hi = _handles.begin() ;
189 map<string,map<string,string> >::iterator he = _handles.end() ;
190 for( ; hi != he; hi++ )
192 map<string,string>::iterator hsi = (*hi).second.find( service ) ;
193 if( hsi != (*hi).second.end() )
195 (*hi).second.erase( hsi ) ;
218 const string &format )
221 map<string,map<string,service_cmd> >::iterator si ;
222 si = _services.find( service ) ;
223 if( si != _services.end() )
227 map<string,service_cmd>::iterator ci = (*si).second.find( cmd ) ;
228 if( ci != (*si).second.end() )
230 if( !format.empty() )
232 map<string,string>::iterator fi ;
233 fi = (*ci).second._formats.find( format ) ;
234 if( fi != (*ci).second._formats.end() )
266 const string &service )
268 map<string,map<string,service_cmd> >::iterator si ;
269 si = _services.find( service ) ;
270 if( si == _services.end() )
272 string err = (string)
"Registering a handler to handle service " 273 + service +
" that has not yet been registered" ;
277 map<string,map<string,string> >::iterator hi = _handles.find( handler ) ;
278 if( hi == _handles.end() )
280 map<string,string> services ;
281 services[service] = service ;
282 _handles[handler] = services ;
286 map<string,string>::iterator ci = (*hi).second.find( service ) ;
287 if( ci == (*hi).second.end() )
289 (*hi).second[service] = service ;
304 const string &service )
306 bool handled = false ;
307 map<string,map<string,string> >::iterator hi = _handles.find( handler ) ;
308 if( hi != _handles.end() )
310 map<string,string>::iterator si = (*hi).second.find( service ) ;
311 if( si != (*hi).second.end() )
329 list<string> &services )
331 map<string,map<string,string> >::iterator hi = _handles.find( handler ) ;
332 if( hi != _handles.end() )
334 map<string,string>::const_iterator si = (*hi).second.begin() ;
335 map<string,string>::const_iterator se = (*hi).second.end() ;
336 for( ; si != se; si++ )
338 services.push_back( (*si).second ) ;
354 map<string,map<string,service_cmd> >::iterator si = _services.begin() ;
355 map<string,map<string,service_cmd> >::iterator se = _services.end() ;
356 for( ; si != se; si++ )
358 map<string,string> props ;
359 props[
"name"] = (*si).first ;
360 info.begin_tag(
"serviceDescription", &props ) ;
361 map<string,service_cmd>::iterator ci = (*si).second.begin() ;
362 map<string,service_cmd>::iterator ce = (*si).second.end() ;
363 for( ; ci != ce; ci++ )
365 map<string,string> cprops ;
366 cprops[
"name"] = (*ci).first ;
367 info.begin_tag(
"command", &cprops ) ;
368 info.add_tag(
"description", (*ci).second._description ) ;
369 map<string,string>::iterator fi = (*ci).second._formats.begin() ;
370 map<string,string>::iterator fe = (*ci).second._formats.end() ;
371 for( ; fi != fe; fi++ )
373 map<string,string> fprops ;
374 fprops[
"name"] = (*fi).first ;
375 info.add_tag(
"format",
"", &fprops ) ;
377 info.end_tag(
"command" ) ;
379 info.end_tag(
"serviceDescription" ) ;
393 strm << BESIndent::LMarg <<
"BESServiceRegistry::dump - (" 394 << (
void *)
this <<
")" << endl ;
395 BESIndent::Indent() ;
396 strm << BESIndent::LMarg <<
"registered services" << endl ;
397 BESIndent::Indent() ;
398 map<string,map<string,service_cmd> >::const_iterator si ;
399 si = _services.begin() ;
400 map<string,map<string,service_cmd> >::const_iterator se ;
401 se = _services.end() ;
402 for( ; si != se; si++ )
404 strm << BESIndent::LMarg << (*si).first << endl ;
405 BESIndent::Indent() ;
406 map<string,service_cmd>::const_iterator ci = (*si).second.begin() ;
407 map<string,service_cmd>::const_iterator ce = (*si).second.end() ;
408 for( ; ci != ce; ci++ )
410 strm << BESIndent::LMarg << (*ci).first << endl ;
411 BESIndent::Indent() ;
412 strm << BESIndent::LMarg <<
"description: " 413 << (*ci).second._description << endl ;
414 strm << BESIndent::LMarg <<
"formats:" << endl ;
415 BESIndent::Indent() ;
416 map<string,string>::const_iterator fi ;
417 fi = (*ci).second._formats.begin() ;
418 map<string,string>::const_iterator fe ;
419 fe = (*ci).second._formats.end() ;
420 for( ; fi != fe; fi++ )
422 strm << BESIndent::LMarg << (*fi).first << endl ;
424 BESIndent::UnIndent() ;
425 BESIndent::UnIndent() ;
427 BESIndent::UnIndent() ;
429 BESIndent::UnIndent() ;
430 strm << BESIndent::LMarg <<
"services provided by handler" << endl ;
431 BESIndent::Indent() ;
432 map<string,map<string,string> >::const_iterator hi = _handles.begin() ;
433 map<string,map<string,string> >::const_iterator he = _handles.end() ;
434 for( ; hi != he; hi++ )
436 strm << BESIndent::LMarg << (*hi).first ;
437 map<string,string>::const_iterator hsi = (*hi).second.begin() ;
438 map<string,string>::const_iterator hse = (*hi).second.end() ;
439 bool isfirst = true ;
440 for( ; hsi != hse; hsi++ )
442 if( !isfirst ) strm <<
", " ;
444 strm << (*hsi).first ;
449 BESIndent::UnIndent() ;
450 BESIndent::UnIndent() ;
454 BESServiceRegistry::TheRegistry()
virtual bool does_handle_service(const string &handler, const string &service)
Asks if the specified handler can handle the specified service.
exception thrown if inernal error encountered
virtual void add_service(const string &name)
Add a service to the BES.
The service registry allows modules to register services with the BES that they provide.
virtual void add_to_service(const string &service, const string &cmd, const string &cmd_descript, const string &format)
This function allows callers to add to a service that already exists.
virtual void show_services(BESInfo &info)
fills in the response object for the <showService /> request
virtual void remove_service(const string &name)
remove a service from the BES
informational response object
virtual void add_format(const string &service, const string &cmd, const string &format)
add a format response to a command of a service
virtual void dump(ostream &strm) const
dumps information about this object
virtual bool service_available(const string &name, const string &cmd="", const string &format="")
Determines if a service and, optionally, a command and a return format, is available.
virtual void handles_service(const string &handler, const string &service)
The specified handler can handle the specified service.
virtual void services_handled(const string &handler, list< string > &services)
returns the list of servies provided by the handler in question