blob: 1c52c679f0e76b2a343e5e2477cfa0eff56cde18 [file] [log] [blame]
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +01001// Copyright 2013 The Chromium Authors. All rights reserved.
Torne (Richard Coles)b2df76e2013-05-13 16:52:09 +01002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +01005#ifndef DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_CHROMEOS_H_
6#define DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_CHROMEOS_H_
Torne (Richard Coles)b2df76e2013-05-13 16:52:09 +01007
8#include <string>
9
10#include "base/basictypes.h"
11#include "base/memory/ref_counted.h"
12#include "chromeos/chromeos_export.h"
13#include "device/bluetooth/bluetooth_socket.h"
14
15namespace dbus {
16
17class FileDescriptor;
18
19} // namespace dbus
20
21namespace net {
22
23class DrainableIOBuffer;
24class GrowableIOBuffer;
25
26} // namespace net
27
28namespace chromeos {
29
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010030// The BluetoothSocketChromeOS class implements BluetoothSocket for the
31// Chrome OS platform.
32class CHROMEOS_EXPORT BluetoothSocketChromeOS
Torne (Richard Coles)b2df76e2013-05-13 16:52:09 +010033 : public device::BluetoothSocket {
34 public:
35 // BluetoothSocket override.
36 virtual bool Receive(net::GrowableIOBuffer* buffer) OVERRIDE;
37 virtual bool Send(net::DrainableIOBuffer* buffer) OVERRIDE;
38 virtual std::string GetLastErrorMessage() const OVERRIDE;
39
40 // Create an instance of a BluetoothSocket from the passed file descriptor
41 // received over D-Bus in |fd|, the descriptor will be taken from that object
42 // and ownership passed to the returned object.
43 static scoped_refptr<device::BluetoothSocket> Create(
44 dbus::FileDescriptor* fd);
45
46 protected:
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010047 virtual ~BluetoothSocketChromeOS();
Torne (Richard Coles)b2df76e2013-05-13 16:52:09 +010048
49 private:
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010050 BluetoothSocketChromeOS(int fd);
Torne (Richard Coles)b2df76e2013-05-13 16:52:09 +010051
52 // The different socket types have different reading patterns; l2cap sockets
53 // have to be read with boundaries between datagrams preserved while rfcomm
54 // sockets do not.
55 enum SocketType {
56 L2CAP,
57 RFCOMM
58 };
59
60 // File descriptor and socket type of the socket.
61 const int fd_;
62 SocketType socket_type_;
63
64 // Last error message, set during Receive() and Send() and retrieved using
65 // GetLastErrorMessage().
66 std::string error_message_;
67
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010068 DISALLOW_COPY_AND_ASSIGN(BluetoothSocketChromeOS);
Torne (Richard Coles)b2df76e2013-05-13 16:52:09 +010069};
70
71} // namespace chromeos
72
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010073#endif // DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_CHROMEOS_H_