Upstream version 10.38.208.0
[platform/framework/web/crosswalk.git] / src / device / hid / hid_connection_mac.h
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 MessageLoopProxy;
19 }
20
21 namespace net {
22 class IOBuffer;
23 }
24
25 namespace device {
26
27 class HidConnectionMac : public HidConnection {
28  public:
29   explicit HidConnectionMac(HidDeviceInfo device_info);
30
31   // HidConnection implementation.
32   virtual void PlatformRead(scoped_refptr<net::IOBufferWithSize> buffer,
33                             const IOCallback& callback) OVERRIDE;
34   virtual void PlatformWrite(uint8_t report_id,
35                              scoped_refptr<net::IOBufferWithSize> buffer,
36                              const IOCallback& callback) OVERRIDE;
37   virtual void PlatformGetFeatureReport(
38       uint8_t report_id,
39       scoped_refptr<net::IOBufferWithSize> buffer,
40       const IOCallback& callback) OVERRIDE;
41   virtual void PlatformSendFeatureReport(
42       uint8_t report_id,
43       scoped_refptr<net::IOBufferWithSize> buffer,
44       const IOCallback& callback) OVERRIDE;
45
46  private:
47   virtual ~HidConnectionMac();
48
49   static void InputReportCallback(void* context,
50                                   IOReturn result,
51                                   void* sender,
52                                   IOHIDReportType type,
53                                   uint32_t report_id,
54                                   uint8_t* report_bytes,
55                                   CFIndex report_length);
56
57   void WriteReport(IOHIDReportType type,
58                    uint8_t report_id,
59                    scoped_refptr<net::IOBufferWithSize> buffer,
60                    const IOCallback& callback);
61
62   void Flush();
63   void ProcessInputReport(scoped_refptr<net::IOBufferWithSize> buffer);
64   void ProcessReadQueue();
65
66   base::ScopedCFTypeRef<IOHIDDeviceRef> device_;
67   scoped_refptr<base::MessageLoopProxy> message_loop_;
68   std::vector<uint8_t> inbound_buffer_;
69
70   std::queue<PendingHidReport> pending_reports_;
71   std::queue<PendingHidRead> pending_reads_;
72
73   DISALLOW_COPY_AND_ASSIGN(HidConnectionMac);
74 };
75
76 }  // namespace device
77
78 #endif  // DEVICE_HID_HID_CONNECTION_MAC_H_