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

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

Issue 411463005: hid: Linux expects the report ID in the output report buffer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 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_linux.h" 5 #include "device/hid/hid_connection_linux.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <libudev.h> 9 #include <libudev.h>
10 #include <linux/hidraw.h> 10 #include <linux/hidraw.h>
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 pending_read.buffer = buffer; 97 pending_read.buffer = buffer;
98 pending_read.callback = callback; 98 pending_read.callback = callback;
99 pending_reads_.push(pending_read); 99 pending_reads_.push(pending_read);
100 ProcessReadQueue(); 100 ProcessReadQueue();
101 } 101 }
102 102
103 void HidConnectionLinux::PlatformWrite( 103 void HidConnectionLinux::PlatformWrite(
104 uint8_t report_id, 104 uint8_t report_id,
105 scoped_refptr<net::IOBufferWithSize> buffer, 105 scoped_refptr<net::IOBufferWithSize> buffer,
106 const IOCallback& callback) { 106 const IOCallback& callback) {
107 // If report ID is non-zero, insert it into a new copy of the buffer. 107 // Linux always expects the first byte of the buffer to be the report ID.
108 if (report_id != 0) 108 buffer = CopyBufferWithReportId(buffer, report_id);
109 buffer = CopyBufferWithReportId(buffer, report_id); 109 const int bytes_written = HANDLE_EINTR(
110 int bytes_written = HANDLE_EINTR(
111 write(device_file_.GetPlatformFile(), buffer->data(), buffer->size())); 110 write(device_file_.GetPlatformFile(), buffer->data(), buffer->size()));
112 if (bytes_written < 0) { 111 if (bytes_written < 0) {
113 VPLOG(1) << "Write failed"; 112 VPLOG(1) << "Write failed";
114 Disconnect(); 113 Disconnect();
115 callback.Run(false, 0); 114 callback.Run(false, 0);
116 } else { 115 } else {
117 callback.Run(true, bytes_written); 116 if (bytes_written != buffer->size()) {
117 LOG(WARNING) << "Incomplete HID write: "
118 << bytes_written << " != " << buffer->size();
119 }
120 callback.Run(true, bytes_written == 0 ? 0 : bytes_written - 1);
118 } 121 }
119 } 122 }
120 123
121 void HidConnectionLinux::PlatformGetFeatureReport( 124 void HidConnectionLinux::PlatformGetFeatureReport(
122 uint8_t report_id, 125 uint8_t report_id,
123 scoped_refptr<net::IOBufferWithSize> buffer, 126 scoped_refptr<net::IOBufferWithSize> buffer,
124 const IOCallback& callback) { 127 const IOCallback& callback) {
125 if (buffer->size() == 0) { 128 if (buffer->size() == 0) {
126 callback.Run(false, 0); 129 callback.Run(false, 0);
127 return; 130 return;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 pending_reports_.pop(); 224 pending_reports_.pop();
222 225
223 if (CompleteRead(report.buffer, read.callback)) { 226 if (CompleteRead(report.buffer, read.callback)) {
224 pending_reads_.pop(); 227 pending_reads_.pop();
225 } 228 }
226 } 229 }
227 } 230 }
228 } 231 }
229 232
230 } // namespace device 233 } // 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