summaryrefslogtreecommitdiffstats
path: root/device/hid/hid_connection_mac.cc
diff options
context:
space:
mode:
authorjracle@logitech.com <jracle@logitech.com@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-03 18:32:39 +0000
committerjracle@logitech.com <jracle@logitech.com@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-03 18:32:39 +0000
commit34b0bcc770bb95ca4b62e957a34c69f63c7ad29b (patch)
tree27e2ebd651d4babcfd648b2d86985d7310a1bd68 /device/hid/hid_connection_mac.cc
parentfd2dac13bf483998d94a1f5ba647e489d6170922 (diff)
downloadchromium_src-34b0bcc770bb95ca4b62e957a34c69f63c7ad29b.zip
chromium_src-34b0bcc770bb95ca4b62e957a34c69f63c7ad29b.tar.gz
chromium_src-34b0bcc770bb95ca4b62e957a34c69f63c7ad29b.tar.bz2
Handle HID report ID correctly on Mac OS
- Read (Input callback) : report ID is already contained in input buffer... - Write : append report ID to payload, to be consistent with other platforms BUG=358686 TBR=rockot@chromium.org Review URL: https://codereview.chromium.org/223793002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@261487 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'device/hid/hid_connection_mac.cc')
-rw-r--r--device/hid/hid_connection_mac.cc30
1 files changed, 16 insertions, 14 deletions
diff --git a/device/hid/hid_connection_mac.cc b/device/hid/hid_connection_mac.cc
index 63b7998..ce17df4 100644
--- a/device/hid/hid_connection_mac.cc
+++ b/device/hid/hid_connection_mac.cc
@@ -105,18 +105,11 @@ void HidConnectionMac::InputReportCallback(void* context,
uint8_t* report_bytes,
CFIndex report_length) {
HidConnectionMac* connection = static_cast<HidConnectionMac*>(context);
- // If a report ID was received, inject it into a copy of the received
- // report. This is consistent with how input reports are received on
- // other platforms.
+ // report_id is already contained in report_bytes
scoped_refptr<net::IOBufferWithSize> buffer;
- if (report_id != 0) {
- buffer = new net::IOBufferWithSize(report_length + 1);
- buffer->data()[0] = static_cast<uint8_t>(report_id);
- memcpy(buffer->data() + 1, report_bytes, report_length);
- } else {
- buffer = new net::IOBufferWithSize(report_length);
- memcpy(buffer->data(), report_bytes, report_length);
- }
+ buffer = new net::IOBufferWithSize(report_length);
+ memcpy(buffer->data(), report_bytes, report_length);
+
connection->message_loop_->PostTask(
FROM_HERE,
base::Bind(
@@ -158,16 +151,25 @@ void HidConnectionMac::WriteReport(IOHIDReportType type,
callback.Run(false, 0);
return;
}
+ scoped_refptr<net::IOBufferWithSize> output_buffer;
+ if (report_id != 0) {
+ output_buffer = new net::IOBufferWithSize(buffer->size() + 1);
+ output_buffer->data()[0] = static_cast<uint8_t>(report_id);
+ memcpy(output_buffer->data() + 1, buffer->data(), buffer->size());
+ } else {
+ output_buffer = new net::IOBufferWithSize(buffer->size());
+ memcpy(output_buffer->data(), buffer->data(), buffer->size());
+ }
IOReturn res =
IOHIDDeviceSetReport(device_.get(),
type,
report_id,
- reinterpret_cast<uint8_t*>(buffer->data()),
- buffer->size());
+ reinterpret_cast<uint8_t*>(output_buffer->data()),
+ output_buffer->size());
if (res != kIOReturnSuccess) {
callback.Run(false, 0);
} else {
- callback.Run(true, buffer->size());
+ callback.Run(true, output_buffer->size());
}
}