C++ Micro Services: ServiceFactory Class Reference
ServiceFactory Class Referenceabstract

A factory for module scope services. More...

Inheritance diagram for ServiceFactory:

Public Member Functions

virtual ~ServiceFactory ()
 
virtual InterfaceMap GetService (Module *module, const ServiceRegistrationBase &registration)=0
 Creates a new service object. More...
 
virtual void UngetService (Module *module, const ServiceRegistrationBase &registration, const InterfaceMap &service)=0
 Releases a service object. More...
 

Detailed Description

A factory for module scope services.

The factory can provide service objects unique to each module.

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

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

When the module's use count for the service equals zero (including the module unloading 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 modules in the module environment. The framework may concurrently call a ServiceFactory.

See Also
ModuleContext::GetService
PrototypeServiceFactory
Remarks
This class is thread safe.

Constructor & Destructor Documentation

virtual ServiceFactory::~ServiceFactory ( )
inlinevirtual

Member Function Documentation

virtual InterfaceMap ServiceFactory::GetService ( Module module,
const ServiceRegistrationBase registration 
)
pure virtual

Creates a new service object.

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

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

Parameters
moduleThe module using the service.
registrationThe ServiceRegistrationBase object for the service.
Returns
A service object that must contain entries for all the interfaces named when the service was registered.
See Also
ModuleContext::GetService
InterfaceMap

Implemented in PrototypeServiceFactory.

virtual void ServiceFactory::UngetService ( Module module,
const ServiceRegistrationBase registration,
const InterfaceMap service 
)
pure virtual

Releases a service object.

The framework invokes this method when a service has been released by a module. The service object may then be destroyed.

Parameters
moduleThe Module releasing the service.
registrationThe ServiceRegistration object for the service.
serviceThe service object returned by a previous call to the ServiceFactory::GetService method.
See Also
ModuleContext::UngetService
InterfaceMap

Implemented in PrototypeServiceFactory.