diff options
author | Enrico Scholz <ensc@ensc.de> | 2014-01-02 20:33:57 +0100 |
---|---|---|
committer | Enrico Scholz <ensc@ensc.de> | 2014-01-02 20:39:20 +0100 |
commit | df32484d1f248233602c48438802954d61d6d49f (patch) | |
tree | 2780ad8e88ca93df9760ac5c3cd8b038e45627a2 | |
parent | 022a3a615a82279e9ac8d03ac4038159838c9560 (diff) | |
download | vdr-plugin-inputdev-df32484d1f248233602c48438802954d61d6d49f.tar.gz vdr-plugin-inputdev-df32484d1f248233602c48438802954d61d6d49f.tar.bz2 |
refactored; added and use find_by_path() method
-rw-r--r-- | inputdev.cc | 37 | ||||
-rw-r--r-- | 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_; } } @@ -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); |