CppMicroServices

C++ Micro Services: ServiceObjects< S > Class Template Reference
ServiceObjects< S > Class Template Reference

Allows multiple service objects for a service to be obtained. More...

Inheritance diagram for ServiceObjects< S >:
Collaboration diagram for ServiceObjects< S >:

Public Member Functions

S * GetService () const
 Returns a service object for the referenced service. More...
 
void UngetService (S *service)
 Releases a service object for the referenced service. More...
 
ServiceReference< S > GetServiceReference () const
 Returns the ServiceReference for this ServiceObjects object. More...
 

Detailed Description

template<class S>
class ServiceObjects< S >

Allows multiple service objects for a service to be obtained.

For services with prototype scope, multiple service objects for the service can be obtained. For services with singleton or module scope, only one, use-counted service object is available. Any unreleased service objects obtained from this ServiceObjects object are automatically released by the framework when the modules associated with the ModuleContext used to create this ServiceObjects object is stopped.

Template Parameters
SType of Service.

Member Function Documentation

template<class S >
S* ServiceObjects< S >::GetService ( ) const
inline

Returns a service object for the referenced service.

This ServiceObjects object can be used to obtain multiple service objects for the referenced service if the service has prototype scope. If the referenced service has singleton or module scope, this method behaves the same as calling the ModuleContext::GetService(const ServiceReferenceBase&) method for the referenced service. That is, only one, use-counted service object is available from this ServiceObjects object.

This method will always return NULL when the referenced service has been unregistered.

For a prototype scope service, the following steps are taken to get the service object:

  1. If the referenced service has been unregistered, NULL is returned.
  2. The PrototypeServiceFactory::GetService(Module*, const ServiceRegistrationBase&) method is called to create a service object for the caller.
  3. If the service object (an instance of InterfaceMap) returned by the PrototypeServiceFactory object is empty, does not contain all the interfaces named when the service was registered or the PrototypeServiceFactory object throws an exception, NULL is returned and a warning message is issued.
  4. The service object is returned.
Returns
A service object for the referenced service or NULL if the service is not registered, the service object returned by a ServiceFactory does not contain all the classes under which it was registered or the ServiceFactory threw an exception.
Exceptions
std::logic_errorIf the ModuleContext used to create this ServiceObjects object is no longer valid.
See Also
UngetService()
template<class S >
ServiceReference<S> ServiceObjects< S >::GetServiceReference ( ) const
inline

Returns the ServiceReference for this ServiceObjects object.

Returns
The ServiceReference for this ServiceObjects object.
template<class S >
void ServiceObjects< S >::UngetService ( S *  service)
inline

Releases a service object for the referenced service.

This ServiceObjects object can be used to obtain multiple service objects for the referenced service if the service has prototype scope. If the referenced service has singleton or module scope, this method behaves the same as calling the ModuleContext::UngetService(const ServiceReferenceBase&) method for the referenced service. That is, only one, use-counted service object is available from this ServiceObjects object.

For a prototype scope service, the following steps are take to release the service object:

  1. If the referenced service has been unregistered, this method returns without doing anything.
  2. The PrototypeServiceFactory::UngetService(Module*, const ServiceRegistrationBase&, const InterfaceMap&) method is called to release the specified service object.
  3. The specified service object must no longer be used and all references to it should be destroyed after calling this method.
Parameters
serviceA service object previously provided by this ServiceObjects object.
Exceptions
std::logic_errorIf the ModuleContext used to create this ServiceObjects object is no longer valid.
std::invalid_argumentIf the specified service was not provided by this ServiceObjects object.
See Also
GetService()