summaryrefslogtreecommitdiffstats
path: root/device/bluetooth/bluetooth_socket.h
blob: 6ae349e9ac92c2f1480f4360b6546287e73cef41 (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
// Copyright (c) 2012 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_H_
#define DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_H_

#include <string>

#include "base/memory/ref_counted.h"

namespace net {

class DrainableIOBuffer;
class GrowableIOBuffer;

}  // namespace net

namespace device {

// BluetoothSocket represents a socket to a specific service on a
// BluetoothDevice.  BluetoothSocket objects are ref counted and may outlive
// both the BluetoothDevice and BluetoothAdapter that were involved in their
// creation.
class BluetoothSocket : public base::RefCounted<BluetoothSocket> {
 public:
  // Receives data from the socket and stores it in |buffer|. It returns whether
  // the reception has been successful. If it fails, the caller can get the
  // error message through |GetLastErrorMessage()|.
  virtual bool Receive(net::GrowableIOBuffer* buffer) = 0;

  // Sends |buffer| to the socket. It returns whether the sending has been
  // successful. If it fails, the caller can get the error message through
  // |GetLastErrorMessage()|.
  virtual bool Send(net::DrainableIOBuffer* buffer) = 0;

  virtual std::string GetLastErrorMessage() const = 0;

 protected:
  friend class base::RefCounted<BluetoothSocket>;
  virtual ~BluetoothSocket() {}
};

}  // namespace device

#endif  // DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_H_