Chromium Code Reviews| 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: |
| 20 enum SpecialReportIds { | |
| 21 kNullReportId = 0x00, | |
| 22 kAnyReportId = 0xFF, | |
| 23 }; | |
| 24 | |
| 19 typedef base::Callback<void(bool success, size_t size)> IOCallback; | 25 typedef base::Callback<void(bool success, size_t size)> IOCallback; |
| 20 | 26 |
| 21 virtual void Read(scoped_refptr<net::IOBufferWithSize> buffer, | 27 const HidDeviceInfo& device_info() const { return device_info_; } |
| 22 const IOCallback& callback) = 0; | 28 bool has_protected_collection() const { return has_protected_collection_; } |
| 23 virtual void Write(uint8_t report_id, | 29 bool has_report_id() const { return has_report_id_; } |
| 24 scoped_refptr<net::IOBufferWithSize> buffer, | 30 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 | 31 |
| 33 const HidDeviceInfo& device_info() const { return device_info_; } | 32 void Read(scoped_refptr<net::IOBufferWithSize> buffer, |
| 33 const IOCallback& callback); | |
| 34 void Write(uint8_t report_id, | |
| 35 scoped_refptr<net::IOBufferWithSize> buffer, | |
| 36 const IOCallback& callback); | |
| 37 void GetFeatureReport(uint8_t report_id, | |
| 38 scoped_refptr<net::IOBufferWithSize> buffer, | |
| 39 const IOCallback& callback); | |
| 40 void SendFeatureReport(uint8_t report_id, | |
| 41 scoped_refptr<net::IOBufferWithSize> buffer, | |
| 42 const IOCallback& callback); | |
| 34 | 43 |
| 35 protected: | 44 protected: |
| 36 friend class base::RefCountedThreadSafe<HidConnection>; | 45 friend class base::RefCountedThreadSafe<HidConnection>; |
| 37 friend struct HidDeviceInfo; | |
| 38 | 46 |
| 39 explicit HidConnection(const HidDeviceInfo& device_info); | 47 explicit HidConnection(const HidDeviceInfo& device_info); |
| 40 virtual ~HidConnection(); | 48 virtual ~HidConnection(); |
| 41 | 49 |
| 50 virtual void PlatformRead(scoped_refptr<net::IOBufferWithSize> buffer, | |
| 51 const IOCallback& callback) = 0; | |
| 52 virtual void PlatformWrite(uint8_t report_id, | |
| 53 scoped_refptr<net::IOBufferWithSize> buffer, | |
| 54 const IOCallback& callback) = 0; | |
| 55 virtual void PlatformGetFeatureReport( | |
| 56 uint8_t report_id, | |
| 57 scoped_refptr<net::IOBufferWithSize> buffer, | |
| 58 const IOCallback& callback) = 0; | |
| 59 virtual void PlatformSendFeatureReport( | |
| 60 uint8_t report_id, | |
| 61 scoped_refptr<net::IOBufferWithSize> buffer, | |
| 62 const IOCallback& callback) = 0; | |
| 63 | |
| 64 // PlatformRead implementation must call this method on read | |
| 65 // success, rather than directly running the callback. | |
| 66 // It filters protected reports, running the callback with an | |
| 67 // empty buffer in such case. | |
|
Ken Rockot(use gerrit already)
2014/06/30 15:19:46
"It filters protected reports and runs the callbac
jracle (use Gerrit)
2014/06/30 15:38:39
Sure.
On 2014/06/30 15:19:46, Ken Rockot wrote:
| |
| 68 void CompleteRead(scoped_refptr<net::IOBufferWithSize> buffer, | |
| 69 const IOCallback& callback); | |
| 70 | |
| 42 private: | 71 private: |
| 72 bool FilterInputReport(scoped_refptr<net::IOBufferWithSize> buffer, | |
| 73 const IOCallback& callback); | |
| 74 | |
| 75 bool IsReportIdProtected(const uint8_t report_id); | |
| 76 | |
| 43 const HidDeviceInfo device_info_; | 77 const HidDeviceInfo device_info_; |
| 78 bool has_report_id_; | |
| 79 bool has_protected_collection_; | |
| 80 base::ThreadChecker thread_checker_; | |
| 44 | 81 |
| 45 DISALLOW_COPY_AND_ASSIGN(HidConnection); | 82 DISALLOW_COPY_AND_ASSIGN(HidConnection); |
| 46 }; | 83 }; |
| 47 | 84 |
| 48 struct PendingHidReport { | 85 struct PendingHidReport { |
| 49 PendingHidReport(); | 86 PendingHidReport(); |
| 50 ~PendingHidReport(); | 87 ~PendingHidReport(); |
| 51 | 88 |
| 52 scoped_refptr<net::IOBufferWithSize> buffer; | 89 scoped_refptr<net::IOBufferWithSize> buffer; |
| 53 }; | 90 }; |
| 54 | 91 |
| 55 struct PendingHidRead { | 92 struct PendingHidRead { |
| 56 PendingHidRead(); | 93 PendingHidRead(); |
| 57 ~PendingHidRead(); | 94 ~PendingHidRead(); |
| 58 | 95 |
| 59 scoped_refptr<net::IOBufferWithSize> buffer; | 96 scoped_refptr<net::IOBufferWithSize> buffer; |
| 60 HidConnection::IOCallback callback; | 97 HidConnection::IOCallback callback; |
| 61 }; | 98 }; |
| 62 | 99 |
| 63 } // namespace device | 100 } // namespace device |
| 64 | 101 |
| 65 #endif // DEVICE_HID_HID_CONNECTION_H_ | 102 #endif // DEVICE_HID_HID_CONNECTION_H_ |
| OLD | NEW |