diff options
author | Enrico Scholz <ensc@ensc.de> | 2014-01-02 20:32:01 +0100 |
---|---|---|
committer | Enrico Scholz <ensc@ensc.de> | 2014-01-02 20:39:20 +0100 |
commit | 2f59b5066e62c81413eb85a5ff59365e0f20c44c (patch) | |
tree | 876f9daae53bd3fd4608e0d4d2d6ae66181488f1 | |
parent | df32484d1f248233602c48438802954d61d6d49f (diff) | |
download | vdr-plugin-inputdev-2f59b5066e62c81413eb85a5ff59365e0f20c44c.tar.gz vdr-plugin-inputdev-2f59b5066e62c81413eb85a5ff59365e0f20c44c.tar.bz2 |
implemented quirks mechanism
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | inputdev.cc | 49 | ||||
-rw-r--r-- | inputdev.h | 1 | ||||
-rw-r--r-- | quirks.cc | 38 | ||||
-rw-r--r-- | quirks.h | 49 |
5 files changed, 140 insertions, 1 deletions
@@ -6,7 +6,9 @@ plugin_SOURCES = \ inputdev.h \ plugin.cc \ modmap.cc \ - modmap.h + modmap.h \ + quirks.cc \ + quirks.h helper_SOURCES = \ udevhelper.c diff --git a/inputdev.cc b/inputdev.cc index 23ef0f9..68ffa90 100644 --- a/inputdev.cc +++ b/inputdev.cc @@ -30,6 +30,7 @@ #include "modmap.h" #include "util.h" +#include "quirks.h" namespace Time { static int compare(struct timespec const &a, @@ -200,6 +201,7 @@ private: int fd_; dev_t dev_t_; class MagicState magic_state_; + class Quirks quirks_; unsigned long modifiers_; unsigned int orig_rate_[2]; @@ -246,6 +248,7 @@ public: unsigned int rate_ms); void dump(void) const; + void change_quirk(char const *quirk, bool do_set); static uint64_t generate_code(uint16_t type, uint16_t code, uint32_t value); @@ -274,6 +277,20 @@ void cInputDevice::dump(void) const get_dev_path(), get_description(), get_fd()); } +void cInputDevice::change_quirk(char const *quirk, bool do_set) +{ + try { + quirks_.change(quirk, do_set); + dsyslog("%s: %s %s quirk '%s'\n", controller_.plugin_name(), + get_dev_path(), + do_set ? "set" : "cleared", + quirk); + } catch (Quirks::UnknownQuirkError const &e) { + esyslog("%s: %s %s\n", controller_.plugin_name(), + get_dev_path(), e.what()); + } +} + uint64_t cInputDevice::generate_code(uint16_t type, uint16_t code, uint32_t value) { @@ -910,6 +927,36 @@ class cInputDevice *cInputDeviceController::find_by_path(char const *path) return dev; } +void cInputDeviceController::change_quirk(char const *dev_path, + char const *quirk) +{ + cMutexLock lock(&dev_mutex_); + class cInputDevice *dev = find_by_path(dev_path); + + if (!dev) { + esyslog("%s: device '%s' not found\n", + plugin_name(), dev_path); + } else { + bool do_set; + + switch (quirk[0]) { + case '+': + do_set = true; + ++quirk; + break; + case '-': + do_set = true; + ++quirk; + break; + default: + do_set = true; + break; + } + + dev->change_quirk(quirk, do_set); + } +} + void cInputDeviceController::remove_device(char const *dev_path) { cMutexLock lock(&dev_mutex_); @@ -1067,6 +1114,8 @@ void cInputDeviceController::handle_pollin(void) add_device(dev); } else if (strcasecmp(cmd, "remove") == 0) { remove_device(dev); + } else if (strncasecmp(cmd, "quirk:", 6) == 0) { + change_quirk(dev, cmd+6); } else if (strcasecmp(cmd, "dump") == 0) { bool is_all = strcasecmp(dev, "all") == 0; if (is_all || strcasecmp(dev, "active") == 0) @@ -82,6 +82,7 @@ public: bool add_device(char const *dev); void remove_device(char const *dev); void remove_device(class cInputDevice *dev); + void change_quirk(char const *dev, char const *quirk); bool set_repeat_rate(unsigned int delay_ms, unsigned int rate_ms); diff --git a/quirks.cc b/quirks.cc new file mode 100644 index 0000000..1db33af --- /dev/null +++ b/quirks.cc @@ -0,0 +1,38 @@ +/* --*- c++ -*-- + * Copyright (C) 2014 Enrico Scholz <ensc@ensc.de> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "quirks.h" +#include <cstring> + +using namespace std; + +Quirks::Quirks() : broken_repeat(false) +{ +} + +bool &Quirks::find_quirk(char const *quirk) throw(UnknownQuirkError) +{ + if (strcasecmp(quirk, "broken_repeat") == 0) + return broken_repeat; + else + throw UnknownQuirkError(quirk); +} + +Quirks &Quirks::change(char const *quirk, bool set) throw(UnknownQuirkError) +{ + find_quirk(quirk) = set; + return *this; +} diff --git a/quirks.h b/quirks.h new file mode 100644 index 0000000..7771cd6 --- /dev/null +++ b/quirks.h @@ -0,0 +1,49 @@ +/* --*- c++ -*-- + * Copyright (C) 2014 Enrico Scholz <ensc@ensc.de> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef H_ENSC_VDR_INPUTDEV_QUIRKS_H +#define H_ENSC_VDR_INPUTDEV_QUIRKS_H + +#include <stdexcept> + +class Quirks { +public: + class UnknownQuirkError : public std::runtime_error { + public: + UnknownQuirkError(std::string const &quirk) : + std::runtime_error("unknown quirk '" + quirk + "'") { + } + }; + + bool broken_repeat; + + Quirks(); + + Quirks &change(char const *quirk, bool set) throw(UnknownQuirkError); + + Quirks &set(char const *quirk) throw(UnknownQuirkError) { + return change(quirk, true); + } + + Quirks &clear(char const *quirk) throw(UnknownQuirkError) { + return change(quirk, false); + } + +private: + bool &find_quirk(char const *quirk) throw(UnknownQuirkError); +}; + +#endif /* H_ENSC_VDR_INPUTDEV_QUIRKS_H */ |