CppMicroServices

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

Allows services to provide customized service objects in the module environment. More...

Public Member Functions

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

Detailed Description

Allows services to provide customized service objects in the module environment.

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
Remarks
This class is thread safe.

Constructor & Destructor Documentation

virtual ServiceFactory::~ServiceFactory ( )
inlinevirtual

Member Function Documentation

virtual us::Base* ServiceFactory::GetService ( Module module,
const ServiceRegistration 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 ServiceReference&) method. The service factory can then return a specific service object for each module.

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

Parameters
moduleThe module using the service.
registrationThe ServiceRegistration object for the service.
Returns
A service object that must be an instance of all the classes named when the service was registered.
See Also
ModuleContext::GetService
virtual void ServiceFactory::UngetService ( Module module,
const ServiceRegistration registration,
us::Base *  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