QtService  1.1.0
A platform independent library to easily create system services and use some of their features
Public Member Functions | Protected Member Functions | List of all members
QtService::ServicePlugin Class Referenceabstract

The plugin interface to implement as primary interface of a servicebackend plugin. More...

#include <serviceplugin.h>

Public Member Functions

virtual QString currentServiceId () const =0
 Return the ID of the currently setup service.
 
virtual ServiceBackendcreateServiceBackend (const QString &backend, Service *service)=0
 Create a new service backend for the given backend and service. More...
 
virtual ServiceControlcreateServiceControl (const QString &backend, QString &&serviceId, QObject *parent)=0
 Create a new service backend for the given backend, name and parent. More...
 

Protected Member Functions

QPair< QString, QStringdetectNamedService (const QString &serviceId) const
 Check if the given service id is an encoded name and domain, and if yes decode them. More...
 

Detailed Description

The plugin interface to implement as primary interface of a servicebackend plugin.

The plugin that must be implemented to create a Service plugin. The plugins IID is QtService_ServicePlugin_Iid. The plugin most have a json file with the following layout:

{
"Keys" : [ "backend1", "backend2", ... ]
}

Each string in the Keys array is the name of a kind of backend that is provided from that plugin. Most plugins provide only one type of backend, so for most cases you have only 1 element in the list. Please note that the plugin must be able to handle all these providers when passed to it's methods.

For more details on how to implement such a plugin, have a look at: The High-Level API: Writing Qt Extensions

See also
ServiceBackend, ServiceControl, QtService_ServicePlugin_Iid

Definition at line 14 of file serviceplugin.h.

Member Function Documentation

◆ createServiceBackend()

QtService::ServicePlugin::createServiceBackend ( const QString backend,
Service service 
)
pure virtual

Create a new service backend for the given backend and service.

Parameters
backendThe service manager backend to create a service for
serviceThe service instance that will use the backend to run as a service
Returns
A newly created backend instance for the given backend.

This method is only called from the service instance to create the backend used to run the service. This method is called before any Qt-related stuff has been done - so there is not QCoreApplication yet.

See also
Service::exec, ServiceBackend

◆ createServiceControl()

QtService::ServicePlugin::createServiceControl ( const QString backend,
QString &&  serviceId,
QObject parent 
)
pure virtual

Create a new service backend for the given backend, name and parent.

Parameters
backendThe service manager backend to create a control for
serviceIdThe identifier of the service to create the control for
parentThe parent for the control. Should be set as the QObject::parent of the newly created control
Returns
A newly created control instance for the given backend.

This method must be threadsafe

You should always return a valid backend for all valid providers and don't need to perform additional validity checks. It is save to return nullptr in case the store cannot be created. The backends passed to this method are the ones defined in the json file.

Attention
You should always use detectNamedService() in this method to be able to handle controls that are created via ServiceControl::createFromName instead of a service id.
See also
ServiceControl::create, ServiceControl::createFromName, ServiceControl, ServicePlugin::detectNamedService

◆ detectNamedService()

QtService::ServicePlugin::detectNamedService ( const QString serviceId) const
protected

Check if the given service id is an encoded name and domain, and if yes decode them.

This method was only introduced to keep binary compability. For now, it is used to differentiate between a service control created from the service id and one created from a name.

You should call this method at the beginning of createServiceControl(). If the pair is empty, you can assume an actual service id was passed and treat it like that. If the pair however does hold something and thus is not empty, first will be the services name and second the domain. You should then use these two to generate a valid service id and try to create a service control from it.

See also
ServicePlugin::createServiceControl, ServiceControl::createFromName

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