Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1068)

Side by Side Diff: device/hid/hid_connection_mac.cc

Issue 223793002: Handle HID report ID correctly on Mac OS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "device/hid/hid_connection_mac.h" 5 #include "device/hid/hid_connection_mac.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/mac/foundation_util.h" 8 #include "base/mac/foundation_util.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/threading/thread_restrictions.h" 10 #include "base/threading/thread_restrictions.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 } 98 }
99 99
100 void HidConnectionMac::InputReportCallback(void* context, 100 void HidConnectionMac::InputReportCallback(void* context,
101 IOReturn result, 101 IOReturn result,
102 void* sender, 102 void* sender,
103 IOHIDReportType type, 103 IOHIDReportType type,
104 uint32_t report_id, 104 uint32_t report_id,
105 uint8_t* report_bytes, 105 uint8_t* report_bytes,
106 CFIndex report_length) { 106 CFIndex report_length) {
107 HidConnectionMac* connection = static_cast<HidConnectionMac*>(context); 107 HidConnectionMac* connection = static_cast<HidConnectionMac*>(context);
108 // If a report ID was received, inject it into a copy of the received 108 // report_id is already contained in report_bytes
109 // report. This is consistent with how input reports are received on
110 // other platforms.
111 scoped_refptr<net::IOBufferWithSize> buffer; 109 scoped_refptr<net::IOBufferWithSize> buffer;
112 if (report_id != 0) { 110 buffer = new net::IOBufferWithSize(report_length);
113 buffer = new net::IOBufferWithSize(report_length + 1); 111 memcpy(buffer->data(), report_bytes, report_length);
114 buffer->data()[0] = static_cast<uint8_t>(report_id); 112
115 memcpy(buffer->data() + 1, report_bytes, report_length);
116 } else {
117 buffer = new net::IOBufferWithSize(report_length);
118 memcpy(buffer->data(), report_bytes, report_length);
119 }
120 connection->message_loop_->PostTask( 113 connection->message_loop_->PostTask(
121 FROM_HERE, 114 FROM_HERE,
122 base::Bind( 115 base::Bind(
123 &HidConnectionMac::ProcessInputReport, connection, type, buffer)); 116 &HidConnectionMac::ProcessInputReport, connection, type, buffer));
124 } 117 }
125 118
126 void HidConnectionMac::ProcessReadQueue() { 119 void HidConnectionMac::ProcessReadQueue() {
127 DCHECK(thread_checker_.CalledOnValidThread()); 120 DCHECK(thread_checker_.CalledOnValidThread());
128 while (pending_reads_.size() && pending_reports_.size()) { 121 while (pending_reads_.size() && pending_reports_.size()) {
129 PendingHidRead read = pending_reads_.front(); 122 PendingHidRead read = pending_reads_.front();
(...skipping 21 matching lines...) Expand all
151 144
152 void HidConnectionMac::WriteReport(IOHIDReportType type, 145 void HidConnectionMac::WriteReport(IOHIDReportType type,
153 uint8_t report_id, 146 uint8_t report_id,
154 scoped_refptr<net::IOBufferWithSize> buffer, 147 scoped_refptr<net::IOBufferWithSize> buffer,
155 const IOCallback& callback) { 148 const IOCallback& callback) {
156 DCHECK(thread_checker_.CalledOnValidThread()); 149 DCHECK(thread_checker_.CalledOnValidThread());
157 if (!device_) { 150 if (!device_) {
158 callback.Run(false, 0); 151 callback.Run(false, 0);
159 return; 152 return;
160 } 153 }
154 scoped_refptr<net::IOBufferWithSize> output_buffer;
155 if (report_id != 0) {
156 output_buffer = new net::IOBufferWithSize(buffer->size() + 1);
157 output_buffer->data()[0] = static_cast<uint8_t>(report_id);
158 memcpy(output_buffer->data() + 1, buffer->data(), buffer->size());
159 } else {
160 output_buffer = new net::IOBufferWithSize(buffer->size());
161 memcpy(output_buffer->data(), buffer->data(), buffer->size());
162 }
161 IOReturn res = 163 IOReturn res =
162 IOHIDDeviceSetReport(device_.get(), 164 IOHIDDeviceSetReport(device_.get(),
163 type, 165 type,
164 report_id, 166 report_id,
165 reinterpret_cast<uint8_t*>(buffer->data()), 167 reinterpret_cast<uint8_t*>(output_buffer->data()),
166 buffer->size()); 168 output_buffer->size());
167 if (res != kIOReturnSuccess) { 169 if (res != kIOReturnSuccess) {
168 callback.Run(false, 0); 170 callback.Run(false, 0);
169 } else { 171 } else {
170 callback.Run(true, buffer->size()); 172 callback.Run(true, output_buffer->size());
171 } 173 }
172 } 174 }
173 175
174 } // namespace device 176 } // namespace device
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698