summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2012-08-29 15:29:36 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2012-08-29 16:05:32 +1000
commit39507ef9eab2f48fda02f62d019e1cb172e74f18 (patch)
treea2f10d525ae869c0bcbf1f1c23bced5c55750dff
parent91bba3825f53460a187786de8a8cfdf27829087c (diff)
device: split device comparison into a helper function
No functional changes, we'll re-use this though. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Chase Douglas <chase.douglas@canonical.com>
-rw-r--r--src/device.cpp38
1 files changed, 23 insertions, 15 deletions
diff --git a/src/device.cpp b/src/device.cpp
index ffe33c6..5868036 100644
--- a/src/device.cpp
+++ b/src/device.cpp
@@ -62,6 +62,26 @@ static int _event_device_filter(const struct dirent *d) {
return (strncmp("event", d->d_name, sizeof("event") - 1) == 0);
}
+static bool event_is_device(const std::string &path,
+ const std::string &devname,
+ time_t ctime) {
+ char device_name[256];
+ bool equal = false;
+ int fd = open(path.c_str(), O_RDONLY);
+
+ if (ioctl(fd, EVIOCGNAME(sizeof(device_name)), device_name) != -1 &&
+ devname.compare(device_name) == 0) {
+ struct stat buf;
+
+ if (fstat(fd, &buf) == 0)
+ if (buf.st_ctime >= ctime)
+ equal = true;
+ }
+ close(fd);
+
+ return equal;
+}
+
void xorg::testing::evemu::Device::GuessDeviceNode(time_t ctime) {
struct dirent **event_devices = NULL;
int n_event_devices;
@@ -73,21 +93,9 @@ void xorg::testing::evemu::Device::GuessDeviceNode(time_t ctime) {
for (int i = 0; i < n_event_devices && !found; i++) {
std::stringstream s;
s << DEV_INPUT_DIR << event_devices[i]->d_name;
-
- int fd = open(s.str().c_str(), O_RDONLY);
- char device_name[256];
-
- if (ioctl(fd, EVIOCGNAME(sizeof(device_name)), device_name) != -1 &&
- strcmp(device_name, evemu_get_name(d_->device)) == 0) {
- struct stat buf;
- if (fstat(fd, &buf) == 0) {
- if (buf.st_ctime >= ctime) {
- d_->device_node = s.str();
- found = true;
- }
- }
- }
- close(fd);
+ found = event_is_device(s.str(), evemu_get_name(d_->device), ctime);
+ if (found)
+ d_->device_node = s.str();
}
if (!found)