Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Side by Side Diff: device/hid/hid_connection_mac.h

Issue 161823002: Clean up HID backend and API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « device/hid/hid_connection_linux.cc ('k') | device/hid/hid_connection_mac.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef DEVICE_HID_HID_CONNECTION_MAC_H_ 5 #ifndef DEVICE_HID_HID_CONNECTION_MAC_H_
6 #define DEVICE_HID_HID_CONNECTION_MAC_H_ 6 #define DEVICE_HID_HID_CONNECTION_MAC_H_
7 7
8 #include "base/callback.h" 8 #include <CoreFoundation/CoreFoundation.h>
9 #include <IOKit/hid/IOHIDManager.h>
10
11 #include <queue>
12
13 #include "base/mac/foundation_util.h"
9 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
10 #include "base/tuple.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/threading/thread_checker.h"
11 #include "device/hid/hid_connection.h" 17 #include "device/hid/hid_connection.h"
12 #include "device/hid/hid_device_info.h" 18 #include "device/hid/hid_device_info.h"
13 #include "device/hid/hid_service_mac.h" 19
20 namespace base {
21 class MessageLoopProxy;
22 }
14 23
15 namespace net { 24 namespace net {
16 class IOBuffer; 25 class IOBuffer;
17 } 26 }
18 27
19 namespace device { 28 namespace device {
20 29
21 class HidConnectionMac : public HidConnection { 30 class HidConnectionMac : public HidConnection {
22 public: 31 public:
23 HidConnectionMac(HidServiceMac* service, 32 explicit HidConnectionMac(HidDeviceInfo device_info);
24 HidDeviceInfo device_info,
25 IOHIDDeviceRef device);
26 33
27 virtual void Read(scoped_refptr<net::IOBuffer> buffer, 34 virtual void Read(scoped_refptr<net::IOBufferWithSize> buffer,
28 size_t size,
29 const IOCallback& callback) OVERRIDE; 35 const IOCallback& callback) OVERRIDE;
30 virtual void Write(scoped_refptr<net::IOBuffer> buffer, 36 virtual void Write(uint8_t report_id,
31 size_t size, 37 scoped_refptr<net::IOBufferWithSize> buffer,
32 const IOCallback& callback) OVERRIDE; 38 const IOCallback& callback) OVERRIDE;
33 virtual void GetFeatureReport(scoped_refptr<net::IOBuffer> buffer, 39 virtual void GetFeatureReport(uint8_t report_id,
34 size_t size, 40 scoped_refptr<net::IOBufferWithSize> buffer,
35 const IOCallback& callback) OVERRIDE; 41 const IOCallback& callback) OVERRIDE;
36 virtual void SendFeatureReport(scoped_refptr<net::IOBuffer> buffer, 42 virtual void SendFeatureReport(uint8_t report_id,
37 size_t size, 43 scoped_refptr<net::IOBufferWithSize> buffer,
38 const IOCallback& callback) OVERRIDE; 44 const IOCallback& callback) OVERRIDE;
39 45
40 private: 46 private:
41 virtual ~HidConnectionMac(); 47 virtual ~HidConnectionMac();
42 48
43 static void InputReportCallback(void * context, 49 static void InputReportCallback(void* context,
44 IOReturn result, 50 IOReturn result,
45 void * sender, 51 void* sender,
46 IOHIDReportType type, 52 IOHIDReportType type,
47 uint32_t reportID, 53 uint32_t report_id,
48 uint8_t * report, 54 uint8_t* report_bytes,
49 CFIndex reportLength); 55 CFIndex report_length);
50 void ProcessReadQueue(); 56 void ProcessReadQueue();
51 void ProcessInputReport(IOHIDReportType type, 57 void ProcessInputReport(IOHIDReportType type,
52 scoped_refptr<net::IOBuffer> report, 58 scoped_refptr<net::IOBufferWithSize> buffer);
53 CFIndex reportLength);
54 59
55 void WriteReport(IOHIDReportType type, 60 void WriteReport(IOHIDReportType type,
56 scoped_refptr<net::IOBuffer> buffer, 61 uint8_t report_id,
57 size_t size, 62 scoped_refptr<net::IOBufferWithSize> buffer,
58 const IOCallback& callback); 63 const IOCallback& callback);
59 64
60 HidServiceMac* service_;
61 scoped_refptr<base::MessageLoopProxy> message_loop_; 65 scoped_refptr<base::MessageLoopProxy> message_loop_;
66
62 base::ScopedCFTypeRef<IOHIDDeviceRef> device_; 67 base::ScopedCFTypeRef<IOHIDDeviceRef> device_;
63 scoped_ptr<uint8_t, base::FreeDeleter> inbound_buffer_; 68 scoped_ptr<uint8_t, base::FreeDeleter> inbound_buffer_;
64 bool disconnected_;
65 69
66 typedef std::pair<scoped_refptr<net::IOBuffer>, size_t> PendingReport; 70 std::queue<PendingHidReport> pending_reports_;
67 std::queue<PendingReport> input_reports_; 71 std::queue<PendingHidRead> pending_reads_;
68 typedef Tuple3<scoped_refptr<net::IOBuffer>, size_t, IOCallback> PendingRead; 72
69 std::queue<PendingRead> read_queue_; 73 base::ThreadChecker thread_checker_;
70 74
71 DISALLOW_COPY_AND_ASSIGN(HidConnectionMac); 75 DISALLOW_COPY_AND_ASSIGN(HidConnectionMac);
72 }; 76 };
73 77
74 78
75 } // namespace device 79 } // namespace device
76 80
77 #endif // DEVICE_HID_HID_CONNECTION_MAC_H_ 81 #endif // DEVICE_HID_HID_CONNECTION_MAC_H_
OLDNEW
« no previous file with comments | « device/hid/hid_connection_linux.cc ('k') | device/hid/hid_connection_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698