API Documentation
Loading...
Searching...
No Matches
DeviceWatcher_p.h
Go to the documentation of this file.
1
2#pragma once
3
4#include <QtCore/qglobal.h>
5#define CONFIG_SOCKETNOTIFIER 1
6#define CONFIG_TCPSOCKET 0 //QtNetwork
7#if defined(Q_OS_WINCE)
8 #define CONFIG_THREAD 1
9#elif defined(Q_OS_LINUX)
10 #define CONFIG_THREAD (!CONFIG_SOCKETNOTIFIER && !CONFIG_TCPSOCKET)
11 #if CONFIG_TCPSOCKET
12 class QTcpSocket;
13 #elif CONFIG_SOCKETNOTIFIER
14 class QSocketNotifier;
15 #endif
16#elif defined Q_OS_MAC //OSX or MACX
17#define CONFIG_THREAD 1
18#include <DiskArbitration/DiskArbitration.h>
19#else
20#define CONFIG_THREAD 0
21#endif
22
23#if CONFIG_DEBUG
24#define zDebug(fmt, ...) qDebug("%s: " #fmt, __FUNCTION__, ##__VA_ARGS__)
25#else
26#define zDebug(fmt, ...)
27#endif //CONFIG_DEBUG
28
29#ifdef Q_OS_WIN
30#include <qt_windows.h>
31#else
32#include <QtCore/QBuffer>
33#endif //Q_OS_WIN
34#include <QtCore/QList>
35#include <QtCore/QThread>
36namespace NDEVR
37{
38 class DeviceWatcher;
41 : public QThread
42#else
43 : public QObject
44#endif //CONFIG_THREAD
45 {
46 Q_OBJECT
47 public:
48 DeviceWatcherPrivate(QObject * parent = 0)
49 :
51 QThread(parent)
52 #else
53 QObject(parent)
54 #endif //CONFIG_THREAD
55 {
56 //init();
57 }
59
60 void setWatcher(DeviceWatcher* w) { watcher = w; }
61 bool start(); //conflict with QThread::start()
62 bool stop();
63
64 //Do not use Qt::DirectConnection. this thread is not watcher's thread!
65 void emitDeviceAdded(const QString& dev);
66 void emitDeviceChanged(const QString& dev); //Linux: when umounting the device
67 void emitDeviceRemoved(const QString& dev);
68 void emitDeviceAction(const QString& dev, const QString& action);
69
70 QList<QObject*> event_receivers;
71
72 private slots:
73 void parseDeviceInfo();
74
75 private:
76 DeviceWatcher* watcher = nullptr;
77
78 bool init();
79 #if CONFIG_THREAD
80 virtual void run();
81 #endif //CONFIG_THREAD
82 #if defined(Q_OS_LINUX)
83 QBuffer buffer;
84 void parseLine(const QByteArray& line);
85 #if CONFIG_TCPSOCKET
86 QTcpSocket* tcp_socket;
87 #elif CONFIG_SOCKETNOTIFIER
88 QSocketNotifier* socket_notifier;
89 #endif
90
91 QString bus_name;
92 int netlink_socket;
93 #elif defined(Q_OS_WIN32)
94 HWND hwnd = NULL;
95 #elif defined(Q_OS_WINCE)
96 HANDLE mQueueHandle;
97 HANDLE mNotificationHandle;
98 #endif
99 #ifdef Q_OS_MAC
100 volatile bool mStop;
101 DASessionRef mSession;
102 #endif //Q_OS_MAC
103 };
104}
#define CONFIG_THREAD
Definition DeviceWatcher_p.h:20
Definition DeviceWatcher.h:9
Definition DeviceWatcher_p.h:45
QList< QObject * > event_receivers
Definition DeviceWatcher_p.h:70
void emitDeviceAction(const QString &dev, const QString &action)
Definition DeviceWatcher.cpp:81
void emitDeviceChanged(const QString &dev)
Definition DeviceWatcher.cpp:69
DeviceWatcherPrivate(QObject *parent=0)
Definition DeviceWatcher_p.h:48
void emitDeviceAdded(const QString &dev)
Definition DeviceWatcher.cpp:63
void setWatcher(DeviceWatcher *w)
Definition DeviceWatcher_p.h:60
void emitDeviceRemoved(const QString &dev)
Definition DeviceWatcher.cpp:75
Definition ACIColor.h:37