1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
|
/* This file is part of the TDE libraries
Copyright (C) 2012-2014 Timothy Pearson <[email protected]>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef _TDEHARDWAREDEVICES_H
#define _TDEHARDWAREDEVICES_H
// TDE includes
#include <tqobject.h>
#include <tqptrlist.h>
#include <tqmap.h>
#include <tqdict.h>
#include <tqstring.h>
#include <tqstringlist.h>
#include "tdelibs_export.h"
#include "kicontheme.h"
#include "tdehwcommontypes.h"
// FIXME delete those headers after complete fixing everything in over modules
#include "tdegenericdevice.h"
#include "kiconloader.h"
extern "C" {
#include <libudev.h>
}
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <unistd.h>
#include "tdestoragedevice.h"
#include "tdecpudevice.h"
#include "tdebatterydevice.h"
#include "tdemainspowerdevice.h"
#include "tdenetworkdevice.h"
#include "tdebacklightdevice.h"
#include "tdemonitordevice.h"
#include "tdesensordevice.h"
#include "tderootsystemdevice.h"
#include "tdeeventdevice.h"
#include "tdeinputdevice.h"
/**
* Hardware Device Access and Monitoring Library
*
* @author Timothy Pearson
*/
struct udev_device;
class KSimpleDirWatch;
class TDEGenericDevice;
class TDEStorageDevice;
class TDENetworkDevice;
class TDEBacklightDevice;
class TDEMonitorDevice;
class TDESensorDevice;
class TDERootSystemDevice;
class TDEEventDevice;
class TDEInputDevice;
class TQSocketNotifier;
typedef TQPtrList<TDEGenericDevice> TDEGenericHardwareList;
typedef TQMap<TQString, TQString> TDEDeviceIDMap;
typedef TQDict<TDECPUDevice> TDECPUDeviceCache;
class TDECORE_EXPORT TDEHardwareDevices : public TQObject
{
Q_OBJECT
public:
/**
* Constructor.
*/
TDEHardwareDevices();
/**
* Destructor.
*/
~TDEHardwareDevices();
/**
* Query all hardware capabilities on all devices
* This does not normally need to be called by an application, as
* device detection is handled internally and automatically
*
* A call to this method immediately invalidates any TDEGenericHardwareList
* structures returned by listAllPhysicalDevices()
*
* @return TRUE if successful
*/
bool queryHardwareInformation();
/**
* List all hardware capabilities on all devices
* @return TDEGenericHardwareList containing all known hardware devices
*/
TDEGenericHardwareList listAllPhysicalDevices();
/**
* List all hardware capabilities on all devices
* @param a TDEGenericDeviceType::TDEGenericDeviceType specifying the device class
* @return TDEGenericHardwareList containing all known hardware devices
*/
TDEGenericHardwareList listByDeviceClass(TDEGenericDeviceType::TDEGenericDeviceType cl);
/**
* Return the device with system path @arg syspath, or 0 if no device exists for that path
* @return TDEGenericDevice
*/
TDEGenericDevice* findBySystemPath(TQString syspath);
/**
* Return the device with unique ID @arg uid, or 0 if no device exists for that uid
* @return TDEGenericDevice
*/
TDEGenericDevice* findByUniqueID(TQString uid);
/**
* Return the device with device node @arg devnode, or 0 if no device exists at that node
* @return TDEGenericDevice
*/
TDEGenericDevice* findByDeviceNode(TQString devnode);
/**
* Return the storage device with unique ID @arg uid, or 0 if no device exists for that uid
* @return TDEGenericDevice
*/
TDEStorageDevice* findDiskByUID(TQString uid);
/**
* Return the CPU device with system path @arg syspath, or 0 if no device exists for that path
* @return TDEGenericDevice
*/
TDECPUDevice* findCPUBySystemPath(TQString syspath, bool inCache);
/**
* Look up the device in the system PCI database
* @param vendorid a TQString containing the vendor ID in hexadecimal
* @param modelid a TQString containing the model ID in hexadecimal
* @param subvendorid a TQString containing the subvendor ID in hexadecimal
* @param submodelid a TQString containing the submodel ID in hexadecimal
* @return a TQString containing the device name, if found
*/
TQString findPCIDeviceName(TQString vendorid, TQString modelid, TQString subvendorid, TQString submodelid);
/**
* Look up the device in the system USB database
* @param vendorid a TQString containing the vendor ID in hexadecimal
* @param modelid a TQString containing the model ID in hexadecimal
* @param subvendorid a TQString containing the subvendor ID in hexadecimal
* @param submodelid a TQString containing the submodel ID in hexadecimal
* @return a TQString containing the device name, if found
*/
TQString findUSBDeviceName(TQString vendorid, TQString modelid, TQString subvendorid, TQString submodelid);
/**
* Look up the device in the system PNP database
* @param pnpid a TQString containing the PNP ID
* @return a TQString containing the device name, if found
*/
TQString findPNPDeviceName(TQString pnpid);
/**
* Look up the monitor manufacturer in the system display database
* @param pnpid a TQString containing the display manufacturer ID
* @return a TQString containing the manufacturer name, if found
*/
TQString findMonitorManufacturerName(TQString dpyid);
/**
* Get a friendly string describing a device type
* @param query a TDEGenericDeviceType::TDEGenericDeviceType specifying a device type
* @return a TQString containing the friendly type name
*/
TQString getFriendlyDeviceTypeStringFromType(TDEGenericDeviceType::TDEGenericDeviceType query);
/**
* Get an icon for a device type
* @param query a TDEGenericDeviceType::TDEGenericDeviceType specifying a device type
* @param size a TDEIcon::StdSizes structure specifying the desired icon size
* @return a TQPixmap containing the icon for the specified type
*/
TQPixmap getDeviceTypeIconFromType(TDEGenericDeviceType::TDEGenericDeviceType query, TDEIcon::StdSizes size);
/**
* Convenience function to obtain the root system device
* @return a pointer to a TDERootSystemDevice object
*/
TDERootSystemDevice* rootSystemDevice();
/**
* Rescan a hardware device to look for changes
* WARNING: This method can be very expensive. Use with caution!
* @param hwdevice TDEGenericDevice* with the device to rescan
*/
void rescanDeviceInformation(TDEGenericDevice* hwdevice);
/**
* Rescan a hardware device to look for changes
* WARNING: This method can be very expensive. Use with caution!
* The computational expense can be reduced somewhat if the device tree structure
* has not changed by calling this method with regenerateDeviceTree = FALSE.
* @param hwdevice TDEGenericDevice* with the device to rescan
* @param regenerateDeviceTree TRUE to update parent/child links in device tree
*/
void rescanDeviceInformation(TDEGenericDevice* hwdevice, bool regenerateDeviceTree);
/**
* Enable or disable automatic state updates of triggerless hardware devices
* such as CPUs and network cards. When enabled, your application will use
* additional CPU resources to continually poll triggerless hardware devices.
* Automatic updates are disabled by default.
* @param enable a bool specifiying whether or not automatic updates should be enabled
*/
void setTriggerlessHardwareUpdatesEnabled(bool enable);
/**
* Enable or disable automatic state updates of battery hardware devices.
* When enabled, your application will use
* additional CPU resources to continually poll triggerless hardware devices.
* Automatic updates are disabled by default.
* @param enable a bool specifiying whether or not automatic updates should be enabled
*/
void setBatteryUpdatesEnabled(bool enable);
/**
* Convert a byte count to human readable form
* @param bytes a double containing the number of bytes
* @return a TQString containing the human readable byte count
*/
static TQString bytesToFriendlySizeString(double bytes);
signals:
void hardwareAdded(TDEGenericDevice*);
void hardwareRemoved(TDEGenericDevice*);
void hardwareUpdated(TDEGenericDevice*);
void mountTableModified();
void hardwareEvent(TDEHardwareEvent::TDEHardwareEvent, TQString uuid);
/**
* @param keycode the code of the key that was pressed/released
* See include/linux/input.h for a complete list of keycodes
* @param device a TDEEventDevice* with the device that received the event
*/
void eventDeviceKeyPressed(unsigned int keycode, TDEEventDevice* device);
private slots:
void processHotPluggedHardware();
void processModifiedMounts();
void processModifiedCPUs();
void processBatteryDevices();
void processStatelessDevices();
void processEventDeviceKeyPressed(unsigned int keycode, TDEEventDevice* edevice);
private:
void updateBlacklists(TDEGenericDevice* hwdevice, udev_device* dev);
private:
TDEGenericDevice *classifyUnknownDevice(udev_device* dev, TDEGenericDevice* existingdevice=0, bool force_full_classification=true);
TDEGenericDevice *classifyUnknownDeviceByExternalRules(udev_device* dev, TDEGenericDevice* existingdevice=0, bool classifySubDevices=false);
void updateExistingDeviceInformation(TDEGenericDevice* existingdevice, udev_device* dev=NULL);
void updateParentDeviceInformation();
void updateParentDeviceInformation(TDEGenericDevice* hwdevice);
void addCoreSystemDevices();
/**
* Get the binary monitor EDID for the specified sysfs path
* @return a TQByteArray containing the EDID
*/
TQByteArray getEDID(TQString path);
/**
* Get the monitor EDID name for the specified sysfs path
* @return a TQPair<TQString,TQString> containing the monitor vendor and model, if available
*/
TQPair<TQString,TQString> getEDIDMonitorName(TQString path);
struct udev *m_udevStruct;
struct udev_monitor *m_udevMonitorStruct;
TDEGenericHardwareList m_deviceList;
int m_procMountsFd;
KSimpleDirWatch* m_cpuWatch;
TQTimer* m_cpuWatchTimer;
TQTimer* m_batteryWatchTimer;
TQTimer* m_deviceWatchTimer;
TQSocketNotifier* m_devScanNotifier;
TQSocketNotifier* m_mountScanNotifier;
TQStringList m_mountTable;
TQStringList m_cpuInfo;
TDEDeviceIDMap* pci_id_map;
TDEDeviceIDMap* usb_id_map;
TDEDeviceIDMap* pnp_id_map;
TDEDeviceIDMap* dpy_id_map;
TDECPUDeviceCache m_cpuByPathCache;
friend class TDEGenericDevice;
friend class TDEStorageDevice;
friend class TDECPUDevice;
};
#endif // _TDEHARDWAREDEVICES_H
|