QIfServiceManager Class
QIfServiceManager provides the backends to QIfAbstractFeature. More...
Header: | #include <QIfServiceManager> |
qmake: | QT += interfaceframework |
In QML: | ServiceManager |
Inherits: | QAbstractListModel |
Public Types
enum | BackendType { ProductionBackend, SimulationBackend } |
enum | Roles { NameRole, ServiceObjectRole, InterfacesRole, ServiceObjectHandleRole } |
enum | SearchFlag { IncludeProductionBackends, IncludeSimulationBackends, IncludeAll } |
flags | SearchFlags |
Public Functions
QList<QIfServiceObject *> | findServiceByInterface(const QString &interface, QIfServiceManager::SearchFlags searchFlags = IncludeAll, const QStringList &preferredBackends = QStringList()) |
(since 6.8) QList<QIfServiceObjectHandle> | findServiceHandleByInterface(const QString &interface, QIfServiceManager::SearchFlags searchFlags = IncludeAll, const QStringList &preferredBackends = QStringList()) |
bool | hasInterface(const QString &interface) const |
(since 6.8) void | loadServiceObject(QIfServiceObjectHandle handle, bool async = false) |
bool | registerService(QObject *serviceBackendInterface, const QStringList &interfaces, QIfServiceManager::BackendType backendType = ProductionBackend) |
Reimplemented Public Functions
virtual QVariant | data(const QModelIndex &index, int role) const override |
virtual QHash<int, QByteArray> | roleNames() const override |
virtual int | rowCount(const QModelIndex &parent = QModelIndex()) const override |
Signals
(since 6.8) void | serviceObjectLoaded(QIfServiceObjectHandle handle) |
Static Public Members
QIfServiceManager * | instance() |
Detailed Description
QIfServiceManager is the heart of QtInterfaceFramework and provides you with an easy way to detect which backends and interfaces are available.
By default, QIfServiceManager reads the metaData of all plugins within the interfaceframework folder in your plugin path. The plugin itself is loaded when you request for it explicitly, using findServiceByInterface().
The manager can distinguish between Production and Simulation backends, using the filename or the metaData.
Simulation Backends can set the simulation
key in their plugin metadata to true
or use one of two supported plugin postfixes (_simulation, _simulator) in the plugin filename.
The registerService() function can be used to add Backend classes without putting them into a plugin.
The service manager is a process-wide singleton and can be accessed through the instance method.
If you require more detailed information on which plugins are recognized, make sure you enable the qt.if.servicemanagement
logging category.
For more information on how backends are loaded, see Dynamic Backend System.
Note: The QIfServiceManager only accepts plugins that match the build configuration used for building qtinterfaceframework. This means a qtinterfaceframework "release" build won't accept plugins from a "debug" build.
Member Type Documentation
enum QIfServiceManager::BackendType
Constant | Value | Description |
---|---|---|
QIfServiceManager::ProductionBackend | 0 | A backend controlling a real automotive interface, such as a climate control connected over the CAN bus. |
QIfServiceManager::SimulationBackend | 1 | A backend used for development, that only returns simulation values and won't be deployed to the final hardware. |
enum QIfServiceManager::Roles
Constant | Value | Description |
---|---|---|
QIfServiceManager::NameRole | Qt::DisplayRole | The backend's name, such as MediaPlugin. |
QIfServiceManager::ServiceObjectRole | Qt::UserRole | The actual QIfServiceObject, which can be used to connect a frontend API to this backend. |
Note: When using this role in the data() function, the backend plugin is loaded and instantiated. Since 6.8 you can use the ServiceObjectHandleRole to have more control over loading the backend.
Constant | Value | Description |
---|---|---|
QIfServiceManager::InterfacesRole | 257 | A list of interfaces that the backend implements. |
QIfServiceManager::ServiceObjectHandleRole | 258 | The handle to the backend, which can be used to load the backend asynchronously. |
enum QIfServiceManager::SearchFlag
flags QIfServiceManager::SearchFlags
Constant | Value | Description |
---|---|---|
QIfServiceManager::IncludeProductionBackends | 0x01 | Include production backends in the search result. |
QIfServiceManager::IncludeSimulationBackends | 0x02 | Include simulation backends in the search result. |
QIfServiceManager::IncludeAll | IncludeProductionBackends | IncludeSimulationBackends | Include both production and simulation backends in the search result. |
The SearchFlags type is a typedef for QFlags<SearchFlag>. It stores an OR combination of SearchFlag values.
See also ProductionBackend and SimulationBackend.
Member Function Documentation
[override virtual]
QVariant QIfServiceManager::data(const QModelIndex &index, int role) const
Reimplements: QAbstractItemModel::data(const QModelIndex &index, int role) const.
Returns the data for the index and role specified.
See also QAbstractListModel::data().
[invokable]
QList<QIfServiceObject *> QIfServiceManager::findServiceByInterface(const QString &interface, QIfServiceManager::SearchFlags searchFlags = IncludeAll, const QStringList &preferredBackends = QStringList())
Returns a list of backends implementing the specified interface.
The searchFlags argument can be used to control which type of backends are included in the search result.
The preferredBackends argument is used to select a backend when multiple backends implement the specified interface. The wildcards are applied in order to the found backends. If the wildcard matches some backends those backends will be loaded, otherwise the next wildcard is used.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
See also findServiceHandleByInterface().
[invokable, since 6.8]
QList<QIfServiceObjectHandle> QIfServiceManager::findServiceHandleByInterface(const QString &interface, QIfServiceManager::SearchFlags searchFlags = IncludeAll, const QStringList &preferredBackends = QStringList())
Returns a list of backend handles implementing the specified interface, which can be used to load the backend asynchronously using the loadServiceObject() function.
The searchFlags argument can be used to control which type of backends are included in the search result.
The preferredBackends argument is used to select a backend when multiple backends implement the specified interface. The wildcards are applied in order to the found backends. If the wildcard matches some backends those backends will be returned, otherwise the next wildcard is used.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
This function was introduced in Qt 6.8.
See also findServiceByInterface() and loadServiceObject().
[invokable]
bool QIfServiceManager::hasInterface(const QString &interface) const
Returns true
if the specified interface has been registered.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
[static]
QIfServiceManager *QIfServiceManager::instance()
Returns the global service manager instance.
[invokable, since 6.8]
void QIfServiceManager::loadServiceObject(QIfServiceObjectHandle handle, bool async = false)
Loads the backend specified by the handle. If async is true
, the backend is loaded asynchronously.
Emits serviceObjectLoaded() once the backend is loaded successfully or an error occurred.
Note: The signal is always emitted, even if the backend is already loaded or could not be loaded at all.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
This function was introduced in Qt 6.8.
bool QIfServiceManager::registerService(QObject *serviceBackendInterface, const QStringList &interfaces, QIfServiceManager::BackendType backendType = ProductionBackend)
Registers a backend. The serviceBackendInterface specified must implement the QIfServiceInterface, otherwise the registration will fail. interfaces is a list of at least one interface, supported by the backend. The backendType indicates the type of the backend and influences whether the backend can be found by the Feature's auto discovery option.
The ownership of serviceBackendInterface is transferred to the QIfServiceManager.
Returns true
if the backend was successfully registered; otherwise false
.
See also QIfServiceInterface.
[override virtual]
QHash<int, QByteArray> QIfServiceManager::roleNames() const
Reimplements: QAbstractItemModel::roleNames() const.
[override virtual]
int QIfServiceManager::rowCount(const QModelIndex &parent = QModelIndex()) const
Reimplements: QAbstractItemModel::rowCount(const QModelIndex &parent) const.
Returns the number of rows for the given parent. Typically parent is an empty model index.
See also QAbstractListModel::data().
[signal, since 6.8]
void QIfServiceManager::serviceObjectLoaded(QIfServiceObjectHandle handle)
This signal is emitted when a backend identified by handle is loaded successfully or an error occurred as a result of calling loadServiceObject().
This function was introduced in Qt 6.8.
© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.