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 { |
| 18 | class MessageLoopProxy; |
| 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: |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 29 | explicit HidConnectionMac(HidDeviceInfo device_info); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 30 | |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 31 | private: |
| 32 | virtual ~HidConnectionMac(); |
| 33 | |
Primiano Tucci | 1320f92 | 2014-09-30 14:45:55 +0100 | [diff] [blame^] | 34 | // HidConnection implementation. |
| 35 | virtual void PlatformRead(const ReadCallback& callback) OVERRIDE; |
| 36 | virtual void PlatformWrite(scoped_refptr<net::IOBuffer> buffer, |
| 37 | size_t size, |
| 38 | const WriteCallback& callback) OVERRIDE; |
| 39 | virtual void PlatformGetFeatureReport(uint8_t report_id, |
| 40 | const ReadCallback& callback) OVERRIDE; |
| 41 | virtual void PlatformSendFeatureReport( |
| 42 | scoped_refptr<net::IOBuffer> buffer, |
| 43 | size_t size, |
| 44 | const WriteCallback& callback) OVERRIDE; |
| 45 | |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 46 | static void InputReportCallback(void* context, |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 47 | IOReturn result, |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 48 | void* sender, |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 49 | IOHIDReportType type, |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 50 | uint32_t report_id, |
| 51 | uint8_t* report_bytes, |
| 52 | CFIndex report_length); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 53 | |
| 54 | void WriteReport(IOHIDReportType type, |
Primiano Tucci | 1320f92 | 2014-09-30 14:45:55 +0100 | [diff] [blame^] | 55 | scoped_refptr<net::IOBuffer> buffer, |
| 56 | size_t size, |
| 57 | const WriteCallback& callback); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 58 | |
Ben Murdoch | 116680a | 2014-07-20 18:25:52 -0700 | [diff] [blame] | 59 | void Flush(); |
| 60 | void ProcessInputReport(scoped_refptr<net::IOBufferWithSize> buffer); |
| 61 | void ProcessReadQueue(); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 62 | |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 63 | base::ScopedCFTypeRef<IOHIDDeviceRef> device_; |
Ben Murdoch | 116680a | 2014-07-20 18:25:52 -0700 | [diff] [blame] | 64 | scoped_refptr<base::MessageLoopProxy> message_loop_; |
Primiano Tucci | 1320f92 | 2014-09-30 14:45:55 +0100 | [diff] [blame^] | 65 | std::vector<uint8_t> inbound_buffer_; |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 66 | |
| 67 | std::queue<PendingHidReport> pending_reports_; |
| 68 | std::queue<PendingHidRead> pending_reads_; |
| 69 | |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 70 | DISALLOW_COPY_AND_ASSIGN(HidConnectionMac); |
| 71 | }; |
| 72 | |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 73 | } // namespace device |
| 74 | |
| 75 | #endif // DEVICE_HID_HID_CONNECTION_MAC_H_ |