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
ctkManagedServiceFactory Struct Referenceabstract

#include <Libs/PluginFramework/service/cm/ctkManagedServiceFactory.h>

Public Member Functions

virtual void deleted (const QString &pid)=0
 
virtual QString getName ()=0
 
virtual void updated (const QString &pid, const ctkDictionary &properties)=0
 
virtual ~ctkManagedServiceFactory ()
 

Detailed Description

Manage multiple service instances.

Plugins registering this interface are giving the Configuration Admin service the ability to create and configure a number of instances of a service that the implementing plugin can provide. For example, a plugin implementing a DHCP server could be instantiated multiple times for different interfaces using a factory.

Each of these service instances is represented, in the persistent storage of the Configuration Admin service, by a factory ctkConfiguration object that has a PID. When such a ctkConfiguration is updated, the Configuration Admin service calls the ctkManagedServiceFactory updated method with the new properties. When updated is called with a new PID, the Managed Service Factory should create a new factory instance based on these configuration properties. When called with a PID that it has seen before, it should update that existing service instance with the new configuration information.

In general it is expected that the implementation of this interface will maintain a data structure that maps PIDs to the factory instances that it has created. The semantics of a factory instance are defined by the Managed Service Factory. However, if the factory instance is registered as a service object with the service registry, its PID should match the PID of the corresponding ctkConfiguration object (but it should not be registered as a Managed Service!).

An example that demonstrates the use of a factory. It will create serial ports under command of the Configuration Admin service.

class SerialPortFactory : public QObject, public ctkManagedServiceFactory
{
ctkServiceRegistration registration;
void start(ctkPluginContext* context)
{
ctkDictionary properties;
"com.acme.serialportfactory");
registration = context->registerService<ctkManagedServiceFactory>(
this, properties);
}
public:
void updated(const QString& pid, const ctkDictionary& properties)
{
QString portName = properties["port"].toString();
SerialPort* port = ports[pid];
if (port == 0)
{
port = new SerialPort();
ports.insert(pid, port);
port->open();
}
if (port->getPortName() == portName)
return;
port->setPortName(portName);
}
void deleted(const QString& pid)
{
SerialPort* port = ports[pid];
port->close();
ports.remove(pid);
}
...
};
ctkServiceRegistration registerService(const QStringList &clazzes, QObject *service, const ctkDictionary &properties=ctkDictionary())
virtual void updated(const QString &pid, const ctkDictionary &properties)=0
virtual void deleted(const QString &pid)=0
static const QString SERVICE_PID

Definition at line 109 of file ctkManagedServiceFactory.h.

Constructor & Destructor Documentation

◆ ~ctkManagedServiceFactory()

virtual ctkManagedServiceFactory::~ctkManagedServiceFactory ( )
inlinevirtual

Definition at line 111 of file ctkManagedServiceFactory.h.

Member Function Documentation

◆ deleted()

virtual void ctkManagedServiceFactory::deleted ( const QString &  pid)
pure virtual

Remove a factory instance.

Remove the factory instance associated with the PID. If the instance was registered with the service registry, it should be unregistered.

If this method throws any exception, the Configuration Admin service must catch it and should log it.

The Configuration Admin service must call this method asynchronously.

Parameters
pidthe PID of the service to be removed

◆ getName()

virtual QString ctkManagedServiceFactory::getName ( )
pure virtual

Return a descriptive name of this factory.

Returns
the name for the factory, which might be localized

◆ updated()

virtual void ctkManagedServiceFactory::updated ( const QString &  pid,
const ctkDictionary properties 
)
pure virtual

Create a new instance, or update the configuration of an existing instance.

If the PID of the ctkConfiguration object is new for the Managed Service Factory, then create a new factory instance, using the configuration properties provided. Else, update the service instance with the provided properties.

If the factory instance is registered with the Framework, then the configuration properties should be copied to its registry properties. This is not mandatory and security sensitive properties should obviously not be copied.

If this method throws any exception, the Configuration Admin service must catch it and should log it.

When the implementation of updated detects any kind of error in the configuration properties, it should create a new ctkConfigurationException which describes the problem.

The Configuration Admin service must call this method asynchronously. This implies that implementors of the ctkManagedServiceFactory class can be assured that the callback will not take place during registration when they execute the registration in a synchronized method.

Parameters
pidThe PID for this configuration.
propertiesA copy of the configuration properties. This argument must not contain the service.pluginLocation" property. The value of this property may be obtained from the ctkConfiguration::getPluginLocation method.
Exceptions
ctkConfigurationExceptionwhen the configuration properties are invalid.

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