Merge pull request #157 from abraha2d/master

Enable compatibility with libconfig older than v1.5
This commit is contained in:
pixl 2020-11-22 21:02:41 -05:00 committed by GitHub
commit 1d6a89881f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 44 additions and 44 deletions

View File

@ -98,7 +98,7 @@ Configuration::Configuration(const std::string& config_file)
} }
try { try {
auto& ignore = root.lookup("ignore"); auto& ignore = root["ignore"];
if(ignore.getType() == libconfig::Setting::TypeInt) { if(ignore.getType() == libconfig::Setting::TypeInt) {
_ignore_list.insert((int)ignore); _ignore_list.insert((int)ignore);
} else if(ignore.isList() || ignore.isArray()) { } else if(ignore.isList() || ignore.isArray()) {
@ -116,7 +116,7 @@ Configuration::Configuration(const std::string& config_file)
} catch(const SettingNotFoundException& e) { } catch(const SettingNotFoundException& e) {
// May be called blacklist // May be called blacklist
try { try {
auto& ignore = root.lookup("blacklist"); auto& ignore = root["blacklist"];
if(ignore.getType() == libconfig::Setting::TypeInt) { if(ignore.getType() == libconfig::Setting::TypeInt) {
_ignore_list.insert((int)ignore); _ignore_list.insert((int)ignore);
} else if(ignore.isList() || ignore.isArray()) { } else if(ignore.isList() || ignore.isArray()) {

View File

@ -41,7 +41,7 @@ std::shared_ptr<Action> Action::makeAction(Device *device, libconfig::Setting
} }
try { try {
auto& action_type = setting.lookup("type"); auto& action_type = setting["type"];
if(action_type.getType() != libconfig::Setting::TypeString) { if(action_type.getType() != libconfig::Setting::TypeString) {
logPrintf(WARN, "Line %d: Action type must be a string", logPrintf(WARN, "Line %d: Action type must be a string",

View File

@ -77,7 +77,7 @@ ChangeDPI::Config::Config(Device *device, libconfig::Setting &config) :
} }
try { try {
auto& inc = config.lookup("inc"); auto& inc = config["inc"];
if(inc.getType() != libconfig::Setting::TypeInt) if(inc.getType() != libconfig::Setting::TypeInt)
logPrintf(WARN, "Line %d: inc must be an integer", logPrintf(WARN, "Line %d: inc must be an integer",
inc.getSourceLine()); inc.getSourceLine());
@ -88,7 +88,7 @@ ChangeDPI::Config::Config(Device *device, libconfig::Setting &config) :
} }
try { try {
auto& sensor = config.lookup("sensor"); auto& sensor = config["sensor"];
if(sensor.getType() != libconfig::Setting::TypeInt) if(sensor.getType() != libconfig::Setting::TypeInt)
logPrintf(WARN, "Line %d: sensor must be an integer", logPrintf(WARN, "Line %d: sensor must be an integer",
sensor.getSourceLine()); sensor.getSourceLine());

View File

@ -62,7 +62,7 @@ ChangeHostAction::Config::Config(Device *device, libconfig::Setting& config)
: Action::Config(device) : Action::Config(device)
{ {
try { try {
auto& host = config.lookup("host"); auto& host = config["host"];
if(host.getType() == libconfig::Setting::TypeInt) { if(host.getType() == libconfig::Setting::TypeInt) {
_offset = false; _offset = false;
_host = host; _host = host;

View File

@ -77,7 +77,7 @@ CycleDPI::Config::Config(Device *device, libconfig::Setting &config) :
} }
try { try {
auto& sensor = config.lookup("sensor"); auto& sensor = config["sensor"];
if(sensor.getType() != Setting::TypeInt) if(sensor.getType() != Setting::TypeInt)
logPrintf(WARN, "Line %d: sensor must be an integer", logPrintf(WARN, "Line %d: sensor must be an integer",
sensor.getSourceLine()); sensor.getSourceLine());
@ -87,7 +87,7 @@ CycleDPI::Config::Config(Device *device, libconfig::Setting &config) :
} }
try { try {
auto& dpis = config.lookup("dpis"); auto& dpis = config["dpis"];
if(!dpis.isList() && !dpis.isArray()) { if(!dpis.isList() && !dpis.isArray()) {
logPrintf(WARN, "Line %d: dpis must be a list or array, skipping.", logPrintf(WARN, "Line %d: dpis must be a list or array, skipping.",
dpis.getSourceLine()); dpis.getSourceLine());

View File

@ -180,7 +180,7 @@ GestureAction::Config::Config(Device* device, libconfig::Setting &root) :
Action::Config(device) Action::Config(device)
{ {
try { try {
auto& gestures = root.lookup("gestures"); auto& gestures = root["gestures"];
if(!gestures.isList()) { if(!gestures.isList()) {
logPrintf(WARN, "Line %d: gestures must be a list, ignoring.", logPrintf(WARN, "Line %d: gestures must be a list, ignoring.",
@ -199,7 +199,7 @@ GestureAction::Config::Config(Device* device, libconfig::Setting &root) :
Direction d; Direction d;
try { try {
auto& direction = gestures[i].lookup("direction"); auto& direction = gestures[i]["direction"];
if(direction.getType() != libconfig::Setting::TypeString) { if(direction.getType() != libconfig::Setting::TypeString) {
logPrintf(WARN, "Line %d: direction must be a string, " logPrintf(WARN, "Line %d: direction must be a string, "
"skipping.", direction.getSourceLine()); "skipping.", direction.getSourceLine());
@ -228,7 +228,7 @@ GestureAction::Config::Config(Device* device, libconfig::Setting &root) :
if(d == None) { if(d == None) {
try { try {
auto& mode = gestures[i].lookup("mode"); auto& mode = gestures[i]["mode"];
if(mode.getType() == libconfig::Setting::TypeString) { if(mode.getType() == libconfig::Setting::TypeString) {
std::string mode_str = mode; std::string mode_str = mode;
std::transform(mode_str.begin(), mode_str.end(), std::transform(mode_str.begin(), mode_str.end(),
@ -251,10 +251,10 @@ GestureAction::Config::Config(Device* device, libconfig::Setting &root) :
try { try {
_none_action = Action::makeAction(_device, _none_action = Action::makeAction(_device,
gestures[i].lookup("action")); gestures[i]["action"]);
} catch (InvalidAction& e) { } catch (InvalidAction& e) {
logPrintf(WARN, "Line %d: %s is not a valid action, " logPrintf(WARN, "Line %d: %s is not a valid action, "
"skipping.", gestures[i].lookup("action") "skipping.", gestures[i]["action"]
.getSourceLine(), e.what()); .getSourceLine(), e.what());
} catch (libconfig::SettingNotFoundException& e) { } catch (libconfig::SettingNotFoundException& e) {
logPrintf(WARN, "Line %d: action is a required field, " logPrintf(WARN, "Line %d: action is a required field, "

View File

@ -57,7 +57,7 @@ KeypressAction::Config::Config(Device* device, libconfig::Setting& config) :
} }
try { try {
auto &keys = config.lookup("keys"); auto &keys = config["keys"];
if(keys.isArray() || keys.isList()) { if(keys.isArray() || keys.isList()) {
int key_count = keys.getLength(); int key_count = keys.getLength();
for(int i = 0; i < key_count; i++) { for(int i = 0; i < key_count; i++) {

View File

@ -101,7 +101,7 @@ AxisGesture::Config::Config(Device *device, libconfig::Setting &setting) :
Gesture::Config(device, setting, false) Gesture::Config(device, setting, false)
{ {
try { try {
auto& axis = setting.lookup("axis"); auto& axis = setting["axis"];
if(axis.isNumber()) { if(axis.isNumber()) {
_axis = axis; _axis = axis;
} else if(axis.getType() == libconfig::Setting::TypeString) { } else if(axis.getType() == libconfig::Setting::TypeString) {
@ -123,7 +123,7 @@ AxisGesture::Config::Config(Device *device, libconfig::Setting &setting) :
} }
try { try {
auto& multiplier = setting.lookup("axis_multiplier"); auto& multiplier = setting["axis_multiplier"];
if(multiplier.isNumber()) { if(multiplier.isNumber()) {
if(multiplier.getType() == libconfig::Setting::TypeFloat) if(multiplier.getType() == libconfig::Setting::TypeFloat)
_multiplier = multiplier; _multiplier = multiplier;

View File

@ -38,7 +38,7 @@ Gesture::Config::Config(Device* device, libconfig::Setting& root,
if(action_required) { if(action_required) {
try { try {
_action = Action::makeAction(_device, _action = Action::makeAction(_device,
root.lookup("action")); root["action"]);
} catch (libconfig::SettingNotFoundException &e) { } catch (libconfig::SettingNotFoundException &e) {
throw InvalidGesture("action is missing"); throw InvalidGesture("action is missing");
} }
@ -49,7 +49,7 @@ Gesture::Config::Config(Device* device, libconfig::Setting& root,
_threshold = LOGID_GESTURE_DEFAULT_THRESHOLD; _threshold = LOGID_GESTURE_DEFAULT_THRESHOLD;
try { try {
auto& threshold = root.lookup("threshold"); auto& threshold = root["threshold"];
if(threshold.getType() == libconfig::Setting::TypeInt) { if(threshold.getType() == libconfig::Setting::TypeInt) {
_threshold = (int)threshold; _threshold = (int)threshold;
if(_threshold <= 0) { if(_threshold <= 0) {
@ -76,7 +76,7 @@ std::shared_ptr<Gesture> Gesture::makeGesture(Device *device,
} }
try { try {
auto& gesture_mode = setting.lookup("mode"); auto& gesture_mode = setting["mode"];
if(gesture_mode.getType() != libconfig::Setting::TypeString) { if(gesture_mode.getType() != libconfig::Setting::TypeString) {
logPrintf(WARN, "Line %d: Gesture mode must be a string," logPrintf(WARN, "Line %d: Gesture mode must be a string,"

View File

@ -66,7 +66,7 @@ IntervalGesture::Config::Config(Device *device, libconfig::Setting &setting) :
Gesture::Config(device, setting) Gesture::Config(device, setting)
{ {
try { try {
auto& interval = setting.lookup("interval"); auto& interval = setting["interval"];
if(interval.getType() != libconfig::Setting::TypeInt) { if(interval.getType() != libconfig::Setting::TypeInt) {
logPrintf(WARN, "Line %d: interval must be an integer, skipping.", logPrintf(WARN, "Line %d: interval must be an integer, skipping.",
interval.getSourceLine()); interval.getSourceLine());
@ -76,7 +76,7 @@ IntervalGesture::Config::Config(Device *device, libconfig::Setting &setting) :
} catch(libconfig::SettingNotFoundException& e) { } catch(libconfig::SettingNotFoundException& e) {
try { try {
// pixels is an alias for interval // pixels is an alias for interval
auto& interval = setting.lookup("pixels"); auto& interval = setting["pixels"];
if(interval.getType() != libconfig::Setting::TypeInt) { if(interval.getType() != libconfig::Setting::TypeInt) {
logPrintf(WARN, "Line %d: pixels must be an integer, skipping.", logPrintf(WARN, "Line %d: pixels must be an integer, skipping.",
interval.getSourceLine()); interval.getSourceLine());

View File

@ -157,7 +157,7 @@ HiresScroll::Config::Config(Device *dev) : DeviceFeature::Config(dev)
_mode = 0; _mode = 0;
_mask = 0; _mask = 0;
try { try {
auto& hires = config_root.lookup("hires"); auto& hires = config_root["hires"];
if(hires.getType() == libconfig::Setting::TypeBoolean) { if(hires.getType() == libconfig::Setting::TypeBoolean) {
_mask |= hidpp20::HiresScroll::Mode::HiRes; _mask |= hidpp20::HiresScroll::Mode::HiRes;
if(hires) if(hires)
@ -169,7 +169,7 @@ HiresScroll::Config::Config(Device *dev) : DeviceFeature::Config(dev)
} catch(libconfig::SettingNotFoundException& e) { } } catch(libconfig::SettingNotFoundException& e) { }
try { try {
auto& invert = config_root.lookup("invert"); auto& invert = config_root["invert"];
if(invert.getType() == libconfig::Setting::TypeBoolean) { if(invert.getType() == libconfig::Setting::TypeBoolean) {
_mask |= hidpp20::HiresScroll::Mode::Inverted; _mask |= hidpp20::HiresScroll::Mode::Inverted;
if(invert) if(invert)
@ -181,7 +181,7 @@ HiresScroll::Config::Config(Device *dev) : DeviceFeature::Config(dev)
} catch(libconfig::SettingNotFoundException& e) { } } catch(libconfig::SettingNotFoundException& e) { }
try { try {
auto& target = config_root.lookup("target"); auto& target = config_root["target"];
if(target.getType() == libconfig::Setting::TypeBoolean) { if(target.getType() == libconfig::Setting::TypeBoolean) {
_mask |= hidpp20::HiresScroll::Mode::Target; _mask |= hidpp20::HiresScroll::Mode::Target;
if(target) if(target)
@ -194,7 +194,7 @@ HiresScroll::Config::Config(Device *dev) : DeviceFeature::Config(dev)
if(_mode & hidpp20::HiresScroll::Mode::Target) { if(_mode & hidpp20::HiresScroll::Mode::Target) {
try { try {
auto& up = config_root.lookup("up"); auto& up = config_root["up"];
try { try {
auto g = actions::Gesture::makeGesture(dev, up); auto g = actions::Gesture::makeGesture(dev, up);
if(g->wheelCompatibility()) { if(g->wheelCompatibility()) {
@ -214,7 +214,7 @@ HiresScroll::Config::Config(Device *dev) : DeviceFeature::Config(dev)
} }
try { try {
auto& down = config_root.lookup("down"); auto& down = config_root["down"];
try { try {
auto g = actions::Gesture::makeGesture(dev, down); auto g = actions::Gesture::makeGesture(dev, down);
if(g->wheelCompatibility()) { if(g->wheelCompatibility()) {

View File

@ -178,7 +178,7 @@ void RemapButton::Config::_parseButton(libconfig::Setting &setting)
uint16_t cid; uint16_t cid;
try { try {
auto& cid_setting = setting.lookup("cid"); auto& cid_setting = setting["cid"];
if(!cid_setting.isNumber()) { if(!cid_setting.isNumber()) {
logPrintf(WARN, "Line %d: cid must be a number, ignoring.", logPrintf(WARN, "Line %d: cid must be a number, ignoring.",
cid_setting.getSourceLine()); cid_setting.getSourceLine());
@ -193,7 +193,7 @@ void RemapButton::Config::_parseButton(libconfig::Setting &setting)
try { try {
_buttons.emplace(cid, Action::makeAction(_device, _buttons.emplace(cid, Action::makeAction(_device,
setting.lookup("action"))); setting["action"]));
} catch(libconfig::SettingNotFoundException& e) { } catch(libconfig::SettingNotFoundException& e) {
logPrintf(WARN, "Line %d: action is required, ignoring.", logPrintf(WARN, "Line %d: action is required, ignoring.",
setting.getSourceLine()); setting.getSourceLine());

View File

@ -184,7 +184,7 @@ ThumbWheel::Config::Config(Device* dev) : DeviceFeature::Config(dev)
} }
try { try {
auto& divert = config_root.lookup("divert"); auto& divert = config_root["divert"];
if(divert.getType() == libconfig::Setting::TypeBoolean) { if(divert.getType() == libconfig::Setting::TypeBoolean) {
_divert = divert; _divert = divert;
} else { } else {
@ -194,7 +194,7 @@ ThumbWheel::Config::Config(Device* dev) : DeviceFeature::Config(dev)
} catch(libconfig::SettingNotFoundException& e) { } } catch(libconfig::SettingNotFoundException& e) { }
try { try {
auto& invert = config_root.lookup("invert"); auto& invert = config_root["invert"];
if(invert.getType() == libconfig::Setting::TypeBoolean) { if(invert.getType() == libconfig::Setting::TypeBoolean) {
_invert = invert; _invert = invert;
} else { } else {
@ -227,7 +227,7 @@ std::shared_ptr<actions::Action> ThumbWheel::Config::_genAction(Device* dev,
libconfig::Setting& config_root, const std::string& name) libconfig::Setting& config_root, const std::string& name)
{ {
try { try {
auto& a_group = config_root.lookup(name); auto& a_group = config_root[name];
try { try {
return actions::Action::makeAction(dev, a_group); return actions::Action::makeAction(dev, a_group);
} catch(actions::InvalidAction& e) { } catch(actions::InvalidAction& e) {
@ -244,7 +244,7 @@ std::shared_ptr<actions::Gesture> ThumbWheel::Config::_genGesture(Device* dev,
libconfig::Setting& config_root, const std::string& name) libconfig::Setting& config_root, const std::string& name)
{ {
try { try {
auto& g_group = config_root.lookup(name); auto& g_group = config_root[name];
try { try {
auto g = actions::Gesture::makeGesture(dev, g_group); auto g = actions::Gesture::makeGesture(dev, g_group);
if(g->wheelCompatibility()) { if(g->wheelCompatibility()) {