| 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 #ifndef DEVICE_HID_HID_CONNECTION_LINUX_H_ | 5 #ifndef DEVICE_HID_HID_CONNECTION_LINUX_H_ |
| 6 #define DEVICE_HID_HID_CONNECTION_LINUX_H_ | 6 #define DEVICE_HID_HID_CONNECTION_LINUX_H_ |
| 7 | 7 |
| 8 #include "base/files/file.h" | 8 #include "base/files/file.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "device/hid/hid_connection.h" | 10 #include "device/hid/hid_connection.h" |
| 11 #include "device/hid/hid_device_info.h" | 11 #include "device/hid/hid_device_info.h" |
| 12 #include "device/hid/hid_service_linux.h" | 12 #include "device/hid/hid_service_linux.h" |
| 13 | 13 |
| 14 namespace device { | 14 namespace device { |
| 15 | 15 |
| 16 class HidConnectionLinux : public HidConnection, | 16 class HidConnectionLinux : public HidConnection, |
| 17 public base::MessagePumpLibevent::Watcher { | 17 public base::MessagePumpLibevent::Watcher { |
| 18 public: | 18 public: |
| 19 HidConnectionLinux(HidDeviceInfo device_info, | 19 HidConnectionLinux(HidDeviceInfo device_info, |
| 20 ScopedUdevDevicePtr udev_raw_device); | 20 std::string dev_node); |
| 21 | 21 |
| 22 virtual void Read(scoped_refptr<net::IOBufferWithSize> buffer, | 22 virtual void Read(scoped_refptr<net::IOBufferWithSize> buffer, |
| 23 const IOCallback& callback) OVERRIDE; | 23 const IOCallback& callback) OVERRIDE; |
| 24 virtual void Write(uint8_t report_id, | 24 virtual void Write(uint8_t report_id, |
| 25 scoped_refptr<net::IOBufferWithSize> buffer, | 25 scoped_refptr<net::IOBufferWithSize> buffer, |
| 26 const IOCallback& callback) OVERRIDE; | 26 const IOCallback& callback) OVERRIDE; |
| 27 virtual void GetFeatureReport(uint8_t report_id, | 27 virtual void GetFeatureReport(uint8_t report_id, |
| 28 scoped_refptr<net::IOBufferWithSize> buffer, | 28 scoped_refptr<net::IOBufferWithSize> buffer, |
| 29 const IOCallback& callback) OVERRIDE; | 29 const IOCallback& callback) OVERRIDE; |
| 30 virtual void SendFeatureReport(uint8_t report_id, | 30 virtual void SendFeatureReport(uint8_t report_id, |
| 31 scoped_refptr<net::IOBufferWithSize> buffer, | 31 scoped_refptr<net::IOBufferWithSize> buffer, |
| 32 const IOCallback& callback) OVERRIDE; | 32 const IOCallback& callback) OVERRIDE; |
| 33 | 33 |
| 34 // Implements base::MessagePumpLibevent::Watcher | 34 // Implements base::MessagePumpLibevent::Watcher |
| 35 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE; | 35 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE; |
| 36 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE; | 36 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE; |
| 37 | 37 |
| 38 private: | 38 private: |
| 39 friend class base::RefCountedThreadSafe<HidConnectionLinux>; | 39 friend class base::RefCountedThreadSafe<HidConnectionLinux>; |
| 40 virtual ~HidConnectionLinux(); | 40 virtual ~HidConnectionLinux(); |
| 41 | 41 |
| 42 static bool FindHidrawDevNode(udev_device* parent, std::string* result); | |
| 43 | |
| 44 void ProcessReadQueue(); | 42 void ProcessReadQueue(); |
| 45 void Disconnect(); | 43 void Disconnect(); |
| 46 | 44 |
| 47 base::File device_file_; | 45 base::File device_file_; |
| 48 base::MessagePumpLibevent::FileDescriptorWatcher device_file_watcher_; | 46 base::MessagePumpLibevent::FileDescriptorWatcher device_file_watcher_; |
| 49 | 47 |
| 50 std::queue<PendingHidReport> pending_reports_; | 48 std::queue<PendingHidReport> pending_reports_; |
| 51 std::queue<PendingHidRead> pending_reads_; | 49 std::queue<PendingHidRead> pending_reads_; |
| 52 | 50 |
| 53 base::ThreadChecker thread_checker_; | 51 base::ThreadChecker thread_checker_; |
| 54 | 52 |
| 55 DISALLOW_COPY_AND_ASSIGN(HidConnectionLinux); | 53 DISALLOW_COPY_AND_ASSIGN(HidConnectionLinux); |
| 56 }; | 54 }; |
| 57 | 55 |
| 58 } // namespace device | 56 } // namespace device |
| 59 | 57 |
| 60 #endif // DEVICE_HID_HID_CONNECTION_LINUX__ | 58 #endif // DEVICE_HID_HID_CONNECTION_LINUX__ |
| OLD | NEW |