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.
5 #ifndef DEVICE_HID_HID_CONNECTION_MAC_H_
6 #define DEVICE_HID_HID_CONNECTION_MAC_H_
8 #include <CoreFoundation/CoreFoundation.h>
9 #include <IOKit/hid/IOHIDManager.h>
13 #include "base/mac/foundation_util.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "device/hid/hid_connection.h"
18 class SingleThreadTaskRunner
;
27 class HidConnectionMac
: public HidConnection
{
30 IOHIDDeviceRef device
,
31 scoped_refptr
<HidDeviceInfo
> device_info
,
32 scoped_refptr
<base::SingleThreadTaskRunner
> file_task_runner
);
35 ~HidConnectionMac() override
;
37 // HidConnection implementation.
38 void PlatformClose() override
;
39 void PlatformRead(const ReadCallback
& callback
) override
;
40 void PlatformWrite(scoped_refptr
<net::IOBuffer
> buffer
,
42 const WriteCallback
& callback
) override
;
43 void PlatformGetFeatureReport(uint8_t report_id
,
44 const ReadCallback
& callback
) override
;
45 void PlatformSendFeatureReport(scoped_refptr
<net::IOBuffer
> buffer
,
47 const WriteCallback
& callback
) override
;
49 static void InputReportCallback(void* context
,
54 uint8_t* report_bytes
,
55 CFIndex report_length
);
56 void ProcessInputReport(scoped_refptr
<net::IOBufferWithSize
> buffer
);
57 void ProcessReadQueue();
58 void GetFeatureReportAsync(uint8_t report_id
, const ReadCallback
& callback
);
59 void SetReportAsync(IOHIDReportType report_type
,
60 scoped_refptr
<net::IOBuffer
> buffer
,
62 const WriteCallback
& callback
);
63 void ReturnAsyncResult(const base::Closure
& callback
);
65 base::ScopedCFTypeRef
<IOHIDDeviceRef
> device_
;
66 scoped_refptr
<base::SingleThreadTaskRunner
> task_runner_
;
67 scoped_refptr
<base::SingleThreadTaskRunner
> file_task_runner_
;
68 std::vector
<uint8_t> inbound_buffer_
;
70 std::queue
<PendingHidReport
> pending_reports_
;
71 std::queue
<PendingHidRead
> pending_reads_
;
73 DISALLOW_COPY_AND_ASSIGN(HidConnectionMac
);
78 #endif // DEVICE_HID_HID_CONNECTION_MAC_H_