File indexing completed on 2022-09-27 16:29:37

0001 /*
0002     SPDX-FileCopyrightText: 2016 ROSA
0003     SPDX-License-Identifier: GPL-3.0-or-later
0004 */
0005 
0006 #ifndef USBDEVICEMONITOR_H
0007 #define USBDEVICEMONITOR_H
0008 
0009 ////////////////////////////////////////////////////////////////////////////////
0010 // Class implementing monitoring for inserting/removing USB devices
0011 
0012 
0013 #include <QObject>
0014 #include <QAbstractNativeEventFilter>
0015 #include <QSocketNotifier>
0016 
0017 #include "common.h"
0018 
0019 class UsbDeviceMonitorPrivate;
0020 class UsbDeviceMonitor : public QObject, public QAbstractNativeEventFilter
0021 {
0022     Q_OBJECT
0023     Q_DISABLE_COPY_MOVE(UsbDeviceMonitor)
0024 
0025 protected:
0026     UsbDeviceMonitorPrivate* const d_ptr;
0027 
0028 public:
0029     explicit UsbDeviceMonitor(QObject *parent = 0);
0030     ~UsbDeviceMonitor();
0031     
0032     // Implements QAbstractNativeEventFilter interface for processing WM_DEVICECHANGE messages (Windows)
0033 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
0034     bool nativeEventFilter(const QByteArray &theEventType, void *theMessage, long * theResult) override;
0035 #else
0036     bool nativeEventFilter(const QByteArray &theEventType, void *theMessage, qintptr *theResult) override;
0037 #endif
0038 
0039 protected:
0040     // Closes handles and frees resources
0041     void cleanup();
0042 
0043 signals:
0044     // Emitted when device change notification arrives
0045     void deviceChanged();
0046 
0047 public slots:
0048     // Initializes monitoring for USB devices
0049     bool startMonitoring();
0050 };
0051 
0052 #endif // USBDEVICEMONITOR_H