qdevicediscovery_udev.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/platformsupport/devicediscovery/qdevicediscovery_udev.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6const QLoggingCategory &lcDD() { static const QLoggingCategory category("qt.qpa.input"); return
never executed: return category;
category;
never executed: return category;
}
0
7-
8QDeviceDiscovery *QDeviceDiscovery::create(QDeviceTypes types, QObject *parent)-
9{-
10 for (bool qt_category_enabled = lcDD().isDebugEnabled(); qt_category_enabled
qt_category_enabledDescription
TRUEnever evaluated
FALSEnever evaluated
; qt_category_enabled = false) QMessageLogger(__FILE__, 57, __PRETTY_FUNCTION__, lcDD().categoryName()).debug() << "udev device discovery for type" << types;
never executed: QMessageLogger(__FILE__, 57, __PRETTY_FUNCTION__, lcDD().categoryName()).debug() << "udev device discovery for type" << types;
0
11-
12 QDeviceDiscovery *helper = 0;-
13 struct udev *udev;-
14-
15 udev = udev_new();-
16 if (udev
udevDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
17 helper = new QDeviceDiscoveryUDev(types, udev, parent);-
18 }
never executed: end of block
else {
0
19 QMessageLogger(__FILE__, 66, __PRETTY_FUNCTION__).warning("Failed to get udev library context");-
20 }
never executed: end of block
0
21-
22 return
never executed: return helper;
helper;
never executed: return helper;
0
23}-
24-
25QDeviceDiscoveryUDev::QDeviceDiscoveryUDev(QDeviceTypes types, struct udev *udev, QObject *parent) :-
26 QDeviceDiscovery(types, parent),-
27 m_udev(udev), m_udevMonitor(0), m_udevMonitorFileDescriptor(-1), m_udevSocketNotifier(0)-
28{-
29 if (!m_udev
!m_udevDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
30 return;
never executed: return;
0
31-
32 m_udevMonitor = udev_monitor_new_from_netlink(m_udev, "udev");-
33 if (!m_udevMonitor
!m_udevMonitorDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
34 QMessageLogger(__FILE__, 81, __PRETTY_FUNCTION__).warning("Unable to create an udev monitor. No devices can be detected.");-
35 return;
never executed: return;
0
36 }-
37-
38 udev_monitor_filter_add_match_subsystem_devtype(m_udevMonitor, "input", 0);-
39 udev_monitor_filter_add_match_subsystem_devtype(m_udevMonitor, "drm", 0);-
40 udev_monitor_enable_receiving(m_udevMonitor);-
41 m_udevMonitorFileDescriptor = udev_monitor_get_fd(m_udevMonitor);-
42-
43 m_udevSocketNotifier = new QSocketNotifier(m_udevMonitorFileDescriptor, QSocketNotifier::Read, this);-
44 connect(m_udevSocketNotifier, qFlagLocation("2""activated(int)" "\0" __FILE__ ":" "91"), this, qFlagLocation("1""handleUDevNotification()" "\0" __FILE__ ":" "91"));-
45}
never executed: end of block
0
46-
47QDeviceDiscoveryUDev::~QDeviceDiscoveryUDev()-
48{-
49 if (m_udevMonitor
m_udevMonitorDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
50 udev_monitor_unref(m_udevMonitor);
never executed: udev_monitor_unref(m_udevMonitor);
0
51-
52 if (m_udev
m_udevDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
53 udev_unref(m_udev);
never executed: udev_unref(m_udev);
0
54}
never executed: end of block
0
55-
56QStringList QDeviceDiscoveryUDev::scanConnectedDevices()-
57{-
58 QStringList devices;-
59-
60 if (!m_udev
!m_udevDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
61 return
never executed: return devices;
devices;
never executed: return devices;
0
62-
63 udev_enumerate *ue = udev_enumerate_new(m_udev);-
64 udev_enumerate_add_match_subsystem(ue, "input");-
65 udev_enumerate_add_match_subsystem(ue, "drm");-
66-
67 if (m_types & Device_Mouse
m_types & Device_MouseDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
68 udev_enumerate_add_match_property(ue, "ID_INPUT_MOUSE", "1");
never executed: udev_enumerate_add_match_property(ue, "ID_INPUT_MOUSE", "1");
0
69 if (m_types & Device_Touchpad
m_types & Device_TouchpadDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
70 udev_enumerate_add_match_property(ue, "ID_INPUT_TOUCHPAD", "1");
never executed: udev_enumerate_add_match_property(ue, "ID_INPUT_TOUCHPAD", "1");
0
71 if (m_types & Device_Touchscreen
m_types & Device_TouchscreenDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
72 udev_enumerate_add_match_property(ue, "ID_INPUT_TOUCHSCREEN", "1");
never executed: udev_enumerate_add_match_property(ue, "ID_INPUT_TOUCHSCREEN", "1");
0
73 if (m_types & Device_Keyboard
m_types & Device_KeyboardDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
74 udev_enumerate_add_match_property(ue, "ID_INPUT_KEYBOARD", "1");-
75 udev_enumerate_add_match_property(ue, "ID_INPUT_KEY", "1");-
76 }
never executed: end of block
0
77 if (m_types & Device_Tablet
m_types & Device_TabletDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
78 udev_enumerate_add_match_property(ue, "ID_INPUT_TABLET", "1");
never executed: udev_enumerate_add_match_property(ue, "ID_INPUT_TABLET", "1");
0
79 if (m_types & Device_Joystick
m_types & Device_JoystickDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
80 udev_enumerate_add_match_property(ue, "ID_INPUT_JOYSTICK", "1");
never executed: udev_enumerate_add_match_property(ue, "ID_INPUT_JOYSTICK", "1");
0
81-
82 if (udev_enumerate_scan_devices(ue) != 0
udev_enumerate...vices(ue) != 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
83 QMessageLogger(__FILE__, 130, __PRETTY_FUNCTION__).warning("Failed to scan devices");-
84 return
never executed: return devices;
devices;
never executed: return devices;
0
85 }-
86-
87 udev_list_entry *entry;-
88 for (entry = udev_enumerate_get_list_entry(ue); entry != __null
entry != __nullDescription
TRUEnever evaluated
FALSEnever evaluated
; entry = udev_list_entry_get_next(entry)) {
0
89 const char *syspath = udev_list_entry_get_name(entry);-
90 udev_device *udevice = udev_device_new_from_syspath(m_udev, syspath);-
91 QString candidate = QString::fromUtf8(udev_device_get_devnode(udevice));-
92 if ((
(m_types & Device_InputMask)Description
TRUEnever evaluated
FALSEnever evaluated
m_types & Device_InputMask)
(m_types & Device_InputMask)Description
TRUEnever evaluated
FALSEnever evaluated
&& candidate.startsWith(QLatin1String("/dev/input/" "event"))
candidate.star...ut/" "event"))Description
TRUEnever evaluated
FALSEnever evaluated
)
0
93 devices << candidate;
never executed: devices << candidate;
0
94 if ((
(m_types & Device_VideoMask)Description
TRUEnever evaluated
FALSEnever evaluated
m_types & Device_VideoMask)
(m_types & Device_VideoMask)Description
TRUEnever evaluated
FALSEnever evaluated
&& candidate.startsWith(QLatin1String("/dev/dri/" "card"))
candidate.star...dri/" "card"))Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
95 if (m_types & Device_DRM_PrimaryGPU
m_types & Devi...DRM_PrimaryGPUDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
96 udev_device *pci = udev_device_get_parent_with_subsystem_devtype(udevice, "pci", 0);-
97 if (pci
pciDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
98 if (qstrcmp(udev_device_get_sysattr_value(pci, "boot_vga"), "1") == 0
qstrcmp(udev_d...a"), "1") == 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
99 devices << candidate;
never executed: devices << candidate;
0
100 }
never executed: end of block
0
101 }
never executed: end of block
else
0
102 devices << candidate;
never executed: devices << candidate;
0
103 }-
104-
105 udev_device_unref(udevice);-
106 }
never executed: end of block
0
107 udev_enumerate_unref(ue);-
108-
109 for (bool qt_category_enabled = lcDD().isDebugEnabled(); qt_category_enabled
qt_category_enabledDescription
TRUEnever evaluated
FALSEnever evaluated
; qt_category_enabled = false) QMessageLogger(__FILE__, 156, __PRETTY_FUNCTION__, lcDD().categoryName()).debug() << "Found matching devices" << devices;
never executed: QMessageLogger(__FILE__, 156, __PRETTY_FUNCTION__, lcDD().categoryName()).debug() << "Found matching devices" << devices;
0
110-
111 return
never executed: return devices;
devices;
never executed: return devices;
0
112}-
113-
114void QDeviceDiscoveryUDev::handleUDevNotification()-
115{-
116 if (!m_udevMonitor
!m_udevMonitorDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
117 return;
never executed: return;
0
118-
119 struct udev_device *dev;-
120 QString devNode;-
121-
122 dev = udev_monitor_receive_device(m_udevMonitor);-
123 if (!dev
!devDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
124 goto
never executed: goto cleanup;
cleanup;
never executed: goto cleanup;
0
125-
126 const char *action;-
127 action = udev_device_get_action(dev);-
128 if (!action
!actionDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
129 goto
never executed: goto cleanup;
cleanup;
never executed: goto cleanup;
0
130-
131 const char *str;-
132 str = udev_device_get_devnode(dev);-
133 if (!str
!strDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
134 goto
never executed: goto cleanup;
cleanup;
never executed: goto cleanup;
0
135-
136 const char *subsystem;-
137 devNode = QString::fromUtf8(str);-
138 if (devNode.startsWith(QLatin1String("/dev/input/" "event"))
devNode.starts...ut/" "event"))Description
TRUEnever evaluated
FALSEnever evaluated
)
0
139 subsystem = "input";
never executed: subsystem = "input";
0
140 else if (devNode.startsWith(QLatin1String("/dev/dri/" "card"))
devNode.starts...dri/" "card"))Description
TRUEnever evaluated
FALSEnever evaluated
)
0
141 subsystem = "drm";
never executed: subsystem = "drm";
0
142 else goto
never executed: goto cleanup;
cleanup;
never executed: goto cleanup;
0
143-
144-
145 if (!checkDeviceType(dev)
!checkDeviceType(dev)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
146-
147 struct udev_device *parent_dev = udev_device_get_parent_with_subsystem_devtype(dev, subsystem, 0);-
148 if (!parent_dev
!parent_devDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
149 goto
never executed: goto cleanup;
cleanup;
never executed: goto cleanup;
0
150-
151 if (!checkDeviceType(parent_dev)
!checkDeviceType(parent_dev)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
152 goto
never executed: goto cleanup;
cleanup;
never executed: goto cleanup;
0
153 }
never executed: end of block
0
154-
155 if (qstrcmp(action, "add") == 0
qstrcmp(action, "add") == 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
156 deviceDetected(devNode);
never executed: deviceDetected(devNode);
0
157-
158 if (qstrcmp(action, "remove") == 0
qstrcmp(action, "remove") == 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
159 deviceRemoved(devNode);
never executed: deviceRemoved(devNode);
0
160-
161cleanup:
code before this statement never executed: cleanup:
0
162 udev_device_unref(dev);-
163}
never executed: end of block
0
164-
165bool QDeviceDiscoveryUDev::checkDeviceType(udev_device *dev)-
166{-
167 if (!dev
!devDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
168 return
never executed: return false;
false;
never executed: return false;
0
169-
170 if ((
(m_types & Device_Keyboard)Description
TRUEnever evaluated
FALSEnever evaluated
m_types & Device_Keyboard)
(m_types & Device_Keyboard)Description
TRUEnever evaluated
FALSEnever evaluated
&& (
(qstrcmp(udev_...), "1") == 0 )Description
TRUEnever evaluated
FALSEnever evaluated
qstrcmp(udev_device_get_property_value(dev, "ID_INPUT_KEYBOARD"), "1") == 0 )
(qstrcmp(udev_...), "1") == 0 )Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
171 const QString capabilities_key = QString::fromUtf8(udev_device_get_sysattr_value(dev, "capabilities/key"));-
172 const auto val = capabilities_key.splitRef(QLatin1Char(' '), QString::SkipEmptyParts);-
173 if (!val.isEmpty()
!val.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
174 bool ok;-
175 unsigned long long keys = val.last().toULongLong(&ok, 16);-
176 if (ok
okDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
177-
178 bool test = (keys >> 16) & 1;-
179 if (test
testDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
180 return
never executed: return true;
true;
never executed: return true;
0
181 }
never executed: end of block
0
182 }
never executed: end of block
0
183 }
never executed: end of block
0
184-
185 if ((
(m_types & Device_Keyboard)Description
TRUEnever evaluated
FALSEnever evaluated
m_types & Device_Keyboard)
(m_types & Device_Keyboard)Description
TRUEnever evaluated
FALSEnever evaluated
&& (
(qstrcmp(udev_...), "1") == 0 )Description
TRUEnever evaluated
FALSEnever evaluated
qstrcmp(udev_device_get_property_value(dev, "ID_INPUT_KEY"), "1") == 0 )
(qstrcmp(udev_...), "1") == 0 )Description
TRUEnever evaluated
FALSEnever evaluated
)
0
186 return
never executed: return true;
true;
never executed: return true;
0
187-
188 if ((
(m_types & Device_Mouse)Description
TRUEnever evaluated
FALSEnever evaluated
m_types & Device_Mouse)
(m_types & Device_Mouse)Description
TRUEnever evaluated
FALSEnever evaluated
&& (
(qstrcmp(udev_..."), "1") == 0)Description
TRUEnever evaluated
FALSEnever evaluated
qstrcmp(udev_device_get_property_value(dev, "ID_INPUT_MOUSE"), "1") == 0)
(qstrcmp(udev_..."), "1") == 0)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
189 return
never executed: return true;
true;
never executed: return true;
0
190-
191 if ((
(m_types & Device_Touchpad)Description
TRUEnever evaluated
FALSEnever evaluated
m_types & Device_Touchpad)
(m_types & Device_Touchpad)Description
TRUEnever evaluated
FALSEnever evaluated
&& (
(qstrcmp(udev_..."), "1") == 0)Description
TRUEnever evaluated
FALSEnever evaluated
qstrcmp(udev_device_get_property_value(dev, "ID_INPUT_TOUCHPAD"), "1") == 0)
(qstrcmp(udev_..."), "1") == 0)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
192 return
never executed: return true;
true;
never executed: return true;
0
193-
194 if ((
(m_types & Device_Touchscreen)Description
TRUEnever evaluated
FALSEnever evaluated
m_types & Device_Touchscreen)
(m_types & Device_Touchscreen)Description
TRUEnever evaluated
FALSEnever evaluated
&& (
(qstrcmp(udev_..."), "1") == 0)Description
TRUEnever evaluated
FALSEnever evaluated
qstrcmp(udev_device_get_property_value(dev, "ID_INPUT_TOUCHSCREEN"), "1") == 0)
(qstrcmp(udev_..."), "1") == 0)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
195 return
never executed: return true;
true;
never executed: return true;
0
196-
197 if ((
(m_types & Device_Tablet)Description
TRUEnever evaluated
FALSEnever evaluated
m_types & Device_Tablet)
(m_types & Device_Tablet)Description
TRUEnever evaluated
FALSEnever evaluated
&& (
(qstrcmp(udev_..."), "1") == 0)Description
TRUEnever evaluated
FALSEnever evaluated
qstrcmp(udev_device_get_property_value(dev, "ID_INPUT_TABLET"), "1") == 0)
(qstrcmp(udev_..."), "1") == 0)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
198 return
never executed: return true;
true;
never executed: return true;
0
199-
200 if ((
(m_types & Device_Joystick)Description
TRUEnever evaluated
FALSEnever evaluated
m_types & Device_Joystick)
(m_types & Device_Joystick)Description
TRUEnever evaluated
FALSEnever evaluated
&& (
(qstrcmp(udev_..."), "1") == 0)Description
TRUEnever evaluated
FALSEnever evaluated
qstrcmp(udev_device_get_property_value(dev, "ID_INPUT_JOYSTICK"), "1") == 0)
(qstrcmp(udev_..."), "1") == 0)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
201 return
never executed: return true;
true;
never executed: return true;
0
202-
203 if ((
(m_types & Device_DRM)Description
TRUEnever evaluated
FALSEnever evaluated
m_types & Device_DRM)
(m_types & Device_DRM)Description
TRUEnever evaluated
FALSEnever evaluated
&& (
(qstrcmp(udev_..., "drm") == 0)Description
TRUEnever evaluated
FALSEnever evaluated
qstrcmp(udev_device_get_subsystem(dev), "drm") == 0)
(qstrcmp(udev_..., "drm") == 0)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
204 return
never executed: return true;
true;
never executed: return true;
0
205-
206 return
never executed: return false;
false;
never executed: return false;
0
207}-
208-
209-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9