summaryrefslogtreecommitdiffstats
path: root/device/bluetooth/bluetooth_socket_chromeos.h
blob: 1c52c679f0e76b2a343e5e2477cfa0eff56cde18 (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
66
67
68
69
70
71
72
73
// Copyright 2013 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_BLUETOOTH_BLUETOOTH_SOCKET_CHROMEOS_H_
#define DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_CHROMEOS_H_

#include <string>

#include "base/basictypes.h"
#include "base/memory/ref_counted.h"
#include "chromeos/chromeos_export.h"
#include "device/bluetooth/bluetooth_socket.h"

namespace dbus {

class FileDescriptor;

}  // namespace dbus

namespace net {

class DrainableIOBuffer;
class GrowableIOBuffer;

}  // namespace net

namespace chromeos {

// The BluetoothSocketChromeOS class implements BluetoothSocket for the
// Chrome OS platform.
class CHROMEOS_EXPORT BluetoothSocketChromeOS
    : public device::BluetoothSocket {
 public:
  // BluetoothSocket override.
  virtual bool Receive(net::GrowableIOBuffer* buffer) OVERRIDE;
  virtual bool Send(net::DrainableIOBuffer* buffer) OVERRIDE;
  virtual std::string GetLastErrorMessage() const OVERRIDE;

  // Create an instance of a BluetoothSocket from the passed file descriptor
  // received over D-Bus in |fd|, the descriptor will be taken from that object
  // and ownership passed to the returned object.
  static scoped_refptr<device::BluetoothSocket> Create(
      dbus::FileDescriptor* fd);

 protected:
  virtual ~BluetoothSocketChromeOS();

 private:
  BluetoothSocketChromeOS(int fd);

  // The different socket types have different reading patterns; l2cap sockets
  // have to be read with boundaries between datagrams preserved while rfcomm
  // sockets do not.
  enum SocketType {
    L2CAP,
    RFCOMM
  };

  // File descriptor and socket type of the socket.
  const int fd_;
  SocketType socket_type_;

  // Last error message, set during Receive() and Send() and retrieved using
  // GetLastErrorMessage().
  std::string error_message_;

  DISALLOW_COPY_AND_ASSIGN(BluetoothSocketChromeOS);
};

}  // namespace chromeos

#endif  // DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_CHROMEOS_H_