Medical Imaging Interaction Toolkit  2024.06.99-60d9b802
Medical Imaging Interaction Toolkit
us::ServiceObjects< S > Class Template Reference

#include <usServiceObjects.h>

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

Public Member Functions

S * GetService () const
 
void UngetService (S *service)
 
ServiceReference< S > GetServiceReference () const
 

Detailed Description

template<class S>
class us::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.

Definition at line 86 of file usServiceObjects.h.

Member Function Documentation

◆ GetService()

template<class S >
S* us::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 nullptr 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, nullptr 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, nullptr is returned and a warning message is issued.
  4. The service object is returned.
Returns
A service object for the referenced service or nullptr 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()

Definition at line 127 of file usServiceObjects.h.

◆ GetServiceReference()

template<class S >
ServiceReference<S> us::ServiceObjects< S >::GetServiceReference ( ) const
inline

Returns the ServiceReference for this ServiceObjects object.

Returns
The ServiceReference for this ServiceObjects object.

Definition at line 173 of file usServiceObjects.h.

◆ UngetService()

template<class S >
void us::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()

Definition at line 163 of file usServiceObjects.h.


The documentation for this class was generated from the following file: