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

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

Issue 317783010: chrome.hid: enrich model with report IDs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Enrich JavaScript model (no incoming report filter) Created 6 years, 6 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
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"
11 #include "device/hid/hid_connection_mac.h" 11 #include "device/hid/hid_connection_mac.h"
12 12
13 namespace device { 13 namespace device {
14 14
15 HidConnectionMac::HidConnectionMac(HidDeviceInfo device_info) 15 HidConnectionMac::HidConnectionMac(HidDeviceInfo device_info)
16 : HidConnection(device_info), 16 : HidConnection(device_info),
17 device_(device_info.device_id, base::scoped_policy::RETAIN) { 17 device_(device_info.device_id, base::scoped_policy::RETAIN) {
18 DCHECK(thread_checker_.CalledOnValidThread()); 18 DCHECK(thread_checker_.CalledOnValidThread());
19 19
20 message_loop_ = base::MessageLoopProxy::current(); 20 message_loop_ = base::MessageLoopProxy::current();
21 21
22 DCHECK(device_.get()); 22 DCHECK(device_.get());
23 inbound_buffer_.reset((uint8_t*)malloc(device_info.input_report_size)); 23 inbound_buffer_.reset((uint8_t*)malloc(device_info.max_input_report_size));
24 IOHIDDeviceRegisterInputReportCallback(device_.get(), 24 IOHIDDeviceRegisterInputReportCallback(device_.get(),
25 inbound_buffer_.get(), 25 inbound_buffer_.get(),
26 device_info.input_report_size, 26 device_info.max_input_report_size,
27 &HidConnectionMac::InputReportCallback, 27 &HidConnectionMac::InputReportCallback,
28 this); 28 this);
29 IOHIDDeviceOpen(device_, kIOHIDOptionsTypeNone); 29 IOHIDDeviceOpen(device_, kIOHIDOptionsTypeNone);
30 } 30 }
31 31
32 HidConnectionMac::~HidConnectionMac() { 32 HidConnectionMac::~HidConnectionMac() {
33 DCHECK(thread_checker_.CalledOnValidThread()); 33 DCHECK(thread_checker_.CalledOnValidThread());
34 34
35 while (!pending_reads_.empty()) { 35 while (!pending_reads_.empty()) {
36 pending_reads_.front().callback.Run(false, 0); 36 pending_reads_.front().callback.Run(false, 0);
(...skipping 22 matching lines...) Expand all
59 const IOCallback& callback) { 59 const IOCallback& callback) {
60 DCHECK(thread_checker_.CalledOnValidThread()); 60 DCHECK(thread_checker_.CalledOnValidThread());
61 WriteReport(kIOHIDReportTypeOutput, report_id, buffer, callback); 61 WriteReport(kIOHIDReportTypeOutput, report_id, buffer, callback);
62 } 62 }
63 63
64 void HidConnectionMac::GetFeatureReport( 64 void HidConnectionMac::GetFeatureReport(
65 uint8_t report_id, 65 uint8_t report_id,
66 scoped_refptr<net::IOBufferWithSize> buffer, 66 scoped_refptr<net::IOBufferWithSize> buffer,
67 const IOCallback& callback) { 67 const IOCallback& callback) {
68 DCHECK(thread_checker_.CalledOnValidThread()); 68 DCHECK(thread_checker_.CalledOnValidThread());
69 if (device_info().feature_report_size == 0) { 69 if (device_info().max_feature_report_size == 0) {
70 callback.Run(false, 0); 70 callback.Run(false, 0);
71 return; 71 return;
72 } 72 }
73 73
74 if (buffer->size() < device_info().feature_report_size) { 74 if (buffer->size() < device_info().max_feature_report_size) {
75 callback.Run(false, 0); 75 callback.Run(false, 0);
76 return; 76 return;
77 } 77 }
78 78
79 uint8_t* feature_report_buffer = reinterpret_cast<uint8_t*>(buffer->data()); 79 uint8_t* feature_report_buffer = reinterpret_cast<uint8_t*>(buffer->data());
80 CFIndex feature_report_size = device_info().feature_report_size; 80 CFIndex max_feature_report_size = device_info().max_feature_report_size;
81 IOReturn result = IOHIDDeviceGetReport(device_, 81 IOReturn result = IOHIDDeviceGetReport(device_,
82 kIOHIDReportTypeFeature, 82 kIOHIDReportTypeFeature,
83 report_id, 83 report_id,
84 feature_report_buffer, 84 feature_report_buffer,
85 &feature_report_size); 85 &max_feature_report_size);
86 if (result == kIOReturnSuccess) 86 if (result == kIOReturnSuccess)
87 callback.Run(true, feature_report_size); 87 callback.Run(true, max_feature_report_size);
88 else 88 else
89 callback.Run(false, 0); 89 callback.Run(false, 0);
90 } 90 }
91 91
92 void HidConnectionMac::SendFeatureReport( 92 void HidConnectionMac::SendFeatureReport(
93 uint8_t report_id, 93 uint8_t report_id,
94 scoped_refptr<net::IOBufferWithSize> buffer, 94 scoped_refptr<net::IOBufferWithSize> buffer,
95 const IOCallback& callback) { 95 const IOCallback& callback) {
96 DCHECK(thread_checker_.CalledOnValidThread()); 96 DCHECK(thread_checker_.CalledOnValidThread());
97 WriteReport(kIOHIDReportTypeFeature, report_id, buffer, callback); 97 WriteReport(kIOHIDReportTypeFeature, report_id, buffer, callback);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 reinterpret_cast<uint8_t*>(output_buffer->data()), 167 reinterpret_cast<uint8_t*>(output_buffer->data()),
168 output_buffer->size()); 168 output_buffer->size());
169 if (res != kIOReturnSuccess) { 169 if (res != kIOReturnSuccess) {
170 callback.Run(false, 0); 170 callback.Run(false, 0);
171 } else { 171 } else {
172 callback.Run(true, output_buffer->size()); 172 callback.Run(true, output_buffer->size());
173 } 173 }
174 } 174 }
175 175
176 } // namespace device 176 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698