From 44dc1f74627bcf6c9048baa337b4e35f80ac3cc2 Mon Sep 17 00:00:00 2001 From: Benjamin Tissoires Date: Thu, 8 Oct 2015 08:26:56 -0400 Subject: [PATCH] Revert "hidraw: ratbag_hidraw_has_report() can also match the usage and usage page" This reverts commit d5a20efd8b53b34dfc52d24ea336e0125b528996. The API is horrible. Better having 2 additional functions to get the usage and usage pageof the report. Signed-off-by: Benjamin Tissoires --- src/driver-etekcity.c | 2 +- src/driver-hidpp10.c | 2 +- src/driver-hidpp20.c | 2 +- src/driver-roccat.c | 2 +- src/libratbag-hidraw.c | 42 +++--------------------------------------- src/libratbag-hidraw.h | 9 ++------- 6 files changed, 9 insertions(+), 50 deletions(-) diff --git a/src/driver-etekcity.c b/src/driver-etekcity.c index 53df8e4f..a6a70b37 100644 --- a/src/driver-etekcity.c +++ b/src/driver-etekcity.c @@ -781,7 +781,7 @@ etekcity_probe(struct ratbag_device *device, const struct ratbag_id id) return -ENODEV; } - if (!ratbag_hidraw_has_report(device, ETEKCITY_REPORT_ID_KEY_MAPPING, 0, 0)) { + if (!ratbag_hidraw_has_report(device, ETEKCITY_REPORT_ID_KEY_MAPPING)) { ratbag_close_hidraw(device); return -ENODEV; } diff --git a/src/driver-hidpp10.c b/src/driver-hidpp10.c index d1558ef0..90d1844f 100644 --- a/src/driver-hidpp10.c +++ b/src/driver-hidpp10.c @@ -194,7 +194,7 @@ hidpp10drv_fill_from_profile(struct ratbag_device *device, struct hidpp10_device static int hidpp10drv_test_hidraw(struct ratbag_device *device) { - return ratbag_hidraw_has_report(device, REPORT_ID_SHORT, 0, 0); + return ratbag_hidraw_has_report(device, REPORT_ID_SHORT); } static int diff --git a/src/driver-hidpp20.c b/src/driver-hidpp20.c index 1a5cfef8..1cd896e8 100644 --- a/src/driver-hidpp20.c +++ b/src/driver-hidpp20.c @@ -434,7 +434,7 @@ hidpp20drv_20_probe(struct ratbag_device *device, const struct ratbag_id id) static int hidpp20drv_test_hidraw(struct ratbag_device *device) { - return ratbag_hidraw_has_report(device, REPORT_ID_LONG, 0, 0); + return ratbag_hidraw_has_report(device, REPORT_ID_LONG); } static int diff --git a/src/driver-roccat.c b/src/driver-roccat.c index 8aa399b3..d114d3c2 100644 --- a/src/driver-roccat.c +++ b/src/driver-roccat.c @@ -917,7 +917,7 @@ roccat_probe(struct ratbag_device *device, const struct ratbag_id id) return -ENODEV; } - if (!ratbag_hidraw_has_report(device, ROCCAT_REPORT_ID_KEY_MAPPING, 0, 0)) { + if (!ratbag_hidraw_has_report(device, ROCCAT_REPORT_ID_KEY_MAPPING)) { ratbag_close_hidraw(device); return -ENODEV; } diff --git a/src/libratbag-hidraw.c b/src/libratbag-hidraw.c index b87e3747..d25ce5e7 100644 --- a/src/libratbag-hidraw.c +++ b/src/libratbag-hidraw.c @@ -280,53 +280,17 @@ ratbag_open_hidraw(struct ratbag_device *device) return __ratbag_find_hidraw(device, hidraw_match_all, false); } -static inline int -ratbag_hidraw_match_report(struct ratbag_hid_report *report, - unsigned int report_id, - unsigned int usage_page, - unsigned int usage) -{ - if (usage && usage != report->usage) - return 0; - - if (usage_page && usage_page != report->usage_page) - return 0; - - return report->report_id == report_id; -} - int -ratbag_hidraw_has_report(struct ratbag_device *device, - unsigned int report_id, - unsigned int usage_page, - unsigned int usage) +ratbag_hidraw_has_report(struct ratbag_device *device, unsigned int report_id) { unsigned i; if (report_id == 0) - if (ratbag_hidraw_match_report(&device->hidraw.reports[0], - report_id, - usage_page, - usage)) { - log_debug(device->ratbag, - "found matching report ID (0) with 0x%04x | 0x%04x\n", - device->hidraw.reports[0].usage_page, - device->hidraw.reports[0].usage); - return 1; - } + return device->hidraw.reports[0].report_id == report_id; for (i = 0; i < device->hidraw.num_reports; i++) { - if (ratbag_hidraw_match_report(&device->hidraw.reports[i], - report_id, - usage_page, - usage)) { - log_debug(device->ratbag, - "found matching report ID (%d) with 0x%04x | 0x%04x\n", - report_id, - device->hidraw.reports[i].usage_page, - device->hidraw.reports[i].usage); + if (device->hidraw.reports[i].report_id == report_id) return 1; - } } return 0; diff --git a/src/libratbag-hidraw.h b/src/libratbag-hidraw.h index 9657281b..e31b9628 100644 --- a/src/libratbag-hidraw.h +++ b/src/libratbag-hidraw.h @@ -120,16 +120,11 @@ int ratbag_hidraw_read_input_report(struct ratbag_device *device, uint8_t *buf, * Tells if a given device has the specified report ID. * * @param device the ratbag device which hidraw node is opened - * @param report_id the report ID we inquire about (0 means no report ID) - * @param usage_page the usage page we want to match with (0 ignores the match) - * @param usage the usage we want to match with (0 ignores the match) + * @param report_id the report ID we inquire about * * @return 1 if the device has the given report id, 0 otherwise */ int -ratbag_hidraw_has_report(struct ratbag_device *device, - unsigned int report_id, - unsigned int usage_page, - unsigned int usage); +ratbag_hidraw_has_report(struct ratbag_device *device, unsigned int report_id); #endif /* LIBRATBAG_HIDRAW_H */