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

Side by Side Diff: trunk/src/device/hid/hid_connection.h

Issue 369923002: Revert 281133 "chrome.hid: enrich model with report IDs" (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 5 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
« no previous file with comments | « trunk/src/device/hid/hid_collection_info.cc ('k') | trunk/src/device/hid/hid_connection.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
13 #include "device/hid/hid_device_info.h" 12 #include "device/hid/hid_device_info.h"
14 #include "net/base/io_buffer.h" 13 #include "net/base/io_buffer.h"
15 14
16 namespace device { 15 namespace device {
17 16
18 class HidConnection : public base::RefCountedThreadSafe<HidConnection> { 17 class HidConnection : public base::RefCountedThreadSafe<HidConnection> {
19 public: 18 public:
20 enum SpecialReportIds {
21 kNullReportId = 0x00,
22 kAnyReportId = 0xFF,
23 };
24
25 typedef base::Callback<void(bool success, size_t size)> IOCallback; 19 typedef base::Callback<void(bool success, size_t size)> IOCallback;
26 20
21 virtual void Read(scoped_refptr<net::IOBufferWithSize> buffer,
22 const IOCallback& callback) = 0;
23 virtual void Write(uint8_t report_id,
24 scoped_refptr<net::IOBufferWithSize> buffer,
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
27 const HidDeviceInfo& device_info() const { return device_info_; } 33 const HidDeviceInfo& device_info() const { return device_info_; }
28 bool has_protected_collection() const { return has_protected_collection_; }
29 bool has_report_id() const { return has_report_id_; }
30 const base::ThreadChecker& thread_checker() const { return thread_checker_; }
31
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);
43 34
44 protected: 35 protected:
45 friend class base::RefCountedThreadSafe<HidConnection>; 36 friend class base::RefCountedThreadSafe<HidConnection>;
37 friend struct HidDeviceInfo;
46 38
47 explicit HidConnection(const HidDeviceInfo& device_info); 39 explicit HidConnection(const HidDeviceInfo& device_info);
48 virtual ~HidConnection(); 40 virtual ~HidConnection();
49 41
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 // In case incoming buffer is empty or protected, it is filtered
67 // and this method returns false. Otherwise it runs the callback
68 // and returns true.
69 bool CompleteRead(scoped_refptr<net::IOBufferWithSize> buffer,
70 const IOCallback& callback);
71
72 private: 42 private:
73 bool IsReportIdProtected(const uint8_t report_id);
74
75 const HidDeviceInfo device_info_; 43 const HidDeviceInfo device_info_;
76 bool has_report_id_;
77 bool has_protected_collection_;
78 base::ThreadChecker thread_checker_;
79 44
80 DISALLOW_COPY_AND_ASSIGN(HidConnection); 45 DISALLOW_COPY_AND_ASSIGN(HidConnection);
81 }; 46 };
82 47
83 struct PendingHidReport { 48 struct PendingHidReport {
84 PendingHidReport(); 49 PendingHidReport();
85 ~PendingHidReport(); 50 ~PendingHidReport();
86 51
87 scoped_refptr<net::IOBufferWithSize> buffer; 52 scoped_refptr<net::IOBufferWithSize> buffer;
88 }; 53 };
89 54
90 struct PendingHidRead { 55 struct PendingHidRead {
91 PendingHidRead(); 56 PendingHidRead();
92 ~PendingHidRead(); 57 ~PendingHidRead();
93 58
94 scoped_refptr<net::IOBufferWithSize> buffer; 59 scoped_refptr<net::IOBufferWithSize> buffer;
95 HidConnection::IOCallback callback; 60 HidConnection::IOCallback callback;
96 }; 61 };
97 62
98 } // namespace device 63 } // namespace device
99 64
100 #endif // DEVICE_HID_HID_CONNECTION_H_ 65 #endif // DEVICE_HID_HID_CONNECTION_H_
OLDNEW
« no previous file with comments | « trunk/src/device/hid/hid_collection_info.cc ('k') | trunk/src/device/hid/hid_connection.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698