diff options
author | Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de> | 2013-01-04 18:02:14 +0100 |
---|---|---|
committer | Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de> | 2013-01-04 18:02:14 +0100 |
commit | f5389f0183cdde1b04cf68e475376c8fc7e448f5 (patch) | |
tree | 539f33b60b2c9fc768a26a59861cb8bd27c87733 | |
parent | 498d4af811fc1cdb806df9f201907da3f8318e44 (diff) | |
download | vdr-plugin-inputdev-f5389f0183cdde1b04cf68e475376c8fc7e448f5.tar.gz vdr-plugin-inputdev-f5389f0183cdde1b04cf68e475376c8fc7e448f5.tar.bz2 |
refactored epoll event handling
-rw-r--r-- | inputdev.cc | 54 | ||||
-rw-r--r-- | inputdev.h | 14 |
2 files changed, 39 insertions, 29 deletions
diff --git a/inputdev.cc b/inputdev.cc index c607cf1..5342c0c 100644 --- a/inputdev.cc +++ b/inputdev.cc @@ -160,8 +160,7 @@ bool MagicState::process(struct input_event const &ev) return false; } - -class cInputDevice : public cListObject { +class cInputDevice : public cListObject, public cEpollHandler { public: enum modifier { modSHIFT, @@ -202,7 +201,9 @@ public: return this->dev_t_ - b; } - void handle(void); + virtual void handle_hup(); + virtual void handle_pollin(); + bool open(void); bool start(int efd); void stop(int efd); @@ -417,7 +418,14 @@ void cInputDevice::stop(int efd) epoll_ctl(efd, EPOLL_CTL_DEL, fd_, NULL); } -void cInputDevice::handle(void) +void cInputDevice::handle_hup(void) +{ + isyslog("%s: device '%s' (%s) hung up\n", controller_.plugin_name(), + get_dev_path(), get_description()); + controller_.remove_device(this); +} + +void cInputDevice::handle_pollin(void) { struct input_event ev; ssize_t rc; @@ -617,7 +625,7 @@ bool cInputDeviceController::open_generic(int fd_udev) } ev.events = EPOLLIN; - ev.data.ptr = NULL; + ev.data.ptr = this; rc = epoll_ctl(fd_epoll, EPOLL_CTL_ADD, fd_udev, &ev); if (rc < 0) { @@ -728,6 +736,13 @@ void cInputDeviceController::cleanup_devices(void) dev_mutex_.Unlock(); } +void cInputDeviceController::handle_hup(void) +{ + esyslog("%s: uevent socket hung up; stopping plugin\n", + plugin_name()); + this->Cancel(-1); +} + void cInputDeviceController::Action(void) { while (Running()) { @@ -751,26 +766,13 @@ void cInputDeviceController::Action(void) for (i = 0; i < (size_t)(rc); ++i) { unsigned int ev = events[i].events; - class cInputDevice *dev = - static_cast<class cInputDevice *>(events[i].data.ptr); - - if ((ev & (EPOLLHUP|EPOLLIN)) == EPOLLHUP) { - if (dev == NULL) { - esyslog("%s: uevent socket hung up; stopping plugin\n", - plugin_name()); - this->Cancel(-1); - } else { - isyslog("%s: device '%s' (%s) hung up\n", - plugin_name(), - dev->get_dev_path(), - dev->get_description()); - remove_device(dev); - } - } else if (dev == NULL) { - handle_uevent(); - } else { - dev->handle(); - } + class cEpollHandler *dev = + static_cast<class cEpollHandler *>(events[i].data.ptr); + + if ((ev & (EPOLLHUP|EPOLLIN)) == EPOLLHUP) + dev->handle_hup(); + else + dev->handle_pollin(); } cleanup_devices(); @@ -900,7 +902,7 @@ void cInputDeviceController::dump_gc_devices(void) i->dump(); } -void cInputDeviceController::handle_uevent(void) +void cInputDeviceController::handle_pollin(void) { char buf[128]; char cmd[sizeof buf]; @@ -20,10 +20,16 @@ #include <vdr/remote.h> #include <vdr/thread.h> -class cPlugin; +class cEpollHandler { +public: + virtual void handle_hup() = 0; + virtual void handle_pollin() = 0; +}; +class cPlugin; class cInputDevice; -class cInputDeviceController : protected cRemote, protected cThread +class cInputDeviceController : protected cRemote, protected cThread, + protected cEpollHandler { private: cPlugin &plugin_; @@ -40,7 +46,6 @@ private: bool open_generic(int fd_udev); void cleanup_devices(void); - void handle_uevent(void); bool coldplug_devices(char const *); void dump_active_devices(); @@ -49,6 +54,9 @@ private: protected: virtual void Action(void); + virtual void handle_hup(); + virtual void handle_pollin(); + public: explicit cInputDeviceController(cPlugin &p); virtual ~cInputDeviceController(); |