• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 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_BLUETOOTH_BLUETOOTH_SOCKET_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_H_
7 
8 #include <string>
9 
10 #include "base/memory/ref_counted.h"
11 
12 namespace net {
13 
14 class DrainableIOBuffer;
15 class GrowableIOBuffer;
16 
17 }  // namespace net
18 
19 namespace device {
20 
21 // BluetoothSocket represents a socket to a specific service on a
22 // BluetoothDevice.  BluetoothSocket objects are ref counted and may outlive
23 // both the BluetoothDevice and BluetoothAdapter that were involved in their
24 // creation.
25 class BluetoothSocket : public base::RefCounted<BluetoothSocket> {
26  public:
27   // Receives data from the socket and stores it in |buffer|. It returns whether
28   // the reception has been successful. If it fails, the caller can get the
29   // error message through |GetLastErrorMessage()|.
30   virtual bool Receive(net::GrowableIOBuffer* buffer) = 0;
31 
32   // Sends |buffer| to the socket. It returns whether the sending has been
33   // successful. If it fails, the caller can get the error message through
34   // |GetLastErrorMessage()|.
35   virtual bool Send(net::DrainableIOBuffer* buffer) = 0;
36 
37   virtual std::string GetLastErrorMessage() const = 0;
38 
39  protected:
40   friend class base::RefCounted<BluetoothSocket>;
~BluetoothSocket()41   virtual ~BluetoothSocket() {}
42 };
43 
44 }  // namespace device
45 
46 #endif  // DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_H_
47