Add ability to blacklist devices
This commit is contained in:
parent
2654f319c6
commit
ef84577b9c
|
@ -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"]; }
|
||||
|
|
|
@ -32,6 +32,7 @@ namespace logid
|
|||
Configuration(const char* config_file);
|
||||
Configuration() {}
|
||||
std::map<std::string, DeviceConfig*> devices;
|
||||
std::vector<uint16_t> blacklist;
|
||||
private:
|
||||
libconfig::Config cfg;
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Reference in New Issue
Block a user