Commit a4f69b9f1e1672e914e6f1f469538a7dc758fe2b

  • avatar
  • swiesner <swiesner @283d02a7-25f6-0310…ecb5cbfe19da.>
  • Thu Aug 05 13:28:09 CEST 2010
Added a bunch of explanatory comments for the mouse devices monitoring code

git-svn-id: svn+ssh://svn.kde.org/home/kde/trunk/playground/utils/synaptiks@1159456 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
  
4747
4848 virtual ~MouseDevicesMonitorPrivate() {};
4949
50 /**
51 * Slot for monitorNotifier signals. Reads the available device,
52 * and emits a MouseDevicesMonitor signals, if the device is an
53 * added or removed mouse device. Also updates the serial number
54 * and product name caches.
55 */
5056 void _k_udevDataAvailable();
5157
58 /**
59 * Find the device object for the given @p serial number.
60 *
61 * Device lookup is cached using serialCache. UDev is only queried
62 * on cache misses.
63 *
64 * @param serial the serial number
65 * @return the device or 0, if there is no device for @p serial
66 */
5267 QUDevDevicePtr findDeviceBySerial(const QByteArray &serial) const;
5368
54 // maps serials to device paths to speed up mapping from serial
55 // numbers to device paths
69 /**
70 * Map serial numbers to device paths to speed up device look up by
71 * serial number
72 */
5673 mutable QHash<QByteArray, QByteArray> serialCache;
57 // map serials to product names to speed up
74
75 /**
76 * Map serial numbers to the product name of the corresponding
77 * device.
78 */
5879 mutable QHash<QByteArray, QByteArray> productNameCache;
80
81 /**
82 * UDev library context, which is required to access the whole
83 * library.
84 */
5985 QUDevContextPtr context;
86
87 /**
88 * UDev monitor object. Provides a file descriptor to read added or
89 * removed devices from.
90 */
6091 QUDevMonitorPtr monitor;
92
93 /**
94 * Notifier object for the monitor. Monitors the monitor's file
95 * descriptor for added or removed devices.
96 */
6197 QSocketNotifier *monitorNotifier;
98
6299 MouseDevicesMonitor *q_ptr;
63100 };
64101}
65102
103/**
104 * This code uses the serial number of input devices to clearly identify
105 * mouse device. The path is sysfs can't be used, because it depends on the
106 * port, into which the device is plugged: a single mouse device has
107 * different sys paths if plugged into different ports.
108 *
109 * However, udev does not allow for direct property queries. To get a
110 * device object for a given serial number, all input devices are enumerated
111 * and filtered by the given serial number. Results of such lookups are
112 * cached.
113 */
66114
67115MouseDevicesMonitorPrivate::MouseDevicesMonitorPrivate(
68116 MouseDevicesMonitor *qq): q_ptr(qq) {
121121 udev_monitor_get_fd(this->monitor), QSocketNotifier::Read, q);
122122 q->connect(this->monitorNotifier, SIGNAL(activated(int)),
123123 SLOT(_k_udevDataAvailable()));
124 // we are only interested in events on input devices
124125 udev_monitor_filter_add_match_subsystem_devtype(
125126 this->monitor, "input", 0);
126127 udev_monitor_enable_receiving(this->monitor);
132132 * otherwise
133133 */
134134inline bool isMouse(const QUDevDevicePtr &device) {
135 // check the sys name here, because input devices may be represented by
136 // more than one device object (e.g. a raw event device and a mouse
137 // device). We need to make sure, that we really got the mouse device
138 // object
135139 QByteArray sysName = udev_device_get_sysname(device);
136 // check, if the device really is a mouse
137140 QByteArray isMouse = udev_device_get_property_value(
138141 device, "ID_INPUT_MOUSE");
139142 QByteArray isTouchpad = udev_device_get_property_value(
264264 // cache miss, query udev for the product name
265265 QUDevDevicePtr device = d->findDeviceBySerial(id.toAscii());
266266 if (device) {
267 // no need for a guarded pointer here, the parent device is freed
268 // together with the child
267 // the parent object is attached to the device object, and is not
268 // referenced itself. It is destroyed, when the device object is
269 // destroyed, therefore no guarded pointer must be used to avoid
270 // double frees.
269271 udev_device *parent = udev_device_get_parent(device);
270272 if (parent) {
271273 kDebug() << "found" << name << "for serial" << id;