File indexing completed on 2024-05-19 04:03:20

0001 /*
0002     SPDX-FileCopyrightText: 2005 Kevin Ottens <ervin@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #ifndef SOLID_IFACES_DEVICEMANAGER_H
0008 #define SOLID_IFACES_DEVICEMANAGER_H
0009 
0010 #include <QObject>
0011 
0012 #include <QStringList>
0013 
0014 #include <solid/deviceinterface.h>
0015 
0016 namespace Solid
0017 {
0018 namespace Ifaces
0019 {
0020 /**
0021  * This class specifies the interface a backend will have to implement in
0022  * order to be used in the system.
0023  *
0024  * A device manager allows to query the underlying platform to discover the
0025  * available devices. It has also the responsibility to notify when a device
0026  * appears or disappears.
0027  */
0028 class DeviceManager : public QObject
0029 {
0030     Q_OBJECT
0031 
0032 public:
0033     /**
0034      * Constructs a DeviceManager
0035      */
0036     DeviceManager(QObject *parent = nullptr);
0037     /**
0038      * Destructs a DeviceManager object
0039      */
0040     ~DeviceManager() override;
0041 
0042     /**
0043      * Retrieves the prefix used for the UDIs off all the devices
0044      * reported by the device manager
0045      */
0046     virtual QString udiPrefix() const = 0;
0047 
0048     /**
0049      * Retrieves a set of interfaces the backend supports
0050      */
0051     virtual QSet<Solid::DeviceInterface::Type> supportedInterfaces() const = 0;
0052 
0053     /**
0054      * Retrieves the Universal Device Identifier (UDI) of all the devices
0055      * available in the system. This identifier is unique for each device
0056      * in the system.
0057      *
0058      * @returns the UDIs of all the devices in the system
0059      */
0060     virtual QStringList allDevices() = 0;
0061 
0062     /**
0063      * Retrieves the Universal Device Identifier (UDI) of all the devices
0064      * matching the given constraints (parent and device interface)
0065      *
0066      * @param parentUdi UDI of the parent of the devices we're searching for, or QString()
0067      * if there's no constraint on the parent
0068      * @param type DeviceInterface type available on the devices we're looking for, or DeviceInterface::Unknown
0069      * if there's no constraint on the device interfaces
0070      * @returns the UDIs of all the devices having the given parent and device interface
0071      */
0072     virtual QStringList devicesFromQuery(const QString &parentUdi, Solid::DeviceInterface::Type type = Solid::DeviceInterface::Unknown) = 0;
0073 
0074     /**
0075      * Instantiates a new Device object from this backend given its UDI.
0076      *
0077      * @param udi the identifier of the device instantiated
0078      * @returns a new Device object if there's a device having the given UDI, 0 otherwise
0079      */
0080     virtual QObject *createDevice(const QString &udi) = 0;
0081 
0082 Q_SIGNALS:
0083     /**
0084      * This signal is emitted when a new device appears in the system.
0085      *
0086      * @param udi the new device identifier
0087      */
0088     void deviceAdded(const QString &udi);
0089 
0090     /**
0091      * This signal is emitted when a device disappears from the system.
0092      *
0093      * @param udi the old device identifier
0094      */
0095     void deviceRemoved(const QString &udi);
0096 };
0097 }
0098 }
0099 
0100 #endif