From df32484d1f248233602c48438802954d61d6d49f Mon Sep 17 00:00:00 2001 From: Enrico Scholz Date: Thu, 2 Jan 2014 20:33:57 +0100 Subject: refactored; added and use find_by_path() method --- inputdev.cc | 37 ++++++++++++++++++++----------------- inputdev.h | 2 ++ 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/inputdev.cc b/inputdev.cc index 9f280d2..23ef0f9 100644 --- a/inputdev.cc +++ b/inputdev.cc @@ -890,39 +890,42 @@ void cInputDeviceController::Action(void) } } -void cInputDeviceController::remove_device(char const *dev_path) +class cInputDevice *cInputDeviceController::find_by_path(char const *path) { class cInputDevice *dev = NULL; struct stat st; - if (stat(dev_path, &st) < 0) { - esyslog("%s: fstat(%s) failed: %s\n", plugin_name(), - dev_path, strerror(errno)); + if (stat(path, &st) < 0) { + dsyslog("%s: fstat(%s) failed: %s\n", plugin_name(), + path, strerror(errno)); } else { - cMutexLock lock(&dev_mutex_); - for (cInputDevice *i = devices_.First(); i != NULL && dev == NULL; i = devices_.Next(i)) { if (i->Compare(st.st_rdev) == 0) dev = i; } + } - if (dev != NULL) { - dev->stop(fd_epoll_); - - assert(dev->container == &devices_); - devices_.Del(dev, false); + return dev; +} - gc_devices_.Add(dev); - dev->container = &gc_devices_; - } - } +void cInputDeviceController::remove_device(char const *dev_path) +{ + cMutexLock lock(&dev_mutex_); + class cInputDevice *dev = find_by_path(dev_path); - if (dev == NULL) { + if (!dev) { esyslog("%s: device '%s' not found\n", plugin_name(), dev_path); - return; + } else { + dev->stop(fd_epoll_); + + assert(dev->container == &devices_); + devices_.Del(dev, false); + + gc_devices_.Add(dev); + dev->container = &gc_devices_; } } diff --git a/inputdev.h b/inputdev.h index 05c2992..71a7ee0 100644 --- a/inputdev.h +++ b/inputdev.h @@ -58,6 +58,8 @@ private: void dump_active_devices(); void dump_gc_devices(); + class cInputDevice *find_by_path(char const *path); + protected: virtual void Action(void); -- cgit v1.2.3