Upstream version 11.39.250.0
[platform/framework/web/crosswalk.git] / src / device / hid / hid_connection_linux.h
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.
4
5 #ifndef DEVICE_HID_HID_CONNECTION_LINUX_H_
6 #define DEVICE_HID_HID_CONNECTION_LINUX_H_
7
8 #include <queue>
9
10 #include "base/files/file.h"
11 #include "base/message_loop/message_pump_libevent.h"
12 #include "device/hid/hid_connection.h"
13
14 namespace device {
15
16 class HidConnectionLinux : public HidConnection,
17                            public base::MessagePumpLibevent::Watcher {
18  public:
19   HidConnectionLinux(HidDeviceInfo device_info, std::string dev_node);
20
21  private:
22   friend class base::RefCountedThreadSafe<HidConnectionLinux>;
23   virtual ~HidConnectionLinux();
24
25   // HidConnection implementation.
26   virtual void PlatformClose() OVERRIDE;
27   virtual void PlatformRead(const ReadCallback& callback) OVERRIDE;
28   virtual void PlatformWrite(scoped_refptr<net::IOBuffer> buffer,
29                              size_t size,
30                              const WriteCallback& callback) OVERRIDE;
31   virtual void PlatformGetFeatureReport(uint8_t report_id,
32                                         const ReadCallback& callback) OVERRIDE;
33   virtual void PlatformSendFeatureReport(
34       scoped_refptr<net::IOBuffer> buffer,
35       size_t size,
36       const WriteCallback& callback) OVERRIDE;
37
38   // base::MessagePumpLibevent::Watcher implementation.
39   virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE;
40   virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE;
41
42   void Disconnect();
43
44   void Flush();
45   void ProcessInputReport(scoped_refptr<net::IOBuffer> buffer, size_t size);
46   void ProcessReadQueue();
47
48   base::File device_file_;
49   base::MessagePumpLibevent::FileDescriptorWatcher device_file_watcher_;
50
51   std::queue<PendingHidReport> pending_reports_;
52   std::queue<PendingHidRead> pending_reads_;
53
54   DISALLOW_COPY_AND_ASSIGN(HidConnectionLinux);
55 };
56
57 }  // namespace device
58
59 #endif  // DEVICE_HID_HID_CONNECTION_LINUX_H_