blob: 35fdd08e579a326454cc5f7be2196131eff0e27e [file] [log] [blame]
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +00001// 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)a1401312014-03-18 10:20:56 +00008#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)a1401312014-03-18 10:20:56 +000014#include "base/memory/scoped_ptr.h"
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +000015#include "device/hid/hid_connection.h"
Torne (Richard Coles)a1401312014-03-18 10:20:56 +000016
17namespace base {
Ben Murdoch1675a642014-10-22 18:55:17 +010018class SingleThreadTaskRunner;
Torne (Richard Coles)a1401312014-03-18 10:20:56 +000019}
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +000020
21namespace net {
22class IOBuffer;
23}
24
25namespace device {
26
27class HidConnectionMac : public HidConnection {
28 public:
Ben Murdoch1675a642014-10-22 18:55:17 +010029 explicit HidConnectionMac(
30 IOHIDDeviceRef device,
31 HidDeviceInfo device_info,
32 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner);
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +000033
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +000034 private:
35 virtual ~HidConnectionMac();
36
Primiano Tucci1320f922014-09-30 14:45:55 +010037 // HidConnection implementation.
Ben Murdoch1675a642014-10-22 18:55:17 +010038 virtual void PlatformClose() OVERRIDE;
Primiano Tucci1320f922014-09-30 14:45:55 +010039 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
Torne (Richard Coles)a1401312014-03-18 10:20:56 +000050 static void InputReportCallback(void* context,
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +000051 IOReturn result,
Torne (Richard Coles)a1401312014-03-18 10:20:56 +000052 void* sender,
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +000053 IOHIDReportType type,
Torne (Richard Coles)a1401312014-03-18 10:20:56 +000054 uint32_t report_id,
55 uint8_t* report_bytes,
56 CFIndex report_length);
Ben Murdoch116680a2014-07-20 18:25:52 -070057 void ProcessInputReport(scoped_refptr<net::IOBufferWithSize> buffer);
58 void ProcessReadQueue();
Ben Murdoch1675a642014-10-22 18:55:17 +010059 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);
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +000065
Torne (Richard Coles)a1401312014-03-18 10:20:56 +000066 base::ScopedCFTypeRef<IOHIDDeviceRef> device_;
Ben Murdoch1675a642014-10-22 18:55:17 +010067 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
68 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_;
Primiano Tucci1320f922014-09-30 14:45:55 +010069 std::vector<uint8_t> inbound_buffer_;
Torne (Richard Coles)a1401312014-03-18 10:20:56 +000070
71 std::queue<PendingHidReport> pending_reports_;
72 std::queue<PendingHidRead> pending_reads_;
73
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +000074 DISALLOW_COPY_AND_ASSIGN(HidConnectionMac);
75};
76
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +000077} // namespace device
78
79#endif // DEVICE_HID_HID_CONNECTION_MAC_H_