QIfServiceManager Class

QIfServiceManager provides the backends to QIfAbstractFeature. More...

Header: #include <QIfServiceManager>
qmake: QT += interfaceframework
Instantiated By: ServiceManager
Inherits: QAbstractListModel

Public Types

enum BackendType { ProductionBackend, SimulationBackend }
enum Roles { NameRole, ServiceObjectRole, InterfacesRole }
enum SearchFlag { IncludeProductionBackends, IncludeSimulationBackends, IncludeAll }
flags SearchFlags

Public Functions

QList<QIfServiceObject *> findServiceByInterface(const QString &interface, QIfServiceManager::SearchFlags searchFlags = IncludeAll, const QStringList &preferredBackends = QStringList())
bool hasInterface(const QString &interface) const
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

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

QIfServiceManager::ProductionBackend0A backend controlling a real automotive interface, such as a climate control connected over the CAN bus.
QIfServiceManager::SimulationBackend1A backend used for development, that only returns simulation values and won't be deployed to the final hardware.

enum QIfServiceManager::Roles

QIfServiceManager::NameRoleQt::DisplayRoleThe backend's name, such as MediaPlugin.
QIfServiceManager::ServiceObjectRoleQt::UserRoleThe 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.

QIfServiceManager::InterfacesRoleQt::UserRole +1A list of interfaces that the backend implements.

enum QIfServiceManager::SearchFlag
flags QIfServiceManager::SearchFlags

QIfServiceManager::IncludeProductionBackends0x01Include production backends in the search result.
QIfServiceManager::IncludeSimulationBackends0x02Include simulation backends in the search result.
QIfServiceManager::IncludeAllIncludeProductionBackends | IncludeSimulationBackendsInclude 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.

[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.

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.

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().

© 2023 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.