File indexing completed on 2024-05-12 04:01:52

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_DEVICE_H
0008 #define SOLID_IFACES_DEVICE_H
0009 
0010 #include <QObject>
0011 #include <QVariant>
0012 
0013 #include <QMap>
0014 
0015 #include <solid/device.h>
0016 #include <solid/deviceinterface.h>
0017 #include <solid/solidnamespace.h>
0018 
0019 namespace Solid
0020 {
0021 namespace Ifaces
0022 {
0023 /**
0024  * This class specifies the interface a device will have to comply to in order to be used in the system.
0025  *
0026  * Backends will have to implement it to gather and modify data in the underlying system.
0027  * Each device has a set of key/values pair describing its properties. It has also a list of interfaces
0028  * describing what the device actually is (a cdrom drive, a portable media player, etc.)
0029  *
0030  * @author Kevin Ottens <ervin@kde.org>
0031  */
0032 class Device : public QObject
0033 {
0034     Q_OBJECT
0035 
0036 public:
0037     /**
0038      * Constructs a Device
0039      */
0040     Device(QObject *parent = nullptr);
0041     /**
0042      * Destruct the Device object
0043      */
0044     ~Device() override;
0045 
0046     /**
0047      * Retrieves the Universal Device Identifier (UDI) of the Device.
0048      * This identifier is unique for each device in the system.
0049      *
0050      * @returns the Universal Device Identifier of the current device
0051      */
0052     virtual QString udi() const = 0;
0053 
0054     /**
0055      * Retrieves the Universal Device Identifier (UDI) of the Device's
0056      * parent.
0057      *
0058      * @returns the Universal Device Identifier of the parent device
0059      */
0060     virtual QString parentUdi() const;
0061 
0062     /**
0063      * Retrieves the name of the device vendor.
0064      *
0065      * @return the vendor name
0066      */
0067     virtual QString vendor() const = 0;
0068 
0069     /**
0070      * Retrieves the name of the product corresponding to this device.
0071      *
0072      * @return the product name
0073      */
0074     virtual QString product() const = 0;
0075 
0076     /**
0077      * Retrieves the name of the icon representing this device.
0078      * The naming follows the freedesktop.org specification.
0079      *
0080      * @return the icon name
0081      */
0082     virtual QString icon() const = 0;
0083 
0084     /**
0085      * Retrieves the name of the emblems representing the state of this device.
0086      * The naming follows the freedesktop.org specification.
0087      *
0088      * @return the emblem names
0089      */
0090     virtual QStringList emblems() const = 0;
0091 
0092     /**
0093      * Retrieves the display name to use for this device.
0094      * Same as description when not defined.
0095      *
0096      * @return the display name
0097      * @since 5.71
0098      */
0099     virtual QString displayName() const;
0100 
0101     /**
0102      * Retrieves the description of device.
0103      *
0104      * @return the description
0105      */
0106     virtual QString description() const = 0;
0107 
0108     /**
0109      * Tests if a property exist.
0110      *
0111      * @param type the device interface type
0112      * @returns true if the device interface is provided by this device, false otherwise
0113      */
0114     virtual bool queryDeviceInterface(const Solid::DeviceInterface::Type &type) const = 0;
0115 
0116     /**
0117      * Create a specialized interface to interact with the device corresponding to
0118      * a particular device interface.
0119      *
0120      * @param type the device interface type
0121      * @returns a pointer to the device interface if supported by the device, 0 otherwise
0122      */
0123     virtual QObject *createDeviceInterface(const Solid::DeviceInterface::Type &type) = 0;
0124 
0125     /**
0126      * Register an action for the given device. Each time the same device in another process
0127      * broadcast the begin or the end of such action, the corresponding slots will be called
0128      * in the current process.
0129      *
0130      * @param actionName name of the action to register
0131      * @param dest the object receiving the messages when the action begins and ends
0132      * @param requestSlot the slot processing the message when the action begins
0133      * @param doneSlot the slot processing the message when the action ends
0134      */
0135     void registerAction(const QString &actionName, QObject *dest, const char *requestSlot, const char *doneSlot) const;
0136 
0137     /**
0138      * Allows to broadcast that an action just got requested on a device to all
0139      * the corresponding devices in other processes.
0140      *
0141      * @param actionName name of the action which just completed
0142      */
0143     void broadcastActionRequested(const QString &actionName) const;
0144 
0145     /**
0146      * Allows to broadcast that an action just completed in a device to all
0147      * the corresponding devices in other processes.
0148      *
0149      * @param actionName name of the action which just completed
0150      * @param error error code if the action failed
0151      * @param errorString message describing a potential error
0152      */
0153     void broadcastActionDone(const QString &actionName, int error = Solid::NoError, const QString &errorString = QString()) const;
0154 
0155 private:
0156     QString deviceDBusPath() const;
0157 };
0158 }
0159 }
0160 
0161 #endif