class cppmicroservices::ServiceFactory

A factory for bundle scope services.

The factory can provide service objects unique to each bundle.

When registering a service, a ServiceFactory object can be used instead of a service object, so that the bundle developer can gain control of the specific service object granted to a bundle that is using the service.

When this happens, the BundleContext::GetService(const ServiceReference&) method calls the ServiceFactory::GetService method to create a service object specifically for the requesting bundle. The service object returned by the ServiceFactory is cached by the framework until the bundle releases its use of the service.

When the bundle’s use count for the service equals zero (including the bundle stopping or the service being unregistered), the ServiceFactory::UngetService method is called.

ServiceFactory objects are only used by the framework and are not made available to other bundles in the bundle environment. The framework may concurrently call a ServiceFactory.




This class is thread safe.

Subclassed by cppmicroservices::PrototypeServiceFactory

Public Functions

virtual ~ServiceFactory()
virtual InterfaceMapConstPtr GetService(const Bundle &bundle, const ServiceRegistrationBase &registration) = 0

Creates a new service object.

The Framework invokes this method the first time the specified bundle requests a service object using the BundleContext::GetService(const ServiceReferenceBase&) method. The service factory can then return a specific service object for each bundle.

The framework caches the value returned (unless the InterfaceMap is empty), and will return the same service object on any future call to BundleContext::GetService for the same bundles. This means the framework does not allow this method to be concurrently called for the same bundle.

A service object that must contain entries for all the interfaces named when the service was registered.




virtual void UngetService(const Bundle &bundle, const ServiceRegistrationBase &registration, const InterfaceMapConstPtr &service) = 0

Releases a service object.

The framework invokes this method when a service has been released by a bundle.