| OLD | NEW |
| 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 <linux/hidraw.h> | 8 #include <linux/hidraw.h> |
| 9 #include <sys/ioctl.h> | 9 #include <sys/ioctl.h> |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #endif | 25 #endif |
| 26 #ifndef HIDIOCGFEATURE | 26 #ifndef HIDIOCGFEATURE |
| 27 #define HIDIOCGFEATURE(len) _IOC(_IOC_WRITE | _IOC_READ, 'H', 0x07, len) | 27 #define HIDIOCGFEATURE(len) _IOC(_IOC_WRITE | _IOC_READ, 'H', 0x07, len) |
| 28 #endif | 28 #endif |
| 29 | 29 |
| 30 namespace device { | 30 namespace device { |
| 31 | 31 |
| 32 class HidConnectionLinux::Helper : public base::MessagePumpLibevent::Watcher { | 32 class HidConnectionLinux::Helper : public base::MessagePumpLibevent::Watcher { |
| 33 public: | 33 public: |
| 34 Helper(base::PlatformFile platform_file, | 34 Helper(base::PlatformFile platform_file, |
| 35 const HidDeviceInfo& device_info, | 35 scoped_refptr<HidDeviceInfo> device_info, |
| 36 base::WeakPtr<HidConnectionLinux> connection, | 36 base::WeakPtr<HidConnectionLinux> connection, |
| 37 scoped_refptr<base::SingleThreadTaskRunner> task_runner) | 37 scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
| 38 : platform_file_(platform_file), | 38 : platform_file_(platform_file), |
| 39 connection_(connection), | 39 connection_(connection), |
| 40 task_runner_(task_runner) { | 40 task_runner_(task_runner) { |
| 41 // Report buffers must always have room for the report ID. | 41 // Report buffers must always have room for the report ID. |
| 42 report_buffer_size_ = device_info.max_input_report_size + 1; | 42 report_buffer_size_ = device_info->max_input_report_size() + 1; |
| 43 has_report_id_ = device_info.has_report_id; | 43 has_report_id_ = device_info->has_report_id(); |
| 44 } | 44 } |
| 45 | 45 |
| 46 ~Helper() override { DCHECK(thread_checker_.CalledOnValidThread()); } | 46 ~Helper() override { DCHECK(thread_checker_.CalledOnValidThread()); } |
| 47 | 47 |
| 48 // Starts the FileDescriptorWatcher that reads input events from the device. | 48 // Starts the FileDescriptorWatcher that reads input events from the device. |
| 49 // Must be called on a thread that has a base::MessageLoopForIO. The helper | 49 // Must be called on a thread that has a base::MessageLoopForIO. The helper |
| 50 // object is owned by the thread where it was started. | 50 // object is owned by the thread where it was started. |
| 51 void Start() { | 51 void Start() { |
| 52 base::ThreadRestrictions::AssertIOAllowed(); | 52 base::ThreadRestrictions::AssertIOAllowed(); |
| 53 thread_checker_.DetachFromThread(); | 53 thread_checker_.DetachFromThread(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 base::ThreadChecker thread_checker_; | 104 base::ThreadChecker thread_checker_; |
| 105 base::PlatformFile platform_file_; | 105 base::PlatformFile platform_file_; |
| 106 size_t report_buffer_size_; | 106 size_t report_buffer_size_; |
| 107 bool has_report_id_; | 107 bool has_report_id_; |
| 108 base::WeakPtr<HidConnectionLinux> connection_; | 108 base::WeakPtr<HidConnectionLinux> connection_; |
| 109 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 109 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 110 base::MessagePumpLibevent::FileDescriptorWatcher file_watcher_; | 110 base::MessagePumpLibevent::FileDescriptorWatcher file_watcher_; |
| 111 }; | 111 }; |
| 112 | 112 |
| 113 HidConnectionLinux::HidConnectionLinux( | 113 HidConnectionLinux::HidConnectionLinux( |
| 114 const HidDeviceInfo& device_info, | 114 scoped_refptr<HidDeviceInfo> device_info, |
| 115 base::File device_file, | 115 base::File device_file, |
| 116 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner) | 116 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner) |
| 117 : HidConnection(device_info), | 117 : HidConnection(device_info), |
| 118 file_task_runner_(file_task_runner), | 118 file_task_runner_(file_task_runner), |
| 119 weak_factory_(this) { | 119 weak_factory_(this) { |
| 120 task_runner_ = base::ThreadTaskRunnerHandle::Get(); | 120 task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
| 121 device_file_ = device_file.Pass(); | 121 device_file_ = device_file.Pass(); |
| 122 | 122 |
| 123 // The helper is passed a weak pointer to this connection so that it can be | 123 // The helper is passed a weak pointer to this connection so that it can be |
| 124 // cleaned up after the connection is closed. | 124 // cleaned up after the connection is closed. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 base::Bind(&HidConnectionLinux::FinishWrite, | 168 base::Bind(&HidConnectionLinux::FinishWrite, |
| 169 weak_factory_.GetWeakPtr(), size, callback), | 169 weak_factory_.GetWeakPtr(), size, callback), |
| 170 task_runner_)); | 170 task_runner_)); |
| 171 } | 171 } |
| 172 | 172 |
| 173 void HidConnectionLinux::PlatformGetFeatureReport( | 173 void HidConnectionLinux::PlatformGetFeatureReport( |
| 174 uint8_t report_id, | 174 uint8_t report_id, |
| 175 const ReadCallback& callback) { | 175 const ReadCallback& callback) { |
| 176 // The first byte of the destination buffer is the report ID being requested | 176 // The first byte of the destination buffer is the report ID being requested |
| 177 // and is overwritten by the feature report. | 177 // and is overwritten by the feature report. |
| 178 DCHECK_GT(device_info().max_feature_report_size, 0u); | 178 DCHECK_GT(device_info()->max_feature_report_size(), 0u); |
| 179 scoped_refptr<net::IOBufferWithSize> buffer( | 179 scoped_refptr<net::IOBufferWithSize> buffer( |
| 180 new net::IOBufferWithSize(device_info().max_feature_report_size + 1)); | 180 new net::IOBufferWithSize(device_info()->max_feature_report_size() + 1)); |
| 181 buffer->data()[0] = report_id; | 181 buffer->data()[0] = report_id; |
| 182 | 182 |
| 183 file_task_runner_->PostTask( | 183 file_task_runner_->PostTask( |
| 184 FROM_HERE, | 184 FROM_HERE, |
| 185 base::Bind( | 185 base::Bind( |
| 186 &HidConnectionLinux::BlockingIoctl, device_file_.GetPlatformFile(), | 186 &HidConnectionLinux::BlockingIoctl, device_file_.GetPlatformFile(), |
| 187 HIDIOCGFEATURE(buffer->size()), buffer, | 187 HIDIOCGFEATURE(buffer->size()), buffer, |
| 188 base::Bind(&HidConnectionLinux::FinishGetFeatureReport, | 188 base::Bind(&HidConnectionLinux::FinishGetFeatureReport, |
| 189 weak_factory_.GetWeakPtr(), report_id, buffer, callback), | 189 weak_factory_.GetWeakPtr(), report_id, buffer, callback), |
| 190 task_runner_)); | 190 task_runner_)); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 PendingHidReport report = pending_reports_.front(); | 297 PendingHidReport report = pending_reports_.front(); |
| 298 | 298 |
| 299 pending_reports_.pop(); | 299 pending_reports_.pop(); |
| 300 if (CompleteRead(report.buffer, report.size, read.callback)) { | 300 if (CompleteRead(report.buffer, report.size, read.callback)) { |
| 301 pending_reads_.pop(); | 301 pending_reads_.pop(); |
| 302 } | 302 } |
| 303 } | 303 } |
| 304 } | 304 } |
| 305 | 305 |
| 306 } // namespace device | 306 } // namespace device |
| OLD | NEW |