Use multiline attribute to check for IA2_STATE_MULTILINE.
[chromium-blink-merge.git] / device / hid / hid_connection_linux.h
blob1f32420e4171f5f9ea7b50878f4320c81c97e1eb
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 scoped_refptr<HidDeviceInfo> device_info,
24 base::File device_file,
25 scoped_refptr<base::SingleThreadTaskRunner> file_thread_runner);
27 private:
28 friend class base::RefCountedThreadSafe<HidConnectionLinux>;
29 class FileThreadHelper;
31 typedef base::Callback<void(ssize_t)> InternalWriteCallback;
32 typedef base::Callback<void(int)> IoctlCallback;
34 ~HidConnectionLinux() override;
36 // HidConnection implementation.
37 void PlatformClose() override;
38 void PlatformRead(const ReadCallback& callback) override;
39 void PlatformWrite(scoped_refptr<net::IOBuffer> buffer,
40 size_t size,
41 const WriteCallback& callback) override;
42 void PlatformGetFeatureReport(uint8_t report_id,
43 const ReadCallback& callback) override;
44 void PlatformSendFeatureReport(scoped_refptr<net::IOBuffer> buffer,
45 size_t size,
46 const WriteCallback& callback) override;
48 // Callbacks for blocking operations run on the FILE thread.
49 void FinishWrite(size_t expected_size,
50 const WriteCallback& callback,
51 ssize_t result);
52 void FinishGetFeatureReport(uint8_t report_id,
53 scoped_refptr<net::IOBuffer> buffer,
54 const ReadCallback& callback,
55 int result);
56 void FinishSendFeatureReport(const WriteCallback& callback, int result);
58 // Writes to the device. This operation may block.
59 static void BlockingWrite(
60 base::PlatformFile platform_file,
61 scoped_refptr<net::IOBuffer> buffer,
62 size_t size,
63 const InternalWriteCallback& callback,
64 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
65 // Performs an ioctl on the device. This operation may block.
66 static void BlockingIoctl(
67 base::PlatformFile platform_file,
68 int request,
69 scoped_refptr<net::IOBuffer> buffer,
70 const IoctlCallback& callback,
71 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
73 // Closes the device file descriptor. Must be called on the FILE thread.
74 static void CloseDevice(base::File device_file);
76 void ProcessInputReport(scoped_refptr<net::IOBuffer> buffer, size_t size);
77 void ProcessReadQueue();
79 base::File device_file_;
80 FileThreadHelper* helper_;
82 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
83 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_;
85 std::queue<PendingHidReport> pending_reports_;
86 std::queue<PendingHidRead> pending_reads_;
88 base::WeakPtrFactory<HidConnectionLinux> weak_factory_;
90 DISALLOW_COPY_AND_ASSIGN(HidConnectionLinux);
93 } // namespace device
95 #endif // DEVICE_HID_HID_CONNECTION_LINUX_H_