Chromium Code Reviews| Index: device/hid/hid_connection_win.h |
| diff --git a/device/hid/hid_connection_win.h b/device/hid/hid_connection_win.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..44ebeec8a022edf3ac3e49bde5b31b0b366f9105 |
| --- /dev/null |
| +++ b/device/hid/hid_connection_win.h |
| @@ -0,0 +1,80 @@ |
| +// Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef DEVICE_HID_HID_CONNECTION_WIN_H_ |
| +#define DEVICE_HID_HID_CONNECTION_WIN_H_ |
| + |
| +#include <windows.h> |
| + |
| +#include "base/callback.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/win/object_watcher.h" |
| +#include "device/hid/hid_connection.h" |
| +#include "device/hid/hid_device_info.h" |
| + |
| +namespace device { |
| + |
| +class AsyncTransfer : public base::RefCountedThreadSafe<AsyncTransfer>, |
| + public base::win::ObjectWatcher::Delegate { |
| + public: |
|
Ken Rockot(use gerrit already)
2014/01/21 23:03:39
base::MessageLoopForIO::IOHandler essentially prov
Bei Zhang
2014/01/24 12:48:47
As I tested, it only works on IO thread, were IO i
|
| + AsyncTransfer(HANDLE file, |
| + scoped_refptr<net::IOBuffer> buffer, |
| + const HidIOCallback& callback, |
| + bool is_read); |
| + |
| + OVERLAPPED* GetOverlappedPtr(); |
| + DWORD* GetActualSizePtr(); |
| + |
| + void StartWatching(BOOL result_from_winapi); |
| + |
| + private: |
| + friend class base::RefCountedThreadSafe<AsyncTransfer>; |
| + |
| + virtual ~AsyncTransfer(); |
| + |
| + // base::win::ObjectWatcher::Delegate: |
| + virtual void OnObjectSignaled(HANDLE object) OVERRIDE; |
| + |
| + HANDLE file_; |
| + OVERLAPPED overlapped_; |
| + scoped_refptr<net::IOBuffer> buffer_; |
| + base::win::ScopedHandle event_; |
| + HidIOCallback callback_; |
| + base::win::ObjectWatcher watcher_; |
| + DWORD actual_size_; |
| + |
| + // For input transfer, if the first byte is zero, we need to remove it. |
| + bool is_read_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(AsyncTransfer); |
| +}; |
| + |
| +class HidConnectionWin : public HidConnection { |
| + public: |
| + HidConnectionWin(HidDeviceInfo device_info); |
| + |
| + virtual void Read(const HidIOCallback& callback) OVERRIDE; |
| + virtual void Write(scoped_refptr<net::IOBuffer> buffer, |
| + size_t size, |
| + const HidIOCallback& callback) OVERRIDE; |
| + virtual void GetFeatureReport(const HidIOCallback& callback) OVERRIDE; |
| + virtual void SendFeatureReport(scoped_refptr<net::IOBuffer> buffer, |
| + size_t size, |
| + const HidIOCallback& callback) OVERRIDE; |
| + |
| + bool available() const { return available_; } |
| + |
| + private: |
| + ~HidConnectionWin(); |
| + |
| + base::win::ScopedHandle file_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(HidConnectionWin); |
| + |
| + bool available_; |
| +}; |
| + |
| +} // namespace device |
| + |
| +#endif // DEVICE_HID_HID_CONNECTION_WIN_H_ |