Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
Torne (Richard Coles) | b2df76e | 2013-05-13 16:52:09 +0100 | [diff] [blame] | 2 | // 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) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 5 | #ifndef DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_CHROMEOS_H_ |
| 6 | #define DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_CHROMEOS_H_ |
Torne (Richard Coles) | b2df76e | 2013-05-13 16:52:09 +0100 | [diff] [blame] | 7 | |
| 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 | |
| 15 | namespace dbus { |
| 16 | |
| 17 | class FileDescriptor; |
| 18 | |
| 19 | } // namespace dbus |
| 20 | |
| 21 | namespace net { |
| 22 | |
| 23 | class DrainableIOBuffer; |
| 24 | class GrowableIOBuffer; |
| 25 | |
| 26 | } // namespace net |
| 27 | |
| 28 | namespace chromeos { |
| 29 | |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 30 | // The BluetoothSocketChromeOS class implements BluetoothSocket for the |
| 31 | // Chrome OS platform. |
| 32 | class CHROMEOS_EXPORT BluetoothSocketChromeOS |
Torne (Richard Coles) | b2df76e | 2013-05-13 16:52:09 +0100 | [diff] [blame] | 33 | : 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) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 47 | virtual ~BluetoothSocketChromeOS(); |
Torne (Richard Coles) | b2df76e | 2013-05-13 16:52:09 +0100 | [diff] [blame] | 48 | |
| 49 | private: |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 50 | BluetoothSocketChromeOS(int fd); |
Torne (Richard Coles) | b2df76e | 2013-05-13 16:52:09 +0100 | [diff] [blame] | 51 | |
| 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) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 68 | DISALLOW_COPY_AND_ASSIGN(BluetoothSocketChromeOS); |
Torne (Richard Coles) | b2df76e | 2013-05-13 16:52:09 +0100 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | } // namespace chromeos |
| 72 | |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 73 | #endif // DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_CHROMEOS_H_ |