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 "base/memory/ref_counted.h"
9 #include "base/platform_file.h"
10 #include "base/tuple.h"
11 #include "device/hid/hid_connection.h"
12 #include "device/hid/hid_device_info.h"
13 #include "device/hid/hid_service_linux.h"
14 #include "net/base/io_buffer.h"
18 class HidConnectionLinux
: public HidConnection
,
19 public base::MessagePumpLibevent::Watcher
{
21 HidConnectionLinux(HidDeviceInfo device_info
,
22 ScopedUdevDevicePtr udev_raw_device
);
24 virtual void Read(scoped_refptr
<net::IOBuffer
> buffer
,
26 const IOCallback
& callback
) OVERRIDE
;
27 virtual void Write(scoped_refptr
<net::IOBuffer
> buffer
,
29 const IOCallback
& callback
) OVERRIDE
;
30 virtual void GetFeatureReport(scoped_refptr
<net::IOBuffer
> buffer
,
32 const IOCallback
& callback
) OVERRIDE
;
33 virtual void SendFeatureReport(scoped_refptr
<net::IOBuffer
> buffer
,
35 const IOCallback
& callback
) OVERRIDE
;
37 bool initialized() const { return initialized_
; }
39 // Implements base::MessagePumpLibevent::Watcher
40 virtual void OnFileCanReadWithoutBlocking(int fd
) OVERRIDE
;
41 virtual void OnFileCanWriteWithoutBlocking(int fd
) OVERRIDE
;
44 friend class base::RefCountedThreadSafe
<HidConnectionLinux
>;
45 virtual ~HidConnectionLinux();
47 static bool FindHidrawDevNode(udev_device
* parent
, std::string
* result
);
49 void ProcessReadQueue();
52 base::PlatformFile device_file_
;
53 base::MessagePumpLibevent::FileDescriptorWatcher device_file_watcher_
;
55 typedef std::pair
<scoped_refptr
<net::IOBuffer
>, size_t> PendingReport
;
56 typedef Tuple3
<scoped_refptr
<net::IOBuffer
>, size_t, IOCallback
>
59 std::queue
<PendingReport
> input_reports_
;
60 std::queue
<PendingRequest
> read_queue_
;
64 DISALLOW_COPY_AND_ASSIGN(HidConnectionLinux
);
69 #endif // DEVICE_HID_HID_CONNECTION_LINUX__