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