Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef DEVICE_HID_HID_CONNECTION_MAC_H_ |
| 6 | #define DEVICE_HID_HID_CONNECTION_MAC_H_ |
| 7 | |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 8 | #include <CoreFoundation/CoreFoundation.h> |
| 9 | #include <IOKit/hid/IOHIDManager.h> |
| 10 | |
| 11 | #include <queue> |
| 12 | |
| 13 | #include "base/mac/foundation_util.h" |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 14 | #include "base/memory/scoped_ptr.h" |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 15 | #include "device/hid/hid_connection.h" |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 16 | |
| 17 | namespace base { |
Ben Murdoch | 1675a64 | 2014-10-22 18:55:17 +0100 | [diff] [blame] | 18 | class SingleThreadTaskRunner; |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 19 | } |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 20 | |
| 21 | namespace net { |
| 22 | class IOBuffer; |
| 23 | } |
| 24 | |
| 25 | namespace device { |
| 26 | |
| 27 | class HidConnectionMac : public HidConnection { |
| 28 | public: |
Ben Murdoch | 1675a64 | 2014-10-22 18:55:17 +0100 | [diff] [blame] | 29 | explicit HidConnectionMac( |
| 30 | IOHIDDeviceRef device, |
| 31 | HidDeviceInfo device_info, |
| 32 | scoped_refptr<base::SingleThreadTaskRunner> file_task_runner); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 33 | |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 34 | private: |
| 35 | virtual ~HidConnectionMac(); |
| 36 | |
Primiano Tucci | 1320f92 | 2014-09-30 14:45:55 +0100 | [diff] [blame] | 37 | // HidConnection implementation. |
Ben Murdoch | 1675a64 | 2014-10-22 18:55:17 +0100 | [diff] [blame] | 38 | virtual void PlatformClose() OVERRIDE; |
Primiano Tucci | 1320f92 | 2014-09-30 14:45:55 +0100 | [diff] [blame] | 39 | virtual void PlatformRead(const ReadCallback& callback) OVERRIDE; |
| 40 | virtual void PlatformWrite(scoped_refptr<net::IOBuffer> buffer, |
| 41 | size_t size, |
| 42 | const WriteCallback& callback) OVERRIDE; |
| 43 | virtual void PlatformGetFeatureReport(uint8_t report_id, |
| 44 | const ReadCallback& callback) OVERRIDE; |
| 45 | virtual void PlatformSendFeatureReport( |
| 46 | scoped_refptr<net::IOBuffer> buffer, |
| 47 | size_t size, |
| 48 | const WriteCallback& callback) OVERRIDE; |
| 49 | |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 50 | static void InputReportCallback(void* context, |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 51 | IOReturn result, |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 52 | void* sender, |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 53 | IOHIDReportType type, |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 54 | uint32_t report_id, |
| 55 | uint8_t* report_bytes, |
| 56 | CFIndex report_length); |
Ben Murdoch | 116680a | 2014-07-20 18:25:52 -0700 | [diff] [blame] | 57 | void ProcessInputReport(scoped_refptr<net::IOBufferWithSize> buffer); |
| 58 | void ProcessReadQueue(); |
Ben Murdoch | 1675a64 | 2014-10-22 18:55:17 +0100 | [diff] [blame] | 59 | void GetFeatureReportAsync(uint8_t report_id, const ReadCallback& callback); |
| 60 | void SetReportAsync(IOHIDReportType report_type, |
| 61 | scoped_refptr<net::IOBuffer> buffer, |
| 62 | size_t size, |
| 63 | const WriteCallback& callback); |
| 64 | void ReturnAsyncResult(const base::Closure& callback); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 65 | |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 66 | base::ScopedCFTypeRef<IOHIDDeviceRef> device_; |
Ben Murdoch | 1675a64 | 2014-10-22 18:55:17 +0100 | [diff] [blame] | 67 | scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 68 | scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; |
Primiano Tucci | 1320f92 | 2014-09-30 14:45:55 +0100 | [diff] [blame] | 69 | std::vector<uint8_t> inbound_buffer_; |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 70 | |
| 71 | std::queue<PendingHidReport> pending_reports_; |
| 72 | std::queue<PendingHidRead> pending_reads_; |
| 73 | |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 74 | DISALLOW_COPY_AND_ASSIGN(HidConnectionMac); |
| 75 | }; |
| 76 | |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 77 | } // namespace device |
| 78 | |
| 79 | #endif // DEVICE_HID_HID_CONNECTION_MAC_H_ |