CTK  0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
Public Member Functions | List of all members
ctkServiceFactory Class Referenceabstract

#include <Libs/PluginFramework/ctkServiceFactory.h>

Public Member Functions

virtual QObject * getService (QSharedPointer< ctkPlugin > plugin, ctkServiceRegistration registration)=0
 
virtual void ungetService (QSharedPointer< ctkPlugin > plugin, ctkServiceRegistration registration, QObject *service)=0
 

Detailed Description

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

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

When this happens, the ctkPluginContext::getService(const ctkServiceReference&) method calls the ctkServiceFactory::getService method to create a service object specifically for the requesting plugin. The service object returned by the ctkServiceFactory is cached by the Framework until the plugin releases its use of the service.

When the plugin's use count for the service equals zero (including the plugin stopping or the service being unregistered), the ctkServiceFactory::ungetService method is called.

ctkServiceFactory objects are only used by the Framework and are not made available to other plugins in the plugin environment. The Framework may concurrently call a ctkServiceFactory.

See also
ctkPluginContext::getService
Remarks
This class is thread safe.

Definition at line 59 of file ctkServiceFactory.h.

Member Function Documentation

◆ getService()

virtual QObject* ctkServiceFactory::getService ( QSharedPointer< ctkPlugin plugin,
ctkServiceRegistration  registration 
)
pure virtual

Creates a new service object.

The Framework invokes this method the first time the specified plugin requests a service object using the ctkPluginContext::getService(const ctkServiceReference&) method. The service factory can then return a specific service object for each plugin.

The Framework caches the value returned (unless it is 0), and will return the same service object on any future call to ctkPluginContext::getService for the same plugins. This means the Framework must not allow this method to be concurrently called for the same plugin.

The Framework will check if the returned service object is an instance of all the classes named when the service was registered. If not, then 0 is returned to the plugin.

Parameters
pluginThe plugin using the service.
registrationThe ctkServiceRegistration 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
ctkPluginContext::getService

◆ ungetService()

virtual void ctkServiceFactory::ungetService ( QSharedPointer< ctkPlugin plugin,
ctkServiceRegistration  registration,
QObject *  service 
)
pure virtual

Releases a service object.

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

Parameters
pluginThe ctkPlugin releasing the service.
registrationThe ctkServiceRegistration object for the service.
serviceThe service object returned by a previous call to the ctkServiceFactory::getService method.
See also
ctkPluginContext::ungetService

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