• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
8 #include <CoreFoundation/CoreFoundation.h>
9 #include <IOKit/hid/IOHIDManager.h>
10 
11 #include <queue>
12 
13 #include "base/mac/foundation_util.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "device/hid/hid_connection.h"
16 
17 namespace base {
18 class SingleThreadTaskRunner;
19 }
20 
21 namespace net {
22 class IOBuffer;
23 }
24 
25 namespace device {
26 
27 class HidConnectionMac : public HidConnection {
28  public:
29   explicit HidConnectionMac(
30       IOHIDDeviceRef device,
31       HidDeviceInfo device_info,
32       scoped_refptr<base::SingleThreadTaskRunner> file_task_runner);
33 
34  private:
35   virtual ~HidConnectionMac();
36 
37   // HidConnection implementation.
38   virtual void PlatformClose() OVERRIDE;
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 
50   static void InputReportCallback(void* context,
51                                   IOReturn result,
52                                   void* sender,
53                                   IOHIDReportType type,
54                                   uint32_t report_id,
55                                   uint8_t* report_bytes,
56                                   CFIndex report_length);
57   void ProcessInputReport(scoped_refptr<net::IOBufferWithSize> buffer);
58   void ProcessReadQueue();
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);
65 
66   base::ScopedCFTypeRef<IOHIDDeviceRef> device_;
67   scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
68   scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_;
69   std::vector<uint8_t> inbound_buffer_;
70 
71   std::queue<PendingHidReport> pending_reports_;
72   std::queue<PendingHidRead> pending_reads_;
73 
74   DISALLOW_COPY_AND_ASSIGN(HidConnectionMac);
75 };
76 
77 }  // namespace device
78 
79 #endif  // DEVICE_HID_HID_CONNECTION_MAC_H_
80