ServiceObjects

template <class S>
class cppmicroservices::ServiceObjects
#include <cppmicroservices/ServiceObjects.h>

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 bundle 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 bundles associated with the BundleContext used to create this ServiceObjects object is stopped.

Template Parameters
  • S: Type of Service.

Inherits from cppmicroservices::ServiceObjectsBase

Public Functions

ServiceObjects(ServiceObjects const &other)
ServiceObjects &operator=(ServiceObjects const &other)
ServiceObjects(ServiceObjects &&other)
ServiceObjects &operator=(ServiceObjects &&other)
std::shared_ptr<S> GetService() const

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 bundle scope, this method behaves the same as calling the BundleContext::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(const Bundle&, 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.

Return
A shared_ptr to the service object. The returned shared_ptr is empty 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

ServiceReference<S> GetServiceReference() const

Returns the ServiceReference for this ServiceObjects object.

Return
The ServiceReference for this ServiceObjects object.

template <>
template<>
class cppmicroservices::ServiceObjects<void>
#include <cppmicroservices/ServiceObjects.h>

Allows multiple service objects for a service to be obtained.

This is a specialization of the ServiceObjects class template for void, which maps to all service interface types.

See
ServiceObjects

Inherits from cppmicroservices::ServiceObjectsBase

Public Functions

ServiceObjects(ServiceObjects const &other)
ServiceObjects &operator=(ServiceObjects const &other)
ServiceObjects(ServiceObjects &&other)
ServiceObjects &operator=(ServiceObjects &&other)
InterfaceMapConstPtr GetService() const

Returns a service object as a InterfaceMap instance for the referenced service.

This method is the same as ServiceObjects<S>::GetService() except for the return type. Further, this method will always return an empty InterfaceMap object when the referenced service has been unregistered.

Return
A InterfaceMapConstPtr object for the referenced service, which is empty if the service is not registered, the InterfaceMap returned by a ServiceFactory does not contain all the classes under which the service object was registered or the ServiceFactory threw an exception.
See
ServiceObjects<S>::GetService()
Exceptions

ServiceReferenceU GetServiceReference() const

Returns the ServiceReference for this ServiceObjects object.

Return
The ServiceReference for this ServiceObjects object.