Add ability to ignore devices

master
pixl 4 years ago
parent 497ec07bdf
commit 018bdb83ad
No known key found for this signature in database
GPG Key ID: 1866C148CD593B6E
  1. 45
      src/logid/Configuration.cpp
  2. 3
      src/logid/Configuration.h
  3. 11
      src/logid/DeviceManager.cpp
  4. 7
      src/logid/Receiver.cpp

@ -96,6 +96,46 @@ Configuration::Configuration(const std::string& config_file)
catch(const SettingNotFoundException &e) {
logPrintf(WARN, "No devices listed in config file.");
}
try {
auto& ignore = root.lookup("ignore");
if(ignore.getType() == libconfig::Setting::TypeInt) {
_ignore_list.insert((int)ignore);
} else if(ignore.isList() || ignore.isArray()) {
int ignore_count = ignore.getLength();
for(int i = 0; i < ignore_count; i++) {
if(ignore[i].getType() != libconfig::Setting::TypeInt) {
logPrintf(WARN, "Line %d: ignore must refer to device PIDs",
ignore[i].getSourceLine());
if(ignore.isArray())
break;
} else
_ignore_list.insert((int)ignore[i]);
}
}
} catch(const SettingNotFoundException& e) {
// May be called blacklist
try {
auto& ignore = root.lookup("blacklist");
if(ignore.getType() == libconfig::Setting::TypeInt) {
_ignore_list.insert((int)ignore);
} else if(ignore.isList() || ignore.isArray()) {
int ignore_count = ignore.getLength();
for(int i = 0; i < ignore_count; i++) {
if(ignore[i].getType() != libconfig::Setting::TypeInt) {
logPrintf(WARN, "Line %d: blacklist must refer to "
"device PIDs",
ignore[i].getSourceLine());
if(ignore.isArray())
break;
} else
_ignore_list.insert((int)ignore[i]);
}
}
} catch(const SettingNotFoundException& e) {
// Ignore
}
}
}
libconfig::Setting& Configuration::getSetting(const std::string& path)
@ -112,6 +152,11 @@ std::string Configuration::getDevice(const std::string& name)
return it->second;
}
bool Configuration::isIgnored(uint16_t pid) const
{
return _ignore_list.find(pid) != _ignore_list.end();
}
Configuration::DeviceNotFound::DeviceNotFound(std::string name) :
_name (std::move(name))
{

@ -23,6 +23,7 @@
#include <libconfig.h++>
#include <memory>
#include <chrono>
#include <set>
#define LOGID_DEFAULT_IO_TIMEOUT std::chrono::seconds(2)
#define LOGID_DEFAULT_WORKER_COUNT 4
@ -36,6 +37,7 @@ namespace logid
Configuration() = default;
libconfig::Setting& getSetting(const std::string& path);
std::string getDevice(const std::string& name);
bool isIgnored(uint16_t pid) const;
class DeviceNotFound : public std::exception
{
@ -50,6 +52,7 @@ namespace logid
int workerCount() const;
private:
std::map<std::string, std::string> _device_paths;
std::set<uint16_t> _ignore_list;
std::chrono::milliseconds _io_timeout = LOGID_DEFAULT_IO_TIMEOUT;
int _worker_threads = LOGID_DEFAULT_WORKER_COUNT;
libconfig::Config _config;

@ -32,6 +32,17 @@ void DeviceManager::addDevice(std::string path)
{
bool defaultExists = true;
bool isReceiver = false;
// Check if device is ignored before continuing
{
raw::RawDevice raw_dev(path);
if(global_config->isIgnored(raw_dev.productId())) {
logPrintf(DEBUG, "%s: Device 0x%04x ignored.",
path.c_str(), raw_dev.productId());
return;
}
}
try {
hidpp::Device device(path, hidpp::DefaultDevice);
isReceiver = device.version() == std::make_tuple(1, 0);

@ -34,6 +34,13 @@ void Receiver::addDevice(hidpp::DeviceConnectionEvent event)
{
std::unique_lock<std::mutex> lock(_devices_change);
try {
// Check if device is ignored before continuing
if(global_config->isIgnored(event.pid)) {
logPrintf(DEBUG, "%s:%d: Device 0x%04x ignored.",
_path.c_str(), event.index, event.pid);
return;
}
auto dev = _devices.find(event.index);
if(dev != _devices.end()) {
if(event.linkEstablished)

Loading…
Cancel
Save