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

0001 /*
0002     SPDX-FileCopyrightText: 2006-2007 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_GENERICINTERFACE_H
0008 #define SOLID_GENERICINTERFACE_H
0009 
0010 #include <QMap>
0011 #include <QVariant>
0012 
0013 #include <solid/deviceinterface.h>
0014 #include <solid/solid_export.h>
0015 
0016 namespace Solid
0017 {
0018 class GenericInterfacePrivate;
0019 class Device;
0020 
0021 /**
0022  * @class Solid::GenericInterface genericinterface.h <Solid/GenericInterface>
0023  *
0024  * Generic interface to deal with a device. It exposes a set of properties
0025  * and is organized as a key/value set.
0026  *
0027  * Warning: Using this class could expose some backend specific details
0028  * and lead to non portable code. Use it at your own risk, or during
0029  * transitional phases when the provided device interfaces don't
0030  * provide the necessary methods.
0031  */
0032 class SOLID_EXPORT GenericInterface : public DeviceInterface
0033 {
0034     Q_OBJECT
0035     Q_DECLARE_PRIVATE(GenericInterface)
0036     friend class Device;
0037 
0038 public:
0039     /**
0040      * This enum type defines the type of change that can occur to a GenericInterface
0041      * property.
0042      *
0043      * - PropertyModified : A property value has changed in the device
0044      * - PropertyAdded : A new property has been added to the device
0045      * - PropertyRemoved : A property has been removed from the device
0046      */
0047     enum PropertyChange {
0048         PropertyModified,
0049         PropertyAdded,
0050         PropertyRemoved,
0051     };
0052     Q_ENUM(PropertyChange)
0053 
0054 private:
0055     /**
0056      * Creates a new GenericInterface object.
0057      * You generally won't need this. It's created when necessary using
0058      * Device::as().
0059      *
0060      * @param backendObject the device interface object provided by the backend
0061      * @see Solid::Device::as()
0062      */
0063     SOLID_NO_EXPORT explicit GenericInterface(QObject *backendObject);
0064 
0065 public:
0066     /**
0067      * Destroys a Processor object.
0068      */
0069     ~GenericInterface() override;
0070 
0071     /**
0072      * Get the Solid::DeviceInterface::Type of the GenericInterface device interface.
0073      *
0074      * @return the Processor device interface type
0075      * @see Solid::Ifaces::Enums::DeviceInterface::Type
0076      */
0077     static Type deviceInterfaceType()
0078     {
0079         return DeviceInterface::GenericInterface;
0080     }
0081 
0082     /**
0083      * Retrieves a property of the device.
0084      *
0085      * Warning: Using this method could expose some backend specific details
0086      * and lead to non portable code. Use it at your own risk, or during
0087      * transitional phases when the provided device interfaces don't
0088      * provide the necessary methods.
0089      *
0090      * @param key the property key
0091      * @return the actual value of the property, or QVariant() if the
0092      * property is unknown
0093      */
0094     QVariant property(const QString &key) const;
0095 
0096     /**
0097      * Retrieves a key/value map of all the known properties for the device.
0098      *
0099      * Warning: Using this method could expose some backend specific details
0100      * and lead to non portable code. Use it at your own risk, or during
0101      * transitional phases when the provided device interfaces don't
0102      * provide the necessary methods.
0103      *
0104      * @return all the properties of the device
0105      */
0106     QMap<QString, QVariant> allProperties() const;
0107 
0108     /**
0109      * Tests if a property exist in the device.
0110      *
0111      * Warning: Using this method could expose some backend specific details
0112      * and lead to non portable code. Use it at your own risk, or during
0113      * transitional phases when the provided device interfaces don't
0114      * provide the necessary methods.
0115      *
0116      * @param key the property key
0117      * @return true if the property is available in the device, false
0118      * otherwise
0119      */
0120     bool propertyExists(const QString &key) const;
0121 
0122 Q_SIGNALS:
0123     /**
0124      * This signal is emitted when a property is changed in the device.
0125      *
0126      * @param changes the map describing the property changes that
0127      * occurred in the device, keys are property name and values
0128      * describe the kind of change done on the device property
0129      * (added/removed/modified), it's one of the type Solid::Device::PropertyChange
0130      */
0131     void propertyChanged(const QMap<QString, int> &changes);
0132 
0133     /**
0134      * This signal is emitted when an event occurred in the device.
0135      * For example when a button is pressed.
0136      *
0137      * @param condition the condition name
0138      * @param reason a message explaining why the condition has been raised
0139      */
0140     void conditionRaised(const QString &condition, const QString &reason);
0141 };
0142 }
0143 
0144 #endif