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

Side by Side Diff: device/hid/hid_connection_win.h

Issue 161823002: Clean up HID backend and API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 9 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 | « device/hid/hid_connection_unittest.cc ('k') | device/hid/hid_connection_win.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 (c) 2014 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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_WIN_H_ 5 #ifndef DEVICE_HID_HID_CONNECTION_WIN_H_
6 #define DEVICE_HID_HID_CONNECTION_WIN_H_ 6 #define DEVICE_HID_HID_CONNECTION_WIN_H_
7 7
8 #include <windows.h>
9
8 #include <set> 10 #include <set>
9 #include <windows.h>
10 11
11 #include "base/callback.h" 12 #include "base/callback.h"
12 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
13 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
14 #include "base/threading/thread_checker.h" 15 #include "base/threading/thread_checker.h"
15 #include "base/win/object_watcher.h"
16 #include "device/hid/hid_connection.h" 16 #include "device/hid/hid_connection.h"
17 #include "device/hid/hid_device_info.h" 17 #include "device/hid/hid_device_info.h"
18 #include "net/base/io_buffer.h"
19 18
20 namespace device { 19 namespace device {
21 20
21 struct PendingHidTransfer;
22
22 class HidConnectionWin : public HidConnection { 23 class HidConnectionWin : public HidConnection {
23 public: 24 public:
24 struct PendingTransfer : public base::RefCounted<PendingTransfer>, 25 explicit HidConnectionWin(const HidDeviceInfo& device_info);
25 public base::win::ObjectWatcher::Delegate,
26 public base::MessageLoop::DestructionObserver {
27 public:
28 PendingTransfer(scoped_refptr<HidConnectionWin> conn,
29 scoped_refptr<net::IOBuffer> target,
30 scoped_refptr<net::IOBuffer> receiving,
31 bool is_input,
32 IOCallback callback);
33 26
34 void TakeResultFromWindowsAPI(BOOL result); 27 bool available() const;
35 28
36 OVERLAPPED* GetOverlapped() { return &overlapped_; } 29 virtual void Read(scoped_refptr<net::IOBufferWithSize> buffer,
37
38 // Implements base::win::ObjectWatcher::Delegate.
39 virtual void OnObjectSignaled(HANDLE object) OVERRIDE;
40
41 // Implements base::MessageLoop::DestructionObserver
42 virtual void WillDestroyCurrentMessageLoop() OVERRIDE;
43
44
45 private:
46 friend class base::RefCounted<PendingTransfer>;
47 friend class HidConnectionWin;
48
49 virtual ~PendingTransfer();
50
51 scoped_refptr<HidConnectionWin> conn_;
52 bool is_input_;
53 scoped_refptr<net::IOBuffer> target_;
54 scoped_refptr<net::IOBuffer> receiving_;
55 IOCallback callback_;
56 OVERLAPPED overlapped_;
57 base::win::ScopedHandle event_;
58 base::win::ObjectWatcher watcher_;
59
60 DISALLOW_COPY_AND_ASSIGN(PendingTransfer);
61 };
62
63 HidConnectionWin(HidDeviceInfo device_info);
64
65 virtual void Read(scoped_refptr<net::IOBuffer> buffer,
66 size_t size,
67 const IOCallback& callback) OVERRIDE; 30 const IOCallback& callback) OVERRIDE;
68 virtual void Write(scoped_refptr<net::IOBuffer> buffer, 31 virtual void Write(uint8_t report_id,
69 size_t size, 32 scoped_refptr<net::IOBufferWithSize> buffer,
70 const IOCallback& callback) OVERRIDE; 33 const IOCallback& callback) OVERRIDE;
71 virtual void GetFeatureReport(scoped_refptr<net::IOBuffer> buffer, 34 virtual void GetFeatureReport(uint8_t report_id,
72 size_t size, 35 scoped_refptr<net::IOBufferWithSize> buffer,
73 const IOCallback& callback) OVERRIDE; 36 const IOCallback& callback) OVERRIDE;
74 virtual void SendFeatureReport(scoped_refptr<net::IOBuffer> buffer, 37 virtual void SendFeatureReport(uint8_t report_id,
75 size_t size, 38 scoped_refptr<net::IOBufferWithSize> buffer,
76 const IOCallback& callback) OVERRIDE; 39 const IOCallback& callback) OVERRIDE;
77 40
78 void OnTransferFinished(scoped_refptr<PendingTransfer> transfer); 41 void OnTransferFinished(scoped_refptr<PendingHidTransfer> transfer);
79 void OnTransferCanceled(scoped_refptr<PendingTransfer> transfer); 42 void OnTransferCanceled(scoped_refptr<PendingHidTransfer> transfer);
80
81 bool available() const { return available_; }
82 43
83 private: 44 private:
84 ~HidConnectionWin(); 45 ~HidConnectionWin();
85 46
86 base::win::ScopedHandle file_; 47 base::win::ScopedHandle file_;
87 std::set<scoped_refptr<PendingTransfer> > transfers_; 48 std::set<scoped_refptr<PendingHidTransfer> > transfers_;
49
50 base::ThreadChecker thread_checker_;
88 51
89 DISALLOW_COPY_AND_ASSIGN(HidConnectionWin); 52 DISALLOW_COPY_AND_ASSIGN(HidConnectionWin);
90
91 bool available_;
92 }; 53 };
93 54
94 } // namespace device 55 } // namespace device
95 56
96 #endif // DEVICE_HID_HID_CONNECTION_WIN_H_ 57 #endif // DEVICE_HID_HID_CONNECTION_WIN_H_
OLDNEW
« no previous file with comments | « device/hid/hid_connection_unittest.cc ('k') | device/hid/hid_connection_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698