Upstream version 6.35.121.0
[platform/framework/web/crosswalk.git] / src / device / hid / hid_connection.h
1 // Copyright 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_H_
6 #define DEVICE_HID_HID_CONNECTION_H_
7
8 #include <stdint.h>
9
10 #include "base/callback.h"
11 #include "base/memory/ref_counted.h"
12 #include "device/hid/hid_device_info.h"
13 #include "net/base/io_buffer.h"
14
15 namespace device {
16
17 class HidConnection : public base::RefCountedThreadSafe<HidConnection> {
18  public:
19   typedef base::Callback<void(bool success, size_t size)> IOCallback;
20
21   virtual void Read(scoped_refptr<net::IOBufferWithSize> buffer,
22                     const IOCallback& callback) = 0;
23   virtual void Write(uint8_t report_id,
24                      scoped_refptr<net::IOBufferWithSize> buffer,
25                      const IOCallback& callback) = 0;
26   virtual void GetFeatureReport(uint8_t report_id,
27                                 scoped_refptr<net::IOBufferWithSize> buffer,
28                                 const IOCallback& callback) = 0;
29   virtual void SendFeatureReport(uint8_t report_id,
30                                  scoped_refptr<net::IOBufferWithSize> buffer,
31                                  const IOCallback& callback) = 0;
32
33   const HidDeviceInfo& device_info() const { return device_info_; }
34
35  protected:
36   friend class base::RefCountedThreadSafe<HidConnection>;
37   friend struct HidDeviceInfo;
38
39   explicit HidConnection(const HidDeviceInfo& device_info);
40   virtual ~HidConnection();
41
42  private:
43   const HidDeviceInfo device_info_;
44
45   DISALLOW_COPY_AND_ASSIGN(HidConnection);
46 };
47
48 struct PendingHidReport {
49   PendingHidReport();
50   ~PendingHidReport();
51
52   scoped_refptr<net::IOBufferWithSize> buffer;
53 };
54
55 struct PendingHidRead {
56   PendingHidRead();
57   ~PendingHidRead();
58
59   scoped_refptr<net::IOBufferWithSize> buffer;
60   HidConnection::IOCallback callback;
61 };
62
63 }  // namespace device
64
65 #endif  // DEVICE_HID_HID_CONNECTION_H_