File indexing completed on 2024-04-14 05:41:27

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     bool nativeEventFilter(const QByteArray &theEventType, void *theMessage, qintptr *theResult) override;
0034 
0035 protected:
0036     // Closes handles and frees resources
0037     void cleanup();
0038 
0039 signals:
0040     // Emitted when device change notification arrives
0041     void deviceChanged();
0042 
0043 public slots:
0044     // Initializes monitoring for USB devices
0045     bool startMonitoring();
0046 };
0047 
0048 #endif // USBDEVICEMONITOR_H