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/ref_counted.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/threading/thread_checker.h"
17 #include "device/hid/hid_connection.h"
18 #include "device/hid/hid_device_info.h"
21 class MessageLoopProxy
;
30 class HidConnectionMac
: public HidConnection
{
32 explicit HidConnectionMac(HidDeviceInfo device_info
);
34 virtual void Read(scoped_refptr
<net::IOBufferWithSize
> buffer
,
35 const IOCallback
& callback
) OVERRIDE
;
36 virtual void Write(uint8_t report_id
,
37 scoped_refptr
<net::IOBufferWithSize
> buffer
,
38 const IOCallback
& callback
) OVERRIDE
;
39 virtual void GetFeatureReport(uint8_t report_id
,
40 scoped_refptr
<net::IOBufferWithSize
> buffer
,
41 const IOCallback
& callback
) OVERRIDE
;
42 virtual void SendFeatureReport(uint8_t report_id
,
43 scoped_refptr
<net::IOBufferWithSize
> buffer
,
44 const IOCallback
& callback
) OVERRIDE
;
47 virtual ~HidConnectionMac();
49 static void InputReportCallback(void* context
,
54 uint8_t* report_bytes
,
55 CFIndex report_length
);
56 void ProcessReadQueue();
57 void ProcessInputReport(IOHIDReportType type
,
58 scoped_refptr
<net::IOBufferWithSize
> buffer
);
60 void WriteReport(IOHIDReportType type
,
62 scoped_refptr
<net::IOBufferWithSize
> buffer
,
63 const IOCallback
& callback
);
65 scoped_refptr
<base::MessageLoopProxy
> message_loop_
;
67 base::ScopedCFTypeRef
<IOHIDDeviceRef
> device_
;
68 scoped_ptr
<uint8_t, base::FreeDeleter
> inbound_buffer_
;
70 std::queue
<PendingHidReport
> pending_reports_
;
71 std::queue
<PendingHidRead
> pending_reads_
;
73 base::ThreadChecker thread_checker_
;
75 DISALLOW_COPY_AND_ASSIGN(HidConnectionMac
);
81 #endif // DEVICE_HID_HID_CONNECTION_MAC_H_