Roll WebRTC 7914:7927, Libjingle 7908:7925
[chromium-blink-merge.git] / device / hid / hid_connection_linux.h
blob13a71652bef35d073d8215dab42cc8075f808284
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
3 // found in the LICENSE file.
5 #ifndef DEVICE_HID_HID_CONNECTION_LINUX_H_
6 #define DEVICE_HID_HID_CONNECTION_LINUX_H_
8 #include <queue>
10 #include "base/files/file.h"
11 #include "base/memory/weak_ptr.h"
12 #include "device/hid/hid_connection.h"
14 namespace base {
15 class SingleThreadTaskRunner;
18 namespace device {
20 class HidConnectionLinux : public HidConnection {
21 public:
22 HidConnectionLinux(
23 const HidDeviceInfo& device_info,
24 base::File device_file,
25 scoped_refptr<base::SingleThreadTaskRunner> file_thread_runner);
27 private:
28 class Helper;
29 friend class Helper;
30 friend class base::RefCountedThreadSafe<HidConnectionLinux>;
32 typedef base::Callback<void(ssize_t)> InternalWriteCallback;
33 typedef base::Callback<void(int)> IoctlCallback;
35 ~HidConnectionLinux() override;
37 // HidConnection implementation.
38 void PlatformClose() override;
39 void PlatformRead(const ReadCallback& callback) override;
40 void PlatformWrite(scoped_refptr<net::IOBuffer> buffer,
41 size_t size,
42 const WriteCallback& callback) override;
43 void PlatformGetFeatureReport(uint8_t report_id,
44 const ReadCallback& callback) override;
45 void PlatformSendFeatureReport(scoped_refptr<net::IOBuffer> buffer,
46 size_t size,
47 const WriteCallback& callback) override;
49 // Callbacks for blocking operations run on the FILE thread.
50 void FinishWrite(size_t expected_size,
51 const WriteCallback& callback,
52 ssize_t result);
53 void FinishGetFeatureReport(uint8_t report_id,
54 scoped_refptr<net::IOBuffer> buffer,
55 const ReadCallback& callback,
56 int result);
57 void FinishSendFeatureReport(const WriteCallback& callback, int result);
59 // Writes to the device. This operation may block.
60 static void BlockingWrite(
61 base::PlatformFile platform_file,
62 scoped_refptr<net::IOBuffer> buffer,
63 size_t size,
64 const InternalWriteCallback& callback,
65 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
66 // Performs an ioctl on the device. This operation may block.
67 static void BlockingIoctl(
68 base::PlatformFile platform_file,
69 int request,
70 scoped_refptr<net::IOBuffer> buffer,
71 const IoctlCallback& callback,
72 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
74 // Closes the device file descriptor. Must be called on the FILE thread.
75 static void CloseDevice(base::File device_file);
77 void ProcessInputReport(scoped_refptr<net::IOBuffer> buffer, size_t size);
78 void ProcessReadQueue();
80 base::File device_file_;
81 Helper* helper_;
83 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
84 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_;
86 std::queue<PendingHidReport> pending_reports_;
87 std::queue<PendingHidRead> pending_reads_;
89 base::WeakPtrFactory<HidConnectionLinux> weak_factory_;
91 DISALLOW_COPY_AND_ASSIGN(HidConnectionLinux);
94 } // namespace device
96 #endif // DEVICE_HID_HID_CONNECTION_LINUX_H_