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

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: Many cleanup, such device ID, woww. Created 6 years, 10 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
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"
15 #include "base/memory/scoped_ptr.h"
10 #include "base/tuple.h" 16 #include "base/tuple.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"
14 19
15 namespace net { 20 namespace net {
16 class IOBuffer; 21 class IOBuffer;
17 } 22 }
18 23
19 namespace device { 24 namespace device {
20 25
26 class HidServiceMac;
27
21 class HidConnectionMac : public HidConnection { 28 class HidConnectionMac : public HidConnection {
22 public: 29 public:
23 HidConnectionMac(HidServiceMac* service, 30 HidConnectionMac(HidServiceMac* service,
24 HidDeviceInfo device_info, 31 HidDeviceInfo device_info,
25 IOHIDDeviceRef device); 32 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(scoped_refptr<net::IOBufferWithSize> buffer,
31 size_t size,
32 const IOCallback& callback) OVERRIDE; 37 const IOCallback& callback) OVERRIDE;
33 virtual void GetFeatureReport(scoped_refptr<net::IOBuffer> buffer, 38 virtual void GetFeatureReport(scoped_refptr<net::IOBufferWithSize> buffer,
34 size_t size,
35 const IOCallback& callback) OVERRIDE; 39 const IOCallback& callback) OVERRIDE;
36 virtual void SendFeatureReport(scoped_refptr<net::IOBuffer> buffer, 40 virtual void SendFeatureReport(scoped_refptr<net::IOBufferWithSize> buffer,
37 size_t size,
38 const IOCallback& callback) OVERRIDE; 41 const IOCallback& callback) OVERRIDE;
39 42
40 private: 43 private:
41 virtual ~HidConnectionMac(); 44 virtual ~HidConnectionMac();
42 45
43 static void InputReportCallback(void * context, 46 static void InputReportCallback(void* context,
44 IOReturn result, 47 IOReturn result,
45 void * sender, 48 void* sender,
46 IOHIDReportType type, 49 IOHIDReportType type,
47 uint32_t reportID, 50 uint32_t report_id,
48 uint8_t * report, 51 uint8_t* report_bytes,
49 CFIndex reportLength); 52 CFIndex report_length);
50 void ProcessReadQueue(); 53 void ProcessReadQueue();
51 void ProcessInputReport(IOHIDReportType type, 54 void ProcessInputReport(IOHIDReportType type,
52 scoped_refptr<net::IOBuffer> report, 55 scoped_refptr<net::IOBufferWithSize> buffer);
53 CFIndex reportLength);
54 56
55 void WriteReport(IOHIDReportType type, 57 void WriteReport(IOHIDReportType type,
56 scoped_refptr<net::IOBuffer> buffer, 58 scoped_refptr<net::IOBufferWithSize> buffer,
57 size_t size,
58 const IOCallback& callback); 59 const IOCallback& callback);
59 60
61 // The HidService that created this connection. Not owned.
60 HidServiceMac* service_; 62 HidServiceMac* service_;
63
61 scoped_refptr<base::MessageLoopProxy> message_loop_; 64 scoped_refptr<base::MessageLoopProxy> message_loop_;
65
62 base::ScopedCFTypeRef<IOHIDDeviceRef> device_; 66 base::ScopedCFTypeRef<IOHIDDeviceRef> device_;
63 scoped_ptr_malloc<uint8_t> inbound_buffer_; 67 scoped_ptr_malloc<uint8_t> inbound_buffer_;
64 bool disconnected_;
65 68
66 typedef std::pair<scoped_refptr<net::IOBuffer>, size_t> PendingReport; 69 std::queue<PendingHidReport> pending_reports_;
67 std::queue<PendingReport> input_reports_; 70 std::queue<PendingHidRead> pending_reads_;
68 typedef Tuple3<scoped_refptr<net::IOBuffer>, size_t, IOCallback> PendingRead;
69 std::queue<PendingRead> read_queue_;
70 71
71 DISALLOW_COPY_AND_ASSIGN(HidConnectionMac); 72 DISALLOW_COPY_AND_ASSIGN(HidConnectionMac);
72 }; 73 };
73 74
74 75
75 } // namespace device 76 } // namespace device
76 77
77 #endif // DEVICE_HID_HID_CONNECTION_MAC_H_ 78 #endif // DEVICE_HID_HID_CONNECTION_MAC_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698