diff --git a/src/logid/Configuration.cpp b/src/logid/Configuration.cpp index 7ee716c..d2a0df3 100644 --- a/src/logid/Configuration.cpp +++ b/src/logid/Configuration.cpp @@ -31,6 +31,36 @@ Configuration::Configuration(const char *config_file) throw e; } const Setting &root = cfg.getRoot(); + + try + { + auto& _blacklist = root.lookup("blacklist"); + if(_blacklist.isArray() || _blacklist.isList()) + { + int len = _blacklist.getLength(); + for(int i = 0; i < len; i++) + { + if(!_blacklist[i].isNumber()) { + log_printf(WARN, "Line %d: blacklist must only contain " + "PIDs", _blacklist[i].getSourceLine()); + if(_blacklist.isArray()) + break; + if(_blacklist.isList()) + continue; + } + blacklist.push_back((int)_blacklist[i]); + } + } + else + { + log_printf(WARN, "Line %d: blacklist must be an array or list, " + "ignnoring.", _blacklist.getSourceLine()); + } + } + catch(const SettingNotFoundException &e) + { + } + Setting* _devices; try { _devices = &root["devices"]; } diff --git a/src/logid/Configuration.h b/src/logid/Configuration.h index 07d5765..7ab0868 100644 --- a/src/logid/Configuration.h +++ b/src/logid/Configuration.h @@ -32,6 +32,7 @@ namespace logid Configuration(const char* config_file); Configuration() {} std::map devices; + std::vector blacklist; private: libconfig::Config cfg; }; diff --git a/src/logid/Device.cpp b/src/logid/Device.cpp index 35a4095..215a833 100644 --- a/src/logid/Device.cpp +++ b/src/logid/Device.cpp @@ -45,6 +45,14 @@ bool Device::init() catch(HIDPP20::Error &e) { return false; } name = hidpp_dev->name(); + + if(std::find(global_config->blacklist.begin(), global_config->blacklist.end(), + hidpp_dev->productID()) != global_config->blacklist.end()) + { + log_printf(INFO, "Ignored blacklisted device %s", name.c_str()); + throw BlacklistedDevice(); + } + features = getFeatures(); // Set config, if none is found for this device then use default if(global_config->devices.find(name) == global_config->devices.end()) @@ -237,7 +245,11 @@ void Device::waitForReceiver() usleep(200000); - if(this->init()) break; + try + { + if(this->init()) break; + } + catch(BlacklistedDevice& e) { return; } log_printf(ERROR, "Failed to initialize device %d on %s, waiting for receiver"); delete(listener); diff --git a/src/logid/Device.h b/src/logid/Device.h index 1d37820..7fba0f7 100644 --- a/src/logid/Device.h +++ b/src/logid/Device.h @@ -18,6 +18,16 @@ namespace logid class EventListener; class DeviceConfig; + class BlacklistedDevice : public std::exception + { + public: + BlacklistedDevice() = default; + virtual const char* what() + { + return "Blacklisted device"; + } + }; + class Device { public: diff --git a/src/logid/DeviceFinder.cpp b/src/logid/DeviceFinder.cpp index dc1f751..53bd2a0 100644 --- a/src/logid/DeviceFinder.cpp +++ b/src/logid/DeviceFinder.cpp @@ -40,10 +40,15 @@ DeviceFinder::~DeviceFinder() this->devices_mutex.unlock(); } +///TODO: Unused return variable? Device* DeviceFinder::insertNewDevice(const std::string &path, HIDPP::DeviceIndex index) { auto device = new Device(path, index); - device->init(); + try + { + device->init(); + } + catch(BlacklistedDevice& e) { return nullptr; } this->devices_mutex.lock(); log_printf(INFO, "%s detected: device %d on %s", device->name.c_str(), index, path.c_str());