OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 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_H_ | 5 #ifndef DEVICE_HID_HID_CONNECTION_H_ |
6 #define DEVICE_HID_HID_CONNECTION_H_ | 6 #define DEVICE_HID_HID_CONNECTION_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/threading/thread_checker.h" | |
12 #include "device/hid/hid_device_info.h" | 13 #include "device/hid/hid_device_info.h" |
13 #include "net/base/io_buffer.h" | 14 #include "net/base/io_buffer.h" |
14 | 15 |
15 namespace device { | 16 namespace device { |
16 | 17 |
17 class HidConnection : public base::RefCountedThreadSafe<HidConnection> { | 18 class HidConnection : public base::RefCountedThreadSafe<HidConnection> { |
18 public: | 19 public: |
19 typedef base::Callback<void(bool success, size_t size)> IOCallback; | 20 typedef base::Callback<void(bool success, size_t size)> IOCallback; |
20 | 21 |
21 virtual void Read(scoped_refptr<net::IOBufferWithSize> buffer, | 22 const HidDeviceInfo& device_info() const { return device_info_; } |
22 const IOCallback& callback) = 0; | 23 bool has_protected_collection() const { return has_protected_collection_; } |
23 virtual void Write(uint8_t report_id, | 24 bool has_report_id() const { return has_report_id_; } |
24 scoped_refptr<net::IOBufferWithSize> buffer, | 25 const base::ThreadChecker& thread_checker() const { return thread_checker_; } |
25 const IOCallback& callback) = 0; | |
26 virtual void GetFeatureReport(uint8_t report_id, | |
27 scoped_refptr<net::IOBufferWithSize> buffer, | |
28 const IOCallback& callback) = 0; | |
29 virtual void SendFeatureReport(uint8_t report_id, | |
30 scoped_refptr<net::IOBufferWithSize> buffer, | |
31 const IOCallback& callback) = 0; | |
32 | 26 |
33 const HidDeviceInfo& device_info() const { return device_info_; } | 27 void Read(scoped_refptr<net::IOBufferWithSize> buffer, |
28 const IOCallback& callback); | |
29 void Write(uint8_t report_id, | |
30 scoped_refptr<net::IOBufferWithSize> buffer, | |
31 const IOCallback& callback); | |
32 void GetFeatureReport(uint8_t report_id, | |
33 scoped_refptr<net::IOBufferWithSize> buffer, | |
34 const IOCallback& callback); | |
35 void SendFeatureReport(uint8_t report_id, | |
36 scoped_refptr<net::IOBufferWithSize> buffer, | |
37 const IOCallback& callback); | |
34 | 38 |
35 protected: | 39 protected: |
36 friend class base::RefCountedThreadSafe<HidConnection>; | 40 friend class base::RefCountedThreadSafe<HidConnection>; |
37 friend struct HidDeviceInfo; | |
38 | 41 |
39 explicit HidConnection(const HidDeviceInfo& device_info); | 42 explicit HidConnection(const HidDeviceInfo& device_info); |
40 virtual ~HidConnection(); | 43 virtual ~HidConnection(); |
41 | 44 |
45 virtual void PlatformRead(scoped_refptr<net::IOBufferWithSize> buffer, | |
46 const IOCallback& callback) = 0; | |
47 virtual void PlatformWrite(uint8_t report_id, | |
48 scoped_refptr<net::IOBufferWithSize> buffer, | |
49 const IOCallback& callback) = 0; | |
50 virtual void PlatformGetFeatureReport( | |
51 uint8_t report_id, | |
52 scoped_refptr<net::IOBufferWithSize> buffer, | |
53 const IOCallback& callback) = 0; | |
54 virtual void PlatformSendFeatureReport( | |
55 uint8_t report_id, | |
56 scoped_refptr<net::IOBufferWithSize> buffer, | |
57 const IOCallback& callback) = 0; | |
58 | |
59 void CompleteRead(scoped_refptr<net::IOBufferWithSize> buffer, | |
Ken Rockot(use gerrit already)
2014/06/27 14:50:22
Please document that platform implementations must
jracle (use Gerrit)
2014/06/27 20:07:06
Sure.
On 2014/06/27 14:50:22, Ken Rockot wrote:
| |
60 const IOCallback& callback); | |
61 | |
42 private: | 62 private: |
63 bool FilterInputReport(scoped_refptr<net::IOBufferWithSize> buffer, | |
64 const IOCallback& callback); | |
65 | |
66 bool IsReportIdProtected(const uint8_t report_id); | |
67 | |
43 const HidDeviceInfo device_info_; | 68 const HidDeviceInfo device_info_; |
69 bool has_report_id_; | |
70 bool has_protected_collection_; | |
71 base::ThreadChecker thread_checker_; | |
44 | 72 |
45 DISALLOW_COPY_AND_ASSIGN(HidConnection); | 73 DISALLOW_COPY_AND_ASSIGN(HidConnection); |
46 }; | 74 }; |
47 | 75 |
48 struct PendingHidReport { | 76 struct PendingHidReport { |
49 PendingHidReport(); | 77 PendingHidReport(); |
50 ~PendingHidReport(); | 78 ~PendingHidReport(); |
51 | 79 |
52 scoped_refptr<net::IOBufferWithSize> buffer; | 80 scoped_refptr<net::IOBufferWithSize> buffer; |
53 }; | 81 }; |
54 | 82 |
55 struct PendingHidRead { | 83 struct PendingHidRead { |
56 PendingHidRead(); | 84 PendingHidRead(); |
57 ~PendingHidRead(); | 85 ~PendingHidRead(); |
58 | 86 |
59 scoped_refptr<net::IOBufferWithSize> buffer; | 87 scoped_refptr<net::IOBufferWithSize> buffer; |
60 HidConnection::IOCallback callback; | 88 HidConnection::IOCallback callback; |
61 }; | 89 }; |
62 | 90 |
63 } // namespace device | 91 } // namespace device |
64 | 92 |
65 #endif // DEVICE_HID_HID_CONNECTION_H_ | 93 #endif // DEVICE_HID_HID_CONNECTION_H_ |
OLD | NEW |