File indexing completed on 2025-02-16 05:07:00
0001 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0002 // SPDX-FileCopyrightText: 2020-2021 Harald Sitter <sitter@kde.org> 0003 0004 #ifndef SMARTMONITOR_H 0005 #define SMARTMONITOR_H 0006 0007 #include <QHash> 0008 #include <QObject> 0009 #include <QTimer> 0010 0011 #include <functional> 0012 #include <memory> 0013 0014 class AbstractSMARTCtl; 0015 class Device; 0016 class DeviceNotifier; 0017 0018 class SMARTMonitor : public QObject 0019 { 0020 Q_OBJECT 0021 friend class SMARTMonitorTest; 0022 0023 public: 0024 explicit SMARTMonitor(std::unique_ptr<AbstractSMARTCtl> ctl, std::unique_ptr<DeviceNotifier> deviceNotifier, QObject *parent = nullptr); 0025 void start(); 0026 0027 QList<Device *> devices() const; 0028 0029 Q_SIGNALS: 0030 void deviceAdded(Device *device); 0031 void deviceRemoved(Device *device); 0032 0033 private Q_SLOTS: 0034 void removeUDI(const QString &udi); 0035 void reloadData(); 0036 void onSMARTCtlFinished(const QString &devicePath, const QJsonDocument &document, const QString &textDocument); 0037 0038 private: 0039 void addDevice(Device *device); 0040 0041 QTimer m_reloadTimer; 0042 const std::unique_ptr<AbstractSMARTCtl> m_ctl; 0043 const std::unique_ptr<DeviceNotifier> m_deviceNotifier; 0044 QHash<QString, Device *> m_pendingDevices; // waiting for smartctl to return 0045 QList<Device *> m_devices; // monitored smart devices 0046 }; 0047 0048 #endif // SMARTMONITOR_H