summaryrefslogtreecommitdiff
path: root/inputdev.c
diff options
context:
space:
mode:
authorEnrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>2012-12-26 17:19:54 +0100
committerEnrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>2012-12-26 17:19:54 +0100
commit1eaaa955de899e8c6076be3a7bd1d8855e7ce682 (patch)
tree4491334331e2402e08f29efbae861ef7ca075137 /inputdev.c
parent97236387af5729929e14d86cafe460dbb08cea1d (diff)
downloadvdr-plugin-inputdev-1eaaa955de899e8c6076be3a7bd1d8855e7ce682.tar.gz
vdr-plugin-inputdev-1eaaa955de899e8c6076be3a7bd1d8855e7ce682.tar.bz2
implemented coldplugging
Diffstat (limited to 'inputdev.c')
-rw-r--r--inputdev.c52
1 files changed, 45 insertions, 7 deletions
diff --git a/inputdev.c b/inputdev.c
index ee1e947..f800425 100644
--- a/inputdev.c
+++ b/inputdev.c
@@ -570,16 +570,17 @@ void cInputDeviceController::remove_device(class cInputDevice *dev)
dev_mutex_.Unlock();
}
-void cInputDeviceController::add_device(char const *dev_name)
+bool cInputDeviceController::add_device(char const *dev_name)
{
class cInputDevice *dev =
new cInputDevice(*this,
cString::sprintf("/dev/input/%s", dev_name));
char const *desc;
+ bool res;
if (!dev->open()) {
delete dev;
- return;
+ return false;
}
desc = dev->get_description();
@@ -606,8 +607,14 @@ void cInputDeviceController::add_device(char const *dev_name)
}
}
- if (dev != NULL && !dev->start(fd_epoll_))
+ if (dev != NULL && !dev->start(fd_epoll_)) {
+ res = false;
remove_device(dev);
+ } else {
+ res = dev != NULL;
+ }
+
+ return res;
}
void cInputDeviceController::handle_uevent(void)
@@ -653,15 +660,46 @@ void cInputDeviceController::handle_uevent(void)
}
}
-bool cInputDeviceController::start(void)
+bool cInputDeviceController::coldplug_devices(char const *path)
{
- cThread::Start();
- return true;
+ cReadDir cdir(path);
+ bool res = true;
+
+ for (;;) {
+ struct dirent const *ent = cdir.Next();
+
+ if (!ent)
+ break;
+
+ if (strcmp(ent->d_name, ".") == 0 ||
+ strcmp(ent->d_name, "..") == 0)
+ continue;
+
+ if (!add_device(ent->d_name)) {
+ esyslog("%s: failed to coldplug '%s'\n",
+ plugin_name(), ent->d_name);
+ res = false;
+ } else {
+ isyslog("%s: coldplugged '%s'\n",
+ plugin_name(), ent->d_name);
+ }
+ }
+
+ return res;
}
-bool cInputDeviceController::initialize(void)
+bool cInputDeviceController::initialize(char const *coldplug_dir)
{
cInputDevice::install_keymap(Name());
+
+ coldplug_devices(coldplug_dir);
+
+ return true;
+}
+
+bool cInputDeviceController::start(void)
+{
+ cThread::Start();
return true;
}