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_MAC_H_ | 5 #ifndef DEVICE_HID_HID_CONNECTION_MAC_H_ |
6 #define DEVICE_HID_HID_CONNECTION_MAC_H_ | 6 #define DEVICE_HID_HID_CONNECTION_MAC_H_ |
7 | 7 |
8 #include <CoreFoundation/CoreFoundation.h> | 8 #include <CoreFoundation/CoreFoundation.h> |
9 #include <IOKit/hid/IOHIDManager.h> | 9 #include <IOKit/hid/IOHIDManager.h> |
10 | 10 |
11 #include <queue> | 11 #include <queue> |
12 | 12 |
13 #include "base/mac/foundation_util.h" | 13 #include "base/mac/foundation_util.h" |
14 #include "base/memory/ref_counted.h" | |
15 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
16 #include "base/threading/thread_checker.h" | |
17 #include "device/hid/hid_connection.h" | 15 #include "device/hid/hid_connection.h" |
18 #include "device/hid/hid_device_info.h" | |
19 | 16 |
20 namespace base { | 17 namespace base { |
21 class MessageLoopProxy; | 18 class MessageLoopProxy; |
22 } | 19 } |
23 | 20 |
24 namespace net { | 21 namespace net { |
25 class IOBuffer; | 22 class IOBuffer; |
26 } | 23 } |
27 | 24 |
28 namespace device { | 25 namespace device { |
29 | 26 |
30 class HidConnectionMac : public HidConnection { | 27 class HidConnectionMac : public HidConnection { |
31 public: | 28 public: |
32 explicit HidConnectionMac(HidDeviceInfo device_info); | 29 explicit HidConnectionMac(HidDeviceInfo device_info); |
33 | 30 |
34 virtual void Read(scoped_refptr<net::IOBufferWithSize> buffer, | 31 // HidConnection implementation. |
35 const IOCallback& callback) OVERRIDE; | 32 virtual void PlatformRead(scoped_refptr<net::IOBufferWithSize> buffer, |
36 virtual void Write(uint8_t report_id, | 33 const IOCallback& callback) OVERRIDE; |
37 scoped_refptr<net::IOBufferWithSize> buffer, | 34 virtual void PlatformWrite(uint8_t report_id, |
38 const IOCallback& callback) OVERRIDE; | 35 scoped_refptr<net::IOBufferWithSize> buffer, |
39 virtual void GetFeatureReport(uint8_t report_id, | 36 const IOCallback& callback) OVERRIDE; |
40 scoped_refptr<net::IOBufferWithSize> buffer, | 37 virtual void PlatformGetFeatureReport( |
41 const IOCallback& callback) OVERRIDE; | 38 uint8_t report_id, |
42 virtual void SendFeatureReport(uint8_t report_id, | 39 scoped_refptr<net::IOBufferWithSize> buffer, |
43 scoped_refptr<net::IOBufferWithSize> buffer, | 40 const IOCallback& callback) OVERRIDE; |
44 const IOCallback& callback) OVERRIDE; | 41 virtual void PlatformSendFeatureReport( |
| 42 uint8_t report_id, |
| 43 scoped_refptr<net::IOBufferWithSize> buffer, |
| 44 const IOCallback& callback) OVERRIDE; |
45 | 45 |
46 private: | 46 private: |
47 virtual ~HidConnectionMac(); | 47 virtual ~HidConnectionMac(); |
48 | 48 |
49 static void InputReportCallback(void* context, | 49 static void InputReportCallback(void* context, |
50 IOReturn result, | 50 IOReturn result, |
51 void* sender, | 51 void* sender, |
52 IOHIDReportType type, | 52 IOHIDReportType type, |
53 uint32_t report_id, | 53 uint32_t report_id, |
54 uint8_t* report_bytes, | 54 uint8_t* report_bytes, |
55 CFIndex report_length); | 55 CFIndex report_length); |
56 void ProcessReadQueue(); | |
57 void ProcessInputReport(IOHIDReportType type, | |
58 scoped_refptr<net::IOBufferWithSize> buffer); | |
59 | 56 |
60 void WriteReport(IOHIDReportType type, | 57 void WriteReport(IOHIDReportType type, |
61 uint8_t report_id, | 58 uint8_t report_id, |
62 scoped_refptr<net::IOBufferWithSize> buffer, | 59 scoped_refptr<net::IOBufferWithSize> buffer, |
63 const IOCallback& callback); | 60 const IOCallback& callback); |
64 | 61 |
65 scoped_refptr<base::MessageLoopProxy> message_loop_; | 62 void Flush(); |
| 63 void ProcessInputReport(scoped_refptr<net::IOBufferWithSize> buffer); |
| 64 void ProcessReadQueue(); |
66 | 65 |
67 base::ScopedCFTypeRef<IOHIDDeviceRef> device_; | 66 base::ScopedCFTypeRef<IOHIDDeviceRef> device_; |
| 67 scoped_refptr<base::MessageLoopProxy> message_loop_; |
68 scoped_ptr<uint8_t, base::FreeDeleter> inbound_buffer_; | 68 scoped_ptr<uint8_t, base::FreeDeleter> inbound_buffer_; |
69 | 69 |
70 std::queue<PendingHidReport> pending_reports_; | 70 std::queue<PendingHidReport> pending_reports_; |
71 std::queue<PendingHidRead> pending_reads_; | 71 std::queue<PendingHidRead> pending_reads_; |
72 | 72 |
73 base::ThreadChecker thread_checker_; | |
74 | |
75 DISALLOW_COPY_AND_ASSIGN(HidConnectionMac); | 73 DISALLOW_COPY_AND_ASSIGN(HidConnectionMac); |
76 }; | 74 }; |
77 | 75 |
78 | |
79 } // namespace device | 76 } // namespace device |
80 | 77 |
81 #endif // DEVICE_HID_HID_CONNECTION_MAC_H_ | 78 #endif // DEVICE_HID_HID_CONNECTION_MAC_H_ |
OLD | NEW |