summaryrefslogtreecommitdiffstats
path: root/device/hid/hid_connection.h
blob: 5c08fbc5bbdf5733e1e3a3c63149bed7044d768b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef DEVICE_HID_HID_CONNECTION_H_
#define DEVICE_HID_HID_CONNECTION_H_

#include <stdint.h>

#include "base/callback.h"
#include "base/memory/ref_counted.h"
#include "device/hid/hid_device_info.h"
#include "net/base/io_buffer.h"

namespace device {

class HidConnection : public base::RefCountedThreadSafe<HidConnection> {
 public:
  typedef base::Callback<void(bool success, size_t size)> IOCallback;

  virtual void Read(scoped_refptr<net::IOBufferWithSize> buffer,
                    const IOCallback& callback) = 0;
  virtual void Write(uint8_t report_id,
                     scoped_refptr<net::IOBufferWithSize> buffer,
                     const IOCallback& callback) = 0;
  virtual void GetFeatureReport(uint8_t report_id,
                                scoped_refptr<net::IOBufferWithSize> buffer,
                                const IOCallback& callback) = 0;
  virtual void SendFeatureReport(uint8_t report_id,
                                 scoped_refptr<net::IOBufferWithSize> buffer,
                                 const IOCallback& callback) = 0;

  const HidDeviceInfo& device_info() const { return device_info_; }

 protected:
  friend class base::RefCountedThreadSafe<HidConnection>;
  friend struct HidDeviceInfo;

  explicit HidConnection(const HidDeviceInfo& device_info);
  virtual ~HidConnection();

 private:
  const HidDeviceInfo device_info_;

  DISALLOW_COPY_AND_ASSIGN(HidConnection);
};

struct PendingHidReport {
  PendingHidReport();
  ~PendingHidReport();

  scoped_refptr<net::IOBufferWithSize> buffer;
};

struct PendingHidRead {
  PendingHidRead();
  ~PendingHidRead();

  scoped_refptr<net::IOBufferWithSize> buffer;
  HidConnection::IOCallback callback;
};

}  // namespace device

#endif  // DEVICE_HID_HID_CONNECTION_H_