1 /* 2 SPDX-FileCopyrightText: 2006 Michaël Larouche <michael.larouche@kdemail.net> 3 4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 5 */ 6 7 #ifndef SOLID_BACKENDS_FAKEHW_FAKEMANAGER_H 8 #define SOLID_BACKENDS_FAKEHW_FAKEMANAGER_H 9 10 #include <solid/devices/ifaces/devicemanager.h> 11 12 class QDomElement; 13 14 using namespace Solid::Ifaces; 15 16 namespace Solid 17 { 18 namespace Backends 19 { 20 namespace Fake 21 { 22 class FakeDevice; 23 24 /** 25 * @brief a Fake manager that read a device list from a XML file. 26 * This fake manager is used for unit tests and developers. 27 * 28 * @author Michaël Larouche <michael.larouche@kdemail.net> 29 */ 30 class FakeManager : public Solid::Ifaces::DeviceManager 31 { 32 Q_OBJECT 33 public: 34 FakeManager(QObject *parent, const QString &xmlFile); 35 ~FakeManager() override; 36 37 QString udiPrefix() const override; 38 QSet<Solid::DeviceInterface::Type> supportedInterfaces() const override; 39 40 /** 41 * Return the list of UDI of all available devices. 42 */ 43 QStringList allDevices() override; 44 45 QStringList devicesFromQuery(const QString &parentUdi, Solid::DeviceInterface::Type type) override; 46 47 QObject *createDevice(const QString &udi) override; 48 virtual FakeDevice *findDevice(const QString &udi); 49 50 public Q_SLOTS: 51 void plug(const QString &udi); 52 void unplug(const QString &udi); 53 54 private Q_SLOTS: 55 /** 56 * @internal 57 * Parse the XML file that represent the fake machine. 58 */ 59 void parseMachineFile(); 60 /** 61 * @internal 62 * Parse a device node and the return the device. 63 */ 64 FakeDevice *parseDeviceElement(const QDomElement &element); 65 66 private: 67 QStringList findDeviceStringMatch(const QString &key, const QString &value); 68 QStringList findDeviceByDeviceInterface(Solid::DeviceInterface::Type type); 69 70 class Private; 71 Private *d; 72 }; 73 } 74 } 75 } 76 77 #endif // SOLID_BACKENDS_FAKEHW_FAKEMANAGER_H 78