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 <queue> | |
| 11 | |
| 10 #include "base/callback.h" | 12 #include "base/callback.h" |
| 11 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/threading/thread_checker.h" | |
| 12 #include "device/hid/hid_device_info.h" | 15 #include "device/hid/hid_device_info.h" |
| 13 #include "net/base/io_buffer.h" | 16 #include "net/base/io_buffer.h" |
| 14 | 17 |
| 15 namespace device { | 18 namespace device { |
| 16 | 19 |
| 17 class HidConnection : public base::RefCountedThreadSafe<HidConnection> { | 20 class HidConnection : public base::RefCountedThreadSafe<HidConnection> { |
| 18 public: | 21 public: |
| 19 typedef base::Callback<void(bool success, size_t size)> IOCallback; | 22 typedef base::Callback<void(bool success, size_t size)> IOCallback; |
| 20 | 23 |
| 21 virtual void Read(scoped_refptr<net::IOBufferWithSize> buffer, | 24 const HidDeviceInfo& device_info() const { return device_info_; } |
| 22 const IOCallback& callback) = 0; | 25 bool has_protected_collection() const { return has_protected_collection_; } |
| 23 virtual void Write(uint8_t report_id, | 26 bool has_report_id() const { return has_report_id_; } |
| 24 scoped_refptr<net::IOBufferWithSize> buffer, | 27 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 | 28 |
| 33 const HidDeviceInfo& device_info() const { return device_info_; } | 29 void Read(scoped_refptr<net::IOBufferWithSize> buffer, |
|
jracle (use Gerrit)
2014/06/11 11:20:04
I made those methods the single entry-point, and c
Ken Rockot(use gerrit already)
2014/06/19 19:29:57
Great!
| |
| 30 const IOCallback& callback); | |
| 31 void Write(uint8_t report_id, | |
| 32 scoped_refptr<net::IOBufferWithSize> buffer, | |
| 33 const IOCallback& callback); | |
| 34 void GetFeatureReport(uint8_t report_id, | |
| 35 scoped_refptr<net::IOBufferWithSize> buffer, | |
| 36 const IOCallback& callback); | |
| 37 void SendFeatureReport(uint8_t report_id, | |
| 38 scoped_refptr<net::IOBufferWithSize> buffer, | |
| 39 const IOCallback& callback); | |
| 34 | 40 |
| 35 protected: | 41 protected: |
| 36 friend class base::RefCountedThreadSafe<HidConnection>; | 42 friend class base::RefCountedThreadSafe<HidConnection>; |
| 37 friend struct HidDeviceInfo; | |
| 38 | 43 |
| 39 explicit HidConnection(const HidDeviceInfo& device_info); | 44 explicit HidConnection(const HidDeviceInfo& device_info); |
| 40 virtual ~HidConnection(); | 45 virtual ~HidConnection(); |
| 41 | 46 |
| 47 virtual void PlatformRead(scoped_refptr<net::IOBufferWithSize> buffer, | |
| 48 const IOCallback& callback) = 0; | |
| 49 virtual void PlatformWrite(uint8_t report_id, | |
| 50 scoped_refptr<net::IOBufferWithSize> buffer, | |
| 51 const IOCallback& callback) = 0; | |
| 52 virtual void PlatformGetFeatureReport( | |
| 53 uint8_t report_id, | |
| 54 scoped_refptr<net::IOBufferWithSize> buffer, | |
| 55 const IOCallback& callback) = 0; | |
| 56 virtual void PlatformSendFeatureReport( | |
| 57 uint8_t report_id, | |
| 58 scoped_refptr<net::IOBufferWithSize> buffer, | |
| 59 const IOCallback& callback) = 0; | |
| 60 | |
| 61 bool FilterInputReport(scoped_refptr<net::IOBufferWithSize> buffer, | |
|
Ken Rockot(use gerrit already)
2014/06/19 19:29:56
Can this be private?
| |
| 62 const IOCallback& callback); | |
| 63 | |
| 42 private: | 64 private: |
| 65 bool IsReportIdProtected(const uint8_t report_id); | |
| 66 | |
| 43 const HidDeviceInfo device_info_; | 67 const HidDeviceInfo device_info_; |
| 68 bool has_report_id_; | |
| 69 bool has_protected_collection_; | |
| 70 base::ThreadChecker thread_checker_; | |
| 44 | 71 |
| 45 DISALLOW_COPY_AND_ASSIGN(HidConnection); | 72 DISALLOW_COPY_AND_ASSIGN(HidConnection); |
| 46 }; | 73 }; |
| 47 | 74 |
| 48 struct PendingHidReport { | 75 struct PendingHidReport { |
|
jracle (use Gerrit)
2014/06/11 11:20:04
I'm very incomfortable with those 2 structs. Their
Ken Rockot(use gerrit already)
2014/06/19 19:29:57
I agree they could be cleaned up, but I'd recommen
jracle (use Gerrit)
2014/06/19 21:39:36
Agree we should keep them in this CL, that'd be to
| |
| 49 PendingHidReport(); | 76 PendingHidReport(); |
| 50 ~PendingHidReport(); | 77 ~PendingHidReport(); |
| 51 | 78 |
| 52 scoped_refptr<net::IOBufferWithSize> buffer; | 79 scoped_refptr<net::IOBufferWithSize> buffer; |
| 53 }; | 80 }; |
| 54 | 81 |
| 55 struct PendingHidRead { | 82 struct PendingHidRead { |
| 56 PendingHidRead(); | 83 PendingHidRead(); |
| 57 ~PendingHidRead(); | 84 ~PendingHidRead(); |
| 58 | 85 |
| 59 scoped_refptr<net::IOBufferWithSize> buffer; | 86 scoped_refptr<net::IOBufferWithSize> buffer; |
| 60 HidConnection::IOCallback callback; | 87 HidConnection::IOCallback callback; |
| 61 }; | 88 }; |
| 62 | 89 |
| 90 class HidConnection2 : public HidConnection { | |
|
jracle (use Gerrit)
2014/06/11 11:20:04
This is of course 'temporary code' before refactor
Ken Rockot(use gerrit already)
2014/06/19 19:29:56
I am very confused by this.
jracle (use Gerrit)
2014/06/19 21:39:36
Code duplication removal.
On 2014/06/19 19:29:56,
| |
| 91 protected: | |
| 92 explicit HidConnection2(const HidDeviceInfo& device_info); | |
| 93 virtual ~HidConnection2(); | |
| 94 | |
| 95 // HidConnection implementation. | |
| 96 virtual void PlatformRead(scoped_refptr<net::IOBufferWithSize> buffer, | |
| 97 const IOCallback& callback) OVERRIDE; | |
| 98 | |
| 99 void ProcessInputReport(scoped_refptr<net::IOBufferWithSize> buffer); | |
| 100 void Flush(); | |
| 101 | |
| 102 private: | |
| 103 void ProcessReadQueue(); | |
| 104 | |
| 105 std::queue<PendingHidReport> pending_reports_; | |
|
jracle (use Gerrit)
2014/06/11 11:20:04
see above comments
| |
| 106 std::queue<PendingHidRead> pending_reads_; | |
| 107 }; | |
| 108 | |
| 63 } // namespace device | 109 } // namespace device |
| 64 | 110 |
| 65 #endif // DEVICE_HID_HID_CONNECTION_H_ | 111 #endif // DEVICE_HID_HID_CONNECTION_H_ |
| OLD | NEW |