| 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 "base/threading/thread_checker.h" | 
| 13 #include "device/hid/hid_device_info.h" | 13 #include "device/hid/hid_device_info.h" | 
| 14 #include "net/base/io_buffer.h" | 14 #include "net/base/io_buffer.h" | 
| 15 | 15 | 
| 16 namespace device { | 16 namespace device { | 
| 17 | 17 | 
| 18 class HidConnection : public base::RefCountedThreadSafe<HidConnection> { | 18 class HidConnection : public base::RefCountedThreadSafe<HidConnection> { | 
| 19  public: | 19  public: | 
| 20   enum SpecialReportIds { | 20   enum SpecialReportIds { | 
| 21     kNullReportId = 0x00, | 21     kNullReportId = 0x00, | 
| 22     kAnyReportId = 0xFF, | 22     kAnyReportId = 0xFF, | 
| 23   }; | 23   }; | 
| 24 | 24 | 
| 25   typedef base::Callback< | 25   typedef base::Callback< | 
| 26       void(bool success, scoped_refptr<net::IOBuffer> buffer, size_t size)> | 26       void(bool success, scoped_refptr<net::IOBuffer> buffer, size_t size)> | 
| 27       ReadCallback; | 27       ReadCallback; | 
| 28   typedef base::Callback<void(bool success)> WriteCallback; | 28   typedef base::Callback<void(bool success)> WriteCallback; | 
| 29 | 29 | 
| 30   const HidDeviceInfo& device_info() const { return device_info_; } | 30   scoped_refptr<HidDeviceInfo> device_info() const { return device_info_; } | 
| 31   bool has_protected_collection() const { return has_protected_collection_; } | 31   bool has_protected_collection() const { return has_protected_collection_; } | 
| 32   const base::ThreadChecker& thread_checker() const { return thread_checker_; } | 32   const base::ThreadChecker& thread_checker() const { return thread_checker_; } | 
| 33   bool closed() const { return closed_; } | 33   bool closed() const { return closed_; } | 
| 34 | 34 | 
| 35   // Closes the connection. This must be called before the object is freed. | 35   // Closes the connection. This must be called before the object is freed. | 
| 36   void Close(); | 36   void Close(); | 
| 37 | 37 | 
| 38   // The report ID (or 0 if report IDs are not supported by the device) is | 38   // The report ID (or 0 if report IDs are not supported by the device) is | 
| 39   // always returned in the first byte of the buffer. | 39   // always returned in the first byte of the buffer. | 
| 40   void Read(const ReadCallback& callback); | 40   void Read(const ReadCallback& callback); | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
| 52 | 52 | 
| 53   // The report ID (or 0 if report IDs are not supported by the device) is | 53   // The report ID (or 0 if report IDs are not supported by the device) is | 
| 54   // always expected in the first byte of the buffer. | 54   // always expected in the first byte of the buffer. | 
| 55   void SendFeatureReport(scoped_refptr<net::IOBuffer> buffer, | 55   void SendFeatureReport(scoped_refptr<net::IOBuffer> buffer, | 
| 56                          size_t size, | 56                          size_t size, | 
| 57                          const WriteCallback& callback); | 57                          const WriteCallback& callback); | 
| 58 | 58 | 
| 59  protected: | 59  protected: | 
| 60   friend class base::RefCountedThreadSafe<HidConnection>; | 60   friend class base::RefCountedThreadSafe<HidConnection>; | 
| 61 | 61 | 
| 62   explicit HidConnection(const HidDeviceInfo& device_info); | 62   explicit HidConnection(scoped_refptr<HidDeviceInfo> device_info); | 
| 63   virtual ~HidConnection(); | 63   virtual ~HidConnection(); | 
| 64 | 64 | 
| 65   virtual void PlatformClose() = 0; | 65   virtual void PlatformClose() = 0; | 
| 66   virtual void PlatformRead(const ReadCallback& callback) = 0; | 66   virtual void PlatformRead(const ReadCallback& callback) = 0; | 
| 67   virtual void PlatformWrite(scoped_refptr<net::IOBuffer> buffer, | 67   virtual void PlatformWrite(scoped_refptr<net::IOBuffer> buffer, | 
| 68                              size_t size, | 68                              size_t size, | 
| 69                              const WriteCallback& callback) = 0; | 69                              const WriteCallback& callback) = 0; | 
| 70   virtual void PlatformGetFeatureReport(uint8_t report_id, | 70   virtual void PlatformGetFeatureReport(uint8_t report_id, | 
| 71                                         const ReadCallback& callback) = 0; | 71                                         const ReadCallback& callback) = 0; | 
| 72   virtual void PlatformSendFeatureReport(scoped_refptr<net::IOBuffer> buffer, | 72   virtual void PlatformSendFeatureReport(scoped_refptr<net::IOBuffer> buffer, | 
| 73                                          size_t size, | 73                                          size_t size, | 
| 74                                          const WriteCallback& callback) = 0; | 74                                          const WriteCallback& callback) = 0; | 
| 75 | 75 | 
| 76   // PlatformRead implementation must call this method on read | 76   // PlatformRead implementation must call this method on read | 
| 77   // success, rather than directly running the callback. | 77   // success, rather than directly running the callback. | 
| 78   // In case incoming buffer is empty or protected, it is filtered | 78   // In case incoming buffer is empty or protected, it is filtered | 
| 79   // and this method returns false. Otherwise it runs the callback | 79   // and this method returns false. Otherwise it runs the callback | 
| 80   // and returns true. | 80   // and returns true. | 
| 81   bool CompleteRead(scoped_refptr<net::IOBuffer> buffer, | 81   bool CompleteRead(scoped_refptr<net::IOBuffer> buffer, | 
| 82                     size_t size, | 82                     size_t size, | 
| 83                     const ReadCallback& callback); | 83                     const ReadCallback& callback); | 
| 84 | 84 | 
| 85  private: | 85  private: | 
| 86   bool IsReportIdProtected(uint8_t report_id); | 86   bool IsReportIdProtected(uint8_t report_id); | 
| 87 | 87 | 
| 88   const HidDeviceInfo device_info_; | 88   scoped_refptr<HidDeviceInfo> device_info_; | 
| 89   bool has_protected_collection_; | 89   bool has_protected_collection_; | 
| 90   base::ThreadChecker thread_checker_; | 90   base::ThreadChecker thread_checker_; | 
| 91   bool closed_; | 91   bool closed_; | 
| 92 | 92 | 
| 93   DISALLOW_COPY_AND_ASSIGN(HidConnection); | 93   DISALLOW_COPY_AND_ASSIGN(HidConnection); | 
| 94 }; | 94 }; | 
| 95 | 95 | 
| 96 struct PendingHidReport { | 96 struct PendingHidReport { | 
| 97   PendingHidReport(); | 97   PendingHidReport(); | 
| 98   ~PendingHidReport(); | 98   ~PendingHidReport(); | 
| 99 | 99 | 
| 100   scoped_refptr<net::IOBuffer> buffer; | 100   scoped_refptr<net::IOBuffer> buffer; | 
| 101   size_t size; | 101   size_t size; | 
| 102 }; | 102 }; | 
| 103 | 103 | 
| 104 struct PendingHidRead { | 104 struct PendingHidRead { | 
| 105   PendingHidRead(); | 105   PendingHidRead(); | 
| 106   ~PendingHidRead(); | 106   ~PendingHidRead(); | 
| 107 | 107 | 
| 108   HidConnection::ReadCallback callback; | 108   HidConnection::ReadCallback callback; | 
| 109 }; | 109 }; | 
| 110 | 110 | 
| 111 }  // namespace device | 111 }  // namespace device | 
| 112 | 112 | 
| 113 #endif  // DEVICE_HID_HID_CONNECTION_H_ | 113 #endif  // DEVICE_HID_HID_CONNECTION_H_ | 
| OLD | NEW | 
|---|