| OLD | NEW |
| 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 "base/win/object_watcher.h" |
| 16 #include "device/hid/hid_connection.h" | 17 #include "device/hid/hid_connection.h" |
| 17 #include "device/hid/hid_device_info.h" | 18 #include "device/hid/hid_device_info.h" |
| 18 #include "net/base/io_buffer.h" | |
| 19 | 19 |
| 20 namespace device { | 20 namespace device { |
| 21 | 21 |
| 22 class HidConnectionWin : public HidConnection { | 22 class HidConnectionWin : public HidConnection { |
| 23 public: | 23 public: |
| 24 struct PendingTransfer : public base::RefCounted<PendingTransfer>, | 24 struct PendingTransfer : public base::RefCounted<PendingTransfer>, |
| 25 public base::win::ObjectWatcher::Delegate, | 25 public base::win::ObjectWatcher::Delegate, |
| 26 public base::MessageLoop::DestructionObserver { | 26 public base::MessageLoop::DestructionObserver { |
| 27 public: | 27 public: |
| 28 PendingTransfer(scoped_refptr<HidConnectionWin> conn, | 28 PendingTransfer(scoped_refptr<HidConnectionWin> conn, |
| 29 scoped_refptr<net::IOBuffer> target, | 29 scoped_refptr<net::IOBufferWithSize> target, |
| 30 scoped_refptr<net::IOBuffer> receiving, | 30 scoped_refptr<net::IOBufferWithSize> receiving, |
| 31 bool is_input, | 31 bool is_input, |
| 32 IOCallback callback); | 32 IOCallback callback); |
| 33 | 33 |
| 34 void TakeResultFromWindowsAPI(BOOL result); | 34 void TakeResultFromWindowsAPI(BOOL result); |
| 35 | 35 |
| 36 OVERLAPPED* GetOverlapped() { return &overlapped_; } | 36 OVERLAPPED* GetOverlapped() { return &overlapped_; } |
| 37 | 37 |
| 38 // Implements base::win::ObjectWatcher::Delegate. | 38 // Implements base::win::ObjectWatcher::Delegate. |
| 39 virtual void OnObjectSignaled(HANDLE object) OVERRIDE; | 39 virtual void OnObjectSignaled(HANDLE object) OVERRIDE; |
| 40 | 40 |
| 41 // Implements base::MessageLoop::DestructionObserver | 41 // Implements base::MessageLoop::DestructionObserver |
| 42 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; | 42 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; |
| 43 | 43 |
| 44 | 44 |
| 45 private: | 45 private: |
| 46 friend class base::RefCounted<PendingTransfer>; | 46 friend class base::RefCounted<PendingTransfer>; |
| 47 friend class HidConnectionWin; | 47 friend class HidConnectionWin; |
| 48 | 48 |
| 49 virtual ~PendingTransfer(); | 49 virtual ~PendingTransfer(); |
| 50 | 50 |
| 51 scoped_refptr<HidConnectionWin> conn_; | 51 scoped_refptr<HidConnectionWin> conn_; |
| 52 bool is_input_; | 52 bool is_input_; |
| 53 scoped_refptr<net::IOBuffer> target_; | 53 scoped_refptr<net::IOBufferWithSize> target_; |
| 54 scoped_refptr<net::IOBuffer> receiving_; | 54 scoped_refptr<net::IOBufferWithSize> receiving_; |
| 55 IOCallback callback_; | 55 IOCallback callback_; |
| 56 OVERLAPPED overlapped_; | 56 OVERLAPPED overlapped_; |
| 57 base::win::ScopedHandle event_; | 57 base::win::ScopedHandle event_; |
| 58 base::win::ObjectWatcher watcher_; | 58 base::win::ObjectWatcher watcher_; |
| 59 | 59 |
| 60 DISALLOW_COPY_AND_ASSIGN(PendingTransfer); | 60 DISALLOW_COPY_AND_ASSIGN(PendingTransfer); |
| 61 }; | 61 }; |
| 62 | 62 |
| 63 HidConnectionWin(HidDeviceInfo device_info); | 63 HidConnectionWin(HidDeviceInfo device_info, const std::string& device_path); |
| 64 | 64 |
| 65 virtual void Read(scoped_refptr<net::IOBuffer> buffer, | 65 bool available() const; |
| 66 size_t size, | 66 |
| 67 virtual void Read(scoped_refptr<net::IOBufferWithSize> buffer, |
| 67 const IOCallback& callback) OVERRIDE; | 68 const IOCallback& callback) OVERRIDE; |
| 68 virtual void Write(scoped_refptr<net::IOBuffer> buffer, | 69 virtual void Write(scoped_refptr<net::IOBufferWithSize> buffer, |
| 69 size_t size, | |
| 70 const IOCallback& callback) OVERRIDE; | 70 const IOCallback& callback) OVERRIDE; |
| 71 virtual void GetFeatureReport(scoped_refptr<net::IOBuffer> buffer, | 71 virtual void GetFeatureReport(scoped_refptr<net::IOBufferWithSize> buffer, |
| 72 size_t size, | |
| 73 const IOCallback& callback) OVERRIDE; | 72 const IOCallback& callback) OVERRIDE; |
| 74 virtual void SendFeatureReport(scoped_refptr<net::IOBuffer> buffer, | 73 virtual void SendFeatureReport(scoped_refptr<net::IOBufferWithSize> buffer, |
| 75 size_t size, | |
| 76 const IOCallback& callback) OVERRIDE; | 74 const IOCallback& callback) OVERRIDE; |
| 77 | 75 |
| 78 void OnTransferFinished(scoped_refptr<PendingTransfer> transfer); | 76 void OnTransferFinished(scoped_refptr<PendingTransfer> transfer); |
| 79 void OnTransferCanceled(scoped_refptr<PendingTransfer> transfer); | 77 void OnTransferCanceled(scoped_refptr<PendingTransfer> transfer); |
| 80 | 78 |
| 81 bool available() const { return available_; } | |
| 82 | |
| 83 private: | 79 private: |
| 84 ~HidConnectionWin(); | 80 ~HidConnectionWin(); |
| 85 | 81 |
| 86 base::win::ScopedHandle file_; | 82 base::win::ScopedHandle file_; |
| 87 std::set<scoped_refptr<PendingTransfer> > transfers_; | 83 std::set<scoped_refptr<PendingTransfer> > transfers_; |
| 88 | 84 |
| 89 DISALLOW_COPY_AND_ASSIGN(HidConnectionWin); | 85 DISALLOW_COPY_AND_ASSIGN(HidConnectionWin); |
| 90 | |
| 91 bool available_; | |
| 92 }; | 86 }; |
| 93 | 87 |
| 94 } // namespace device | 88 } // namespace device |
| 95 | 89 |
| 96 #endif // DEVICE_HID_HID_CONNECTION_WIN_H_ | 90 #endif // DEVICE_HID_HID_CONNECTION_WIN_H_ |
| OLD | NEW |