| 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/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/platform_file.h" | 9 #include "base/platform_file.h" |
| 10 #include "base/tuple.h" | 10 #include "base/tuple.h" |
| 11 #include "device/hid/hid_connection.h" | 11 #include "device/hid/hid_connection.h" |
| 12 #include "device/hid/hid_device_info.h" | 12 #include "device/hid/hid_device_info.h" |
| 13 #include "device/hid/hid_service_linux.h" | 13 #include "device/hid/hid_service_linux.h" |
| 14 #include "net/base/io_buffer.h" | |
| 15 | 14 |
| 16 namespace device { | 15 namespace device { |
| 17 | 16 |
| 18 class HidConnectionLinux : public HidConnection, | 17 class HidConnectionLinux : public HidConnection, |
| 19 public base::MessagePumpLibevent::Watcher { | 18 public base::MessagePumpLibevent::Watcher { |
| 20 public: | 19 public: |
| 21 HidConnectionLinux(HidDeviceInfo device_info, | 20 HidConnectionLinux(HidDeviceInfo device_info, |
| 22 ScopedUdevDevicePtr udev_raw_device); | 21 ScopedUdevDevicePtr udev_raw_device); |
| 23 | 22 |
| 24 virtual void Read(scoped_refptr<net::IOBuffer> buffer, | 23 virtual void Read(scoped_refptr<net::IOBufferWithSize> buffer, |
| 25 size_t size, | |
| 26 const IOCallback& callback) OVERRIDE; | 24 const IOCallback& callback) OVERRIDE; |
| 27 virtual void Write(scoped_refptr<net::IOBuffer> buffer, | 25 virtual void Write(scoped_refptr<net::IOBufferWithSize> buffer, |
| 28 size_t size, | |
| 29 const IOCallback& callback) OVERRIDE; | 26 const IOCallback& callback) OVERRIDE; |
| 30 virtual void GetFeatureReport(scoped_refptr<net::IOBuffer> buffer, | 27 virtual void GetFeatureReport(scoped_refptr<net::IOBufferWithSize> buffer, |
| 31 size_t size, | |
| 32 const IOCallback& callback) OVERRIDE; | 28 const IOCallback& callback) OVERRIDE; |
| 33 virtual void SendFeatureReport(scoped_refptr<net::IOBuffer> buffer, | 29 virtual void SendFeatureReport(scoped_refptr<net::IOBufferWithSize> buffer, |
| 34 size_t size, | |
| 35 const IOCallback& callback) OVERRIDE; | 30 const IOCallback& callback) OVERRIDE; |
| 36 | 31 |
| 37 bool initialized() const { return initialized_; } | 32 bool initialized() const { return initialized_; } |
| 38 | 33 |
| 39 // Implements base::MessagePumpLibevent::Watcher | 34 // Implements base::MessagePumpLibevent::Watcher |
| 40 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE; | 35 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE; |
| 41 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE; | 36 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE; |
| 42 | 37 |
| 43 private: | 38 private: |
| 44 friend class base::RefCountedThreadSafe<HidConnectionLinux>; | 39 friend class base::RefCountedThreadSafe<HidConnectionLinux>; |
| 45 virtual ~HidConnectionLinux(); | 40 virtual ~HidConnectionLinux(); |
| 46 | 41 |
| 47 static bool FindHidrawDevNode(udev_device* parent, std::string* result); | 42 static bool FindHidrawDevNode(udev_device* parent, std::string* result); |
| 48 | 43 |
| 49 void ProcessReadQueue(); | 44 void ProcessReadQueue(); |
| 50 void Disconnect(); | 45 void Disconnect(); |
| 51 | 46 |
| 52 base::PlatformFile device_file_; | 47 base::PlatformFile device_file_; |
| 53 base::MessagePumpLibevent::FileDescriptorWatcher device_file_watcher_; | 48 base::MessagePumpLibevent::FileDescriptorWatcher device_file_watcher_; |
| 54 | 49 |
| 55 typedef std::pair<scoped_refptr<net::IOBuffer>, size_t> PendingReport; | 50 std::queue<PendingHidReport> pending_reports_; |
| 56 typedef Tuple3<scoped_refptr<net::IOBuffer>, size_t, IOCallback> | 51 std::queue<PendingHidRead> pending_reads_; |
| 57 PendingRequest; | |
| 58 | |
| 59 std::queue<PendingReport> input_reports_; | |
| 60 std::queue<PendingRequest> read_queue_; | |
| 61 | 52 |
| 62 bool initialized_; | 53 bool initialized_; |
| 63 | 54 |
| 64 DISALLOW_COPY_AND_ASSIGN(HidConnectionLinux); | 55 DISALLOW_COPY_AND_ASSIGN(HidConnectionLinux); |
| 65 }; | 56 }; |
| 66 | 57 |
| 67 } // namespace device | 58 } // namespace device |
| 68 | 59 |
| 69 #endif // DEVICE_HID_HID_CONNECTION_LINUX__ | 60 #endif // DEVICE_HID_HID_CONNECTION_LINUX__ |
| OLD | NEW |